Skip to content

Commit

Permalink
fixed targets not working
Browse files Browse the repository at this point in the history
  • Loading branch information
eyJhb committed Oct 5, 2024
1 parent b454a69 commit 68dae2e
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions src/modules/languages/rust.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down Expand Up @@ -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)
))
];
}
))
]);
Expand Down

0 comments on commit 68dae2e

Please sign in to comment.