Open thomas-zahner opened 2 weeks ago
From my side, this looks good.
Sorry that we didn't get to go through it during RustLab anymore. A few possible improvements:
let
, make shell.nix a function, taking rust-overlay and pkgs as parameters that default to the values currently set in the variables. This makes them easier to override.
{
rust-overlay ? import (builtins.fetchTarball "https://github.com/oxalica/rust-overlay/archive/master.tar.gz"),
pkgs = import <nixpkgs> { overlays = [ rust-overlay ]; },
rustVersion ? "latest", # using a specific version: "1.62.0"
rust ? pkgs.rust-bin.stable.${rustVersion}.default.override {
extensions = [
"rust-src" # for rust-analyzer
"rust-analyzer" # usable by IDEs like zed-editor
];
},
}:
pkgs.mkShell {
# ...
}
fetchTarball
should be combined with a pinned version and hash to make the result reproducible, e.g.
rust-overlay ? import (fetchTarball {
url = "https://github.com/oxalica/rust-overlay/archive/23c4b3ba5f806fcf25d5a3b6b54fa0d07854c032.tar.gz";
sha256 = "1iy52ms10dcp90r046ida0albxy0qkfk5yhc2ijp4r02hyd63rfr";
}),
@niklaskorz No problem, thank you very much for the detailed comment. I will try to apply your suggestions and merge it this weekend, as I will be attending a local Nix meetup
@niklaskorz @mre I'm now using flakes as they were also suggested by colleagues at the Nix meetup. The Rust version can be easily changed in the variable and it works flawlessly on my side. So if you have no more objections, I will merge this.
Looks good on my end, but I have no idea of Nix.
For info, this config is only working for x86. We should be able to make it compatible with other platforms, for example by using nix-systems. But for now this should suffice.
For info, this config is only working for x86. We should be able to make it compatible with other platforms, for example by using nix-systems. But for now this should suffice.
Supporting multiple systems without external dependencies like flake-utils or nix-systems isn't too hard either, see e.g. https://github.com/niklaskorz/rustlab2024-wgpu/blob/ch1/flake.nix
Edit: Also, it's easy to support both experimental flakes and stable non-flakes users by just importing shell.nix
into your flake.nix
. Or to do it the other way around, you can use https://github.com/edolstra/flake-compat which implements flakes in a backwards-compatible way for users that don't have the experimental flakes feature enabled.
So I've installed Nix OS a week ago. Because of this I created this Nix shell. This way it should be possible to reliably build and develop lychee on any Nix system. I've taken the Custom Rust version example from Nix's documentation and simply added pkg-config and openssl. I'm not proficient at Nix so I'm not sure if this follows best practices. But I know it works on my system and since it's Nix it should basically work on any system :)
@niklaskorz what do you think about this.