fix different toolchain channel between shells and packages

This commit is contained in:
Clément DOUIN 2023-05-01 16:13:31 +02:00
parent ae6fe9a7c1
commit e271ca4293
No known key found for this signature in database
GPG key ID: 353E4A18EE0FAB72
3 changed files with 35 additions and 20 deletions

View file

@ -81,11 +81,11 @@
}, },
"nixpkgs": { "nixpkgs": {
"locked": { "locked": {
"lastModified": 1682669017, "lastModified": 1682817260,
"narHash": "sha256-Vi+p4y3wnl0/4gcwTdmCO398kKlDaUrNROtf3GOD2NY=", "narHash": "sha256-kFMXzKNj4d/0Iqbm5l57rHSLyUeyCLMuvlROZIuuhvk=",
"owner": "nixos", "owner": "nixos",
"repo": "nixpkgs", "repo": "nixpkgs",
"rev": "7449971a3ecf857b4a554cf79b1d9dcc1a4647d8", "rev": "db1e4eeb0f9a9028bcb920e00abbc1409dd3ef36",
"type": "github" "type": "github"
}, },
"original": { "original": {

View file

@ -22,23 +22,12 @@
let let
inherit (gitignore.lib) gitignoreSource; inherit (gitignore.lib) gitignoreSource;
mkToolchain = buildPlatform: mkToolchain = import ./rust-toolchain.nix fenix;
fenix.packages.${buildPlatform}.minimal.toolchain;
mkToolchainWithTarget = buildPlatform: targetPlatform:
with fenix.packages.${buildPlatform}; combine [
stable.rustc
stable.cargo
targets.${targetPlatform}.stable.rust-std
];
mkDevShells = buildPlatform: mkDevShells = buildPlatform:
let let
pkgs = import nixpkgs { system = buildPlatform; }; pkgs = import nixpkgs { system = buildPlatform; };
rust-toolchain = fenix.packages.${buildPlatform}.fromToolchainFile { rust-toolchain = mkToolchain.fromFile { system = buildPlatform; };
file = ./rust-toolchain.toml;
sha256 = "eMJethw5ZLrJHmoN2/l0bIyQjoTX1NsvalWSscTixpI=";
};
in in
{ {
default = pkgs.mkShell { default = pkgs.mkShell {
@ -58,10 +47,9 @@
mkPackage = pkgs: buildPlatform: targetPlatform: package: mkPackage = pkgs: buildPlatform: targetPlatform: package:
let let
toolchain = toolchain = mkToolchain.fromTarget {
if isNull targetPlatform inherit pkgs buildPlatform targetPlatform;
then mkToolchain buildPlatform };
else mkToolchainWithTarget buildPlatform targetPlatform;
naersk' = naersk.lib.${buildPlatform}.override { naersk' = naersk.lib.${buildPlatform}.override {
cargo = toolchain; cargo = toolchain;
rustc = toolchain; rustc = toolchain;

27
rust-toolchain.nix Normal file
View file

@ -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
];
}