diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix index 4499f5217..987a12211 100644 --- a/src/modules/languages/rust.nix +++ b/src/modules/languages/rust.nix @@ -82,23 +82,28 @@ in # enable compiler tooling by default to expose things like cc languages.c.enable = lib.mkDefault true; - # RUST_SRC_PATH is necessary when rust-src is not at the same location as - # as rustc. This is the case with the rust toolchain from nixpkgs. - env.RUST_SRC_PATH = - if cfg.toolchain ? rust-src - then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library" - else pkgs.rustPlatform.rustLibSrc; + + env = + let + darwinFlags = lib.optionalString pkgs.stdenv.isDarwin "-L framework=${config.devenv.profile}/Library/Frameworks"; + in + { + # RUST_SRC_PATH is necessary when rust-src is not at the same location as + # as rustc. This is the case with the rust toolchain from nixpkgs. + RUST_SRC_PATH = + if cfg.toolchain ? rust-src + then "${cfg.toolchain.rust-src}/lib/rustlib/src/rust/library" + else pkgs.rustPlatform.rustLibSrc; + env.RUSTFLAGS = "${darwinFlags} -C link-arg=-fuse-ld=${pkgs.mold-wrapped}/bin/ld.mold"; + env.RUSTDOCFLAGS = "${darwinFlags} -C link-arg=-fuse-ld=${pkgs.mold-wrapped}/bin/ld.mold"; + env.CFLAGS = "${darwinFlags}"; + }; pre-commit.tools.cargo = mkOverrideTools cfg.toolchain.cargo or null; pre-commit.tools.rustfmt = mkOverrideTools cfg.toolchain.rustfmt or null; pre-commit.tools.clippy = mkOverrideTools cfg.toolchain.clippy or null; } )) - (lib.mkIf (cfg.enable && pkgs.stdenv.isDarwin) { - env.RUSTFLAGS = "-L framework=${config.devenv.profile}/Library/Frameworks"; - env.RUSTDOCFLAGS = "-L framework=${config.devenv.profile}/Library/Frameworks"; - env.CFLAGS = "-iframework ${config.devenv.profile}/Library/Frameworks"; - }) (lib.mkIf (cfg.channel != "nixpkgs") ( let rustPackages = fenix.packages.${pkgs.stdenv.system};