nix-shellでRust環境をsetupする
from nix-shellでprojectごとに環境をsetupする
NixOS Wiki
#WIP
$ nix-shell -p cargo
$ cargo new hogehoge
で作ったやつに対して、↓を入れる
たぶんもっと良いやり方はあるだろうけどいったんこれで動く
code:shell.nix
let
moz_overlay = import (builtins.fetchTarball https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz);
pkgs = import <nixpkgs> {
overlays = moz_overlay ;
};
# Rolling updates, not deterministic.
# pkgs = import (fetchTarball("channel:nixpkgs-unstable")) {};
in pkgs.mkShell {
buildInputs = with pkgs; [
cargo
rustc
rustfmt
rustup
];
shellHook = ''
rustup install nightly
rustup component add rls rust-analysis rust-src
'';
# See https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570/3?u=samuela.
RUST_SRC_PATH = "${pkgs.rust.packages.stable.rustPlatform.rustLibSrc}";
}
todos
overlayを上手く使う
rustupのコマンド実行をshellHookの中でやっているけど、他にもっとシンプルなやり方があるはず
ちなみにこれは、VSCodeでちゃんとerrorとかを出すためにrustupの中身を実行している
ここにかいてることをやっただけ
rlsが重複している
nixpkgsのpin度目
moz_overlayのpinどめ
NixのOverlays
新規作成時のやりよう
nix-shell -p cargoして、その中でcargo newして、exitして、普通に利用、みたいなことをしている
ちょいダルいので回避したい
RUST_SRC_PATHは何のために書いているか理解していない
#??
extensionとかのやり方がよくわからない
NixのOverlays使ってやるとできるっぽいがerrorになる
code:error
error: attribute 'lib' missing, at /nix/store/gxld9lwg046....
https://duan.ca/2020/05/07/nix-rust-development/
https://stackoverflow.com/questions/57449098/nix-overlays-and-override-pattern
https://discourse.nixos.org/t/how-do-i-build-a-nix-shell-which-depends-on-some-unstable-packages/928
https://discourse.nixos.org/t/rust-src-not-found-and-other-misadventures-of-developing-rust-on-nixos/11570
https://www.reddit.com/r/NixOS/comments/laht65/help_rustanalyzer_in_shellnix/
https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/6
https://ghedam.at/15978/an-introduction-to-nix-shell
https://nixos.wiki/wiki/Rust
https://gutier.io/post/development-using-rust-with-nix/
https://discourse.nixos.org/t/how-can-i-set-up-my-rust-programming-environment/4501/5
https://github.com/NixOS/nixpkgs/blob/master/doc/languages-frameworks/rust.section.md
https://gist.github.com/georgewhewell/f4e038bde0605fdcae4e166b3c1a34fe