nix: get rust toolchain from rust-overlay

Now, a nix-shell always has the latest rust stable version, compliant to our
rust-toolchain.toml file.
This commit is contained in:
Philipp Schuster 2023-11-14 12:51:43 +01:00
parent dffe5886a9
commit b65cac29bf
5 changed files with 49 additions and 17 deletions

6
nix/nixpkgs.nix Normal file
View file

@ -0,0 +1,6 @@
let
sources = import ./sources.nix { };
rust-overlay = import sources.rust-overlay;
in
import sources.nixpkgs { overlays = [ rust-overlay ]; }

10
nix/rust-toolchain.nix Normal file
View file

@ -0,0 +1,10 @@
# Returns the Rust toolchain for Nix compliant to the rust-toolchain.toml file
# but without rustup.
{
# Comes from rust-overlay
rust-bin
}:
# Includes rustc, cargo, rustfmt, etc
rust-bin.fromRustupToolchainFile ../rust-toolchain.toml

View file

@ -1,14 +1,26 @@
{ {
"nixpkgs": { "nixpkgs": {
"branch": "nixos-23.05", "branch": "nixos-23.05",
"description": "Nix Packages collection", "description": "Nix Packages collection",
"homepage": null, "homepage": null,
"owner": "NixOS", "owner": "NixOS",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "6b0edc9c690c1d8a729f055e0d73439045cfda55", "rev": "6b0edc9c690c1d8a729f055e0d73439045cfda55",
"sha256": "1fdsnmkcz1h5wffjci29af4jrd68pzdvrhbs083niwqfd6ssm633", "sha256": "1fdsnmkcz1h5wffjci29af4jrd68pzdvrhbs083niwqfd6ssm633",
"type": "tarball", "type": "tarball",
"url": "https://github.com/NixOS/nixpkgs/archive/6b0edc9c690c1d8a729f055e0d73439045cfda55.tar.gz", "url": "https://github.com/NixOS/nixpkgs/archive/6b0edc9c690c1d8a729f055e0d73439045cfda55.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz" "url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
} },
"rust-overlay": {
"branch": "master",
"description": "Pure and reproducible nix overlay of binary distributed rust toolchains",
"homepage": "",
"owner": "oxalica",
"repo": "rust-overlay",
"rev": "e485313fc485700a9f1f9b8b272ddc0621d08357",
"sha256": "1v1gq022rnni6mm42pxmw6c5yy9il4jb2l92irh154ax616x2rzd",
"type": "tarball",
"url": "https://github.com/oxalica/rust-overlay/archive/e485313fc485700a9f1f9b8b272ddc0621d08357.tar.gz",
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
}
} }

View file

@ -1,2 +1,5 @@
[toolchain] [toolchain]
channel = "stable"
# cargo, clippy, rustc, rust-docs, rustfmt, rust-std
profile = "default"
targets = ["aarch64-unknown-uefi", "i686-unknown-uefi", "x86_64-unknown-uefi"] targets = ["aarch64-unknown-uefi", "i686-unknown-uefi", "x86_64-unknown-uefi"]

View file

@ -2,10 +2,11 @@
# "cargo xtask run|test|clippy". It uses rustup rather than a pinned rust # "cargo xtask run|test|clippy". It uses rustup rather than a pinned rust
# toolchain. # toolchain.
{ sources ? import ./nix/sources.nix { } let
, pkgs ? import sources.nixpkgs { } sources = import ./nix/sources.nix;
}: pkgs = import ./nix/nixpkgs.nix;
rustToolchain = pkgs.callPackage ./nix/rust-toolchain.nix {};
in
pkgs.mkShell { pkgs.mkShell {
nativeBuildInputs = with pkgs; [ nativeBuildInputs = with pkgs; [
# nix related stuff (such as dependency management) # nix related stuff (such as dependency management)
@ -17,7 +18,7 @@ pkgs.mkShell {
qemu qemu
# Rust toolchain # Rust toolchain
rustup rustToolchain
# Other # Other
yamlfmt yamlfmt