Skip to content

Commit b65cac2

Browse files
committed
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.
1 parent dffe588 commit b65cac2

File tree

5 files changed

+49
-17
lines changed

5 files changed

+49
-17
lines changed

nix/nixpkgs.nix

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
let
2+
sources = import ./sources.nix { };
3+
rust-overlay = import sources.rust-overlay;
4+
in
5+
import sources.nixpkgs { overlays = [ rust-overlay ]; }
6+

nix/rust-toolchain.nix

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Returns the Rust toolchain for Nix compliant to the rust-toolchain.toml file
2+
# but without rustup.
3+
4+
{
5+
# Comes from rust-overlay
6+
rust-bin
7+
}:
8+
9+
# Includes rustc, cargo, rustfmt, etc
10+
rust-bin.fromRustupToolchainFile ../rust-toolchain.toml

nix/sources.json

+24-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,26 @@
11
{
2-
"nixpkgs": {
3-
"branch": "nixos-23.05",
4-
"description": "Nix Packages collection",
5-
"homepage": null,
6-
"owner": "NixOS",
7-
"repo": "nixpkgs",
8-
"rev": "6b0edc9c690c1d8a729f055e0d73439045cfda55",
9-
"sha256": "1fdsnmkcz1h5wffjci29af4jrd68pzdvrhbs083niwqfd6ssm633",
10-
"type": "tarball",
11-
"url": "https://github.com/NixOS/nixpkgs/archive/6b0edc9c690c1d8a729f055e0d73439045cfda55.tar.gz",
12-
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13-
}
2+
"nixpkgs": {
3+
"branch": "nixos-23.05",
4+
"description": "Nix Packages collection",
5+
"homepage": null,
6+
"owner": "NixOS",
7+
"repo": "nixpkgs",
8+
"rev": "6b0edc9c690c1d8a729f055e0d73439045cfda55",
9+
"sha256": "1fdsnmkcz1h5wffjci29af4jrd68pzdvrhbs083niwqfd6ssm633",
10+
"type": "tarball",
11+
"url": "https://github.com/NixOS/nixpkgs/archive/6b0edc9c690c1d8a729f055e0d73439045cfda55.tar.gz",
12+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
13+
},
14+
"rust-overlay": {
15+
"branch": "master",
16+
"description": "Pure and reproducible nix overlay of binary distributed rust toolchains",
17+
"homepage": "",
18+
"owner": "oxalica",
19+
"repo": "rust-overlay",
20+
"rev": "e485313fc485700a9f1f9b8b272ddc0621d08357",
21+
"sha256": "1v1gq022rnni6mm42pxmw6c5yy9il4jb2l92irh154ax616x2rzd",
22+
"type": "tarball",
23+
"url": "https://github.com/oxalica/rust-overlay/archive/e485313fc485700a9f1f9b8b272ddc0621d08357.tar.gz",
24+
"url_template": "https://github.com/<owner>/<repo>/archive/<rev>.tar.gz"
25+
}
1426
}

rust-toolchain.toml

+3
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
[toolchain]
2+
channel = "stable"
3+
# cargo, clippy, rustc, rust-docs, rustfmt, rust-std
4+
profile = "default"
25
targets = ["aarch64-unknown-uefi", "i686-unknown-uefi", "x86_64-unknown-uefi"]

shell.nix

+6-5
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
# "cargo xtask run|test|clippy". It uses rustup rather than a pinned rust
33
# toolchain.
44

5-
{ sources ? import ./nix/sources.nix { }
6-
, pkgs ? import sources.nixpkgs { }
7-
}:
8-
5+
let
6+
sources = import ./nix/sources.nix;
7+
pkgs = import ./nix/nixpkgs.nix;
8+
rustToolchain = pkgs.callPackage ./nix/rust-toolchain.nix {};
9+
in
910
pkgs.mkShell {
1011
nativeBuildInputs = with pkgs; [
1112
# nix related stuff (such as dependency management)
@@ -17,7 +18,7 @@ pkgs.mkShell {
1718
qemu
1819

1920
# Rust toolchain
20-
rustup
21+
rustToolchain
2122

2223
# Other
2324
yamlfmt

0 commit comments

Comments
 (0)