Open adaszko opened 2 years ago
Thanks for flagging! Recently I've been experimenting with using the following shell.nix
:
let
nixpkgs = import <nixpkgs> {};
rtc = (nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain);
rust = rtc.override {
extensions = [ "rust-src" "rust-analysis" ];
};
in
with nixpkgs;
mkShell {
name = "rust";
buildInputs = [
cargo-deny
cargo-expand
cargo-watch
openssl
pkgconfig
ripgrep
rust
];
}
Using rust-overlay
. It might be an idea to commit the shell.nix
file and others can use that, how does that sound to you?
let nixpkgs = import <nixpkgs> {}; rtc = (nixpkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain); rust = rtc.override { extensions = [ "rust-src" "rust-analysis" ]; }; in with nixpkgs; mkShell { name = "rust"; buildInputs = [ cargo-deny cargo-expand cargo-watch openssl pkgconfig ripgrep rust ]; }
I'm getting
% nix-shell shell.nix
error: attribute 'rust-bin' missing, at /home/adaszko/repos/radicle-link/shell.nix:3:10
on my machine.
This OTOH works for me:
let
mozilla_overlay = import (builtins.fetchTarball {
# url = "https://github.com/mozilla/nixpkgs-mozilla/archive/master.tar.gz";
url = "https://github.com/mozilla/andersk/archive/3499e085fb6ae1a846bcf425fa9c98a3b77480da.tar.gz";
sha256 = "1fd9n6p8vjlb5vqka2fzxrf1xb7lif5ibjvx8h1fk5w3yqkds2lg";
});
nixpkgs = import <nixpkgs> { overlays = [ mozilla_overlay ]; };
myrust = ((nixpkgs.rustChannelOf { rustToolchain = ./rust-toolchain; }).rust.override { extensions = [ "rust-src" "rust-analysis" "rustfmt-preview" ];});
in
with nixpkgs;
mkShell {
buildInputs = [
# to use the latest nightly:
# nixpkgs.latest.rustChannels.nightly.rust
# to use a specific nighly:
# (nixpkgs.rustChannelOf { date = "2018-04-11"; channel = "nightly"; }).rust
# to use the project's rust-toolchain file:
# (nixpkgs.rustChannelOf { rustToolchain = ./rust-toolchain; }).rust
myrust
cargo-deny
cargo-expand
cargo-watch
openssl
pkgconfig
ripgrep
];
}
Note that it pins the overlay to a specific version to avoid some "spontaneous" breakages.
Somewhat related: Is it even needed to run rustc nightly instead of stable? Is there some feature not available on stable that's being used?
You likely need to add rust-overlay
to your overlays config, i.e. create ~/.config/nixpkgs/overlays.nix
and add this line:
[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]
If you already have that file, then you should just be able to add it to your list of overlays.
Somewhat related: Is it even needed to run rustc nightly instead of stable? Is there some feature not available on stable that's being used?
Easily checked by changing the toolchain to stable
, and the first compiler error you run into is:
Checking radicle-std-ext v0.1.0 (/home/haptop/Developer/radicle-link/std-ext)
error[E0554]: `#![feature]` may not be used on the stable release channel
--> std-ext/src/lib.rs:6:1
|
6 | #![feature(extend_one)]
| ^^^^^^^^^^^^^^^^^^^^^^^
I think there may be others, so yes we're relying on nightly for the time being :)
You likely need to add
rust-overlay
to your overlays config, i.e. create~/.config/nixpkgs/overlays.nix
and add this line:[ (import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz")) ]
If you already have that file, then you should just be able to add it to your list of overlays.
Hmm, from a point of view of someone completely new to the project, that's an additional step that needs to be performed. It can be avoided by specifying the overlay config within shell.nix
(and thus also avoid the surprising error above). Is there some advantage to having the configuration done per-machine (i.e. in ~/.config/nixpkgs/overlays.nix
)?
For me, it's easier and is one of the recommended ways here: https://github.com/oxalica/rust-overlay#use-as-a-classic-nix-overlay.
But if you have a better setup then I'd be willing to look over a PR and try it out :) My Nix-fu isn't the best, so I use what I can to get by :smile:
For me, it's easier and is one of the recommended ways here: https://github.com/oxalica/rust-overlay#use-as-a-classic-nix-overlay.
But if you have a better setup then I'd be willing to look over a PR and try it out :) My Nix-fu isn't the best, so I use what I can to get by 😄
Same here, Sir 😄 Looks like oxalica's overlay claims to improve upon Mozilla's. I have only used Mozilla's so far so would have to play with it first to make my mind about it :)
Ahaha very good :smile: Welcome to the club! I used Mozilla's for a while but then it started breaking a lot for me so I abandoned it for rust-overlay
and haven't had problems since :raised_hands:
There's a build issue on latest NixOS (21.05):
It's caused by the Mozilla Rust overlay using deprecated nixpkgs "API": https://github.com/mozilla/nixpkgs-mozilla/pull/250
Until the upstream Mozilla overlay PR gets merged, a workaround can be used: