diff --git a/flake.lock b/flake.lock index a344611..4b7fa0f 100644 --- a/flake.lock +++ b/flake.lock @@ -81,11 +81,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1682669017, - "narHash": "sha256-Vi+p4y3wnl0/4gcwTdmCO398kKlDaUrNROtf3GOD2NY=", + "lastModified": 1682817260, + "narHash": "sha256-kFMXzKNj4d/0Iqbm5l57rHSLyUeyCLMuvlROZIuuhvk=", "owner": "nixos", "repo": "nixpkgs", - "rev": "7449971a3ecf857b4a554cf79b1d9dcc1a4647d8", + "rev": "db1e4eeb0f9a9028bcb920e00abbc1409dd3ef36", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index eca6957..ddab2a3 100644 --- a/flake.nix +++ b/flake.nix @@ -22,23 +22,12 @@ let inherit (gitignore.lib) gitignoreSource; - mkToolchain = buildPlatform: - fenix.packages.${buildPlatform}.minimal.toolchain; - - mkToolchainWithTarget = buildPlatform: targetPlatform: - with fenix.packages.${buildPlatform}; combine [ - stable.rustc - stable.cargo - targets.${targetPlatform}.stable.rust-std - ]; + mkToolchain = import ./rust-toolchain.nix fenix; mkDevShells = buildPlatform: let pkgs = import nixpkgs { system = buildPlatform; }; - rust-toolchain = fenix.packages.${buildPlatform}.fromToolchainFile { - file = ./rust-toolchain.toml; - sha256 = "eMJethw5ZLrJHmoN2/l0bIyQjoTX1NsvalWSscTixpI="; - }; + rust-toolchain = mkToolchain.fromFile { system = buildPlatform; }; in { default = pkgs.mkShell { @@ -58,10 +47,9 @@ mkPackage = pkgs: buildPlatform: targetPlatform: package: let - toolchain = - if isNull targetPlatform - then mkToolchain buildPlatform - else mkToolchainWithTarget buildPlatform targetPlatform; + toolchain = mkToolchain.fromTarget { + inherit pkgs buildPlatform targetPlatform; + }; naersk' = naersk.lib.${buildPlatform}.override { cargo = toolchain; rustc = toolchain; diff --git a/rust-toolchain.nix b/rust-toolchain.nix new file mode 100644 index 0000000..64dccb8 --- /dev/null +++ b/rust-toolchain.nix @@ -0,0 +1,27 @@ +fenix: + +let + file = ./rust-toolchain.toml; + sha256 = "eMJethw5ZLrJHmoN2/l0bIyQjoTX1NsvalWSscTixpI="; +in +{ + fromFile = { system }: fenix.packages.${system}.fromToolchainFile { + inherit file sha256; + }; + + fromTarget = { pkgs, buildPlatform, targetPlatform ? null }: + let + inherit ((pkgs.lib.importTOML file).toolchain) channel; + toolchain = fenix.packages.${buildPlatform}; + in + if + isNull targetPlatform + then + fenix.packages.${buildPlatform}.${channel}.toolchain + else + toolchain.combine [ + toolchain.${channel}.rustc + toolchain.${channel}.cargo + toolchain.targets.${targetPlatform}.${channel}.rust-std + ]; +}