Skip to content

Commit

Permalink
Merge pull request #1224 from cachix/fix-1223
Browse files Browse the repository at this point in the history
rust: assert that targets are not used with nixpkgs channel
  • Loading branch information
domenkozar committed May 22, 2024
2 parents 38bf350 + f0e5b8b commit a205e17
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/modules/languages/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,20 @@ in
mkOverrideTools = lib.mkOverride (lib.modules.defaultOverridePriority - 1);
in
{
assertions = [
{
assertion = cfg.channel == "nixpkgs" -> (cfg.targets == [ ]);
message = ''
Cannot use `languages.rust.channel = "nixpkgs"` with `languages.rust.targets`.
The nixpkgs channel does not support cross-compiling with targets.
Use the stable, beta, or nightly channels instead. For example:
languages.rust.channel = "stable";
'';
}
];

# Set $CARGO_INSTALL_ROOT so that executables installed by `cargo install` can be found from $PATH
enterShell = ''
export CARGO_INSTALL_ROOT=$(${
Expand All @@ -100,9 +114,6 @@ in

packages =
lib.optional cfg.mold.enable pkgs.mold-wrapped
# If there are targets we want to add the whole toolchain instead
# TODO: It might always be fine to add the whole toolchain when not using `nixpkgs`
++ lib.optionals (cfg.targets == [ ]) (builtins.map (c: cfg.toolchain.${c} or (throw "toolchain.${c}")) cfg.components)
++ lib.optional pkgs.stdenv.isDarwin pkgs.libiconv;

# enable compiler tooling by default to expose things like cc
Expand Down Expand Up @@ -131,6 +142,10 @@ in
}
)

(lib.mkIf (cfg.channel == "nixpkgs") {
packages = builtins.map (c: cfg.toolchain.${c} or (throw "toolchain.${c}")) cfg.components;
})

(lib.mkIf (cfg.channel != "nixpkgs") (
let
rustPackages = fenix.packages.${pkgs.stdenv.system};
Expand Down

0 comments on commit a205e17

Please sign in to comment.