From 9a48700fe730e1b711196b64a486d5f66aed06b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Domen=20Ko=C5=BEar?= Date: Sat, 5 Oct 2024 08:28:55 +0100 Subject: [PATCH] rust: set empty flags if empty --- src/modules/languages/rust.nix | 7 ++++--- tests/rust/devenv.nix | 10 ++++++++++ 2 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 tests/rust/devenv.nix diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix index 960f81019..60be70fd3 100644 --- a/src/modules/languages/rust.nix +++ b/src/modules/languages/rust.nix @@ -35,7 +35,7 @@ in defaultText = lib.literalExpression ''[ ]''; description = '' List of extra [targets](https://github.com/nix-community/fenix#supported-platforms-and-targets) - to install. Defaults to only the native target. + to install. Defaults to only the native target. ''; }; @@ -128,6 +128,7 @@ in env = let moldFlags = lib.optionalString cfg.mold.enable "-C link-arg=-fuse-ld=mold"; + optionalEnv = cond: str: if cond then str else null; in { # RUST_SRC_PATH is necessary when rust-src is not at the same location as @@ -136,8 +137,8 @@ in if cfg.toolchain ? rust-src then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library" else pkgs.rustPlatform.rustLibSrc; - RUSTFLAGS = "${moldFlags} ${cfg.rustflags}"; - RUSTDOCFLAGS = "${moldFlags}"; + RUSTFLAGS = optionalEnv (moldFlags != "" || cfg.rustflags != "") (lib.concatStringsSep " " (lib.filter (x: x != "") [moldFlags cfg.rustflags])); + RUSTDOCFLAGS = optionalEnv (moldFlags != "") moldFlags; CFLAGS = lib.optionalString pkgs.stdenv.isDarwin "-iframework ${config.devenv.profile}/Library/Frameworks"; }; diff --git a/tests/rust/devenv.nix b/tests/rust/devenv.nix new file mode 100644 index 000000000..fa7a5b7f6 --- /dev/null +++ b/tests/rust/devenv.nix @@ -0,0 +1,10 @@ +{ + languages.rust.enable = true; + languages.rust.mold.enable = false; + enterTest = '' + if [ -n "$RUSTFLAGS" ]; then + echo "RUSTFLAGS is set, but it should not be" + exit 1 + fi + ''; +}