From f0e5b8bf3d27fd3d4be484d36d85e6fa5ebfda62 Mon Sep 17 00:00:00 2001 From: Sander Date: Wed, 22 May 2024 15:36:43 +0000 Subject: [PATCH] rust: assert that targets are not used with nixpkgs channel --- src/modules/languages/rust.nix | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix index b8d427b49..9a9f0ee6a 100644 --- a/src/modules/languages/rust.nix +++ b/src/modules/languages/rust.nix @@ -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=$(${ @@ -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 @@ -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};