From 68dae2e1f058c0d60ea1d8fabb79f2e502b12d1c Mon Sep 17 00:00:00 2001 From: eyjhb Date: Sat, 5 Oct 2024 21:18:27 +0200 Subject: [PATCH] fixed targets not working --- src/modules/languages/rust.nix | 39 +++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/src/modules/languages/rust.nix b/src/modules/languages/rust.nix index b4cc2ce3d..381cd5278 100644 --- a/src/modules/languages/rust.nix +++ b/src/modules/languages/rust.nix @@ -9,6 +9,35 @@ let attribute = "languages.rust.input"; follows = [ "nixpkgs" ]; }; + + # https://github.com/nix-community/fenix/blob/cdfd7bf3e3edaf9e3f6d1e397d3ee601e513613c/lib/combine.nix + combine = name: paths: + pkgs.symlinkJoin { + inherit name paths; + postBuild = '' + for file in $(find $out/bin -xtype f -maxdepth 1); do + install -m755 $(realpath "$file") $out/bin + + if [[ $file =~ /rustfmt$ ]]; then + continue + fi + + ${lib.optionalString pkgs.stdenv.isLinux '' + if isELF "$file"; then + patchelf --set-rpath $out/lib "$file" || true + fi + ''} + + ${lib.optionalString pkgs.stdenv.isDarwin '' + install_name_tool -add_rpath $out/lib "$file" || true + ''} + done + + for file in $(find $out/lib -name "librustc_driver-*"); do + install $(realpath "$file") "$file" + done + ''; + }; in { imports = [ @@ -173,15 +202,19 @@ in (lib.mkIf (cfg.channel != "nixpkgs") ( let - toolchain = (rust-overlay.lib.mkRustBin {} pkgs)."${cfg.channel}"."${cfg.version}"; - # filter toolchain, otherwise it contains a bunch of non-rust stuff (llvm-tools, etc.) + toolchain = (rust-overlay.lib.mkRustBin {} pkgs.buildPackages)."${cfg.channel}"."${cfg.version}"; filteredToolchain = (lib.filterAttrs (n: _: builtins.elem n toolchain._manifest.profiles.complete) toolchain); in { languages.rust.toolchain = (builtins.mapAttrs (_: pkgs.lib.mkDefault) filteredToolchain); - packages = builtins.attrValues (lib.filterAttrs (n: _: builtins.elem n cfg.components) cfg.toolchain); + packages = [ + (combine "rust-mixed" ( + (map (c: toolchain.${c}) cfg.components) ++ + (map (t: toolchain._components.${t}.rust-std) cfg.targets) + )) + ]; } )) ]);