Skip to content

Commit 55d1899

Browse files
timon-schellingFirestar99
authored andcommitted
nix: Add exec with rust-gpu env script to flake
1 parent 2f91852 commit 55d1899

File tree

1 file changed

+20
-31
lines changed

1 file changed

+20
-31
lines changed

.nix/flake.nix

Lines changed: 20 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -35,22 +35,19 @@
3535
};
3636

3737
rustExtensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" ];
38-
3938
rust = pkgs.rust-bin.stable.latest.default.override {
4039
targets = [ "wasm32-unknown-unknown" ];
4140
extensions = rustExtensions;
4241
};
4342

44-
rustNightlyPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
43+
rustGPUToolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
4544
extensions = rustExtensions ++ [ "rustc-dev" "llvm-tools" ];
4645
};
47-
48-
rustPlatformNightly = pkgs.makeRustPlatform {
49-
cargo = rustNightlyPkg;
50-
rustc = rustNightlyPkg;
46+
rustGPUToolchainRustPlatform = pkgs.makeRustPlatform {
47+
cargo = rustGPUToolchainPkg;
48+
rustc = rustGPUToolchainPkg;
5149
};
52-
53-
rustc_codegen_spirv = rustPlatformNightly.buildRustPackage (finalAttrs: {
50+
rustc_codegen_spirv = rustGPUToolchainRustPlatform.buildRustPackage (finalAttrs: {
5451
pname = "rustc_codegen_spirv";
5552
version = "0-unstable-2025-08-04";
5653
src = pkgs.fetchFromGitHub {
@@ -60,32 +57,29 @@
6057
hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno=";
6158
};
6259
cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4=";
63-
6460
cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-installed-tools" "--no-default-features" ];
6561
doCheck = false;
6662
});
6763

68-
cargoGpuPkg = rustPlatformNightly.buildRustPackage (finalAttrs: {
69-
pname = "cargo-gpu";
70-
version = "0-unstable-2025-07-24";
71-
src = pkgs.fetchFromGitHub {
72-
owner = "Rust-GPU";
73-
repo = "cargo-gpu";
74-
rev = "a2ad3574dd32142ff661994e0d79448a45d18f47";
75-
hash = "sha256-YGu9Cuw+pcN9/rCuCxImouzsQ3ScHF+cW6zgxMm0XGI=";
76-
};
77-
cargoHash = "sha256-tyad9kO90uwAnMQYa09takIBXifrumSx2C4rpSK95aM=";
64+
# Wrapper script for running rust commands with the rust toolchain used by rust-gpu.
65+
# For example `rust-gpu cargo --version` or `rust-gpu rustc --version`.
66+
execWithRustGPUEnvironment = pkgs.writeShellScriptBin "rust-gpu" ''
67+
#!${pkgs.lib.getExe pkgs.bash}
7868
79-
doCheck = false;
80-
});
69+
filtered_args=()
70+
for arg in "$@"; do
71+
case "$arg" in
72+
+nightly|+nightly-*) ;;
73+
*) filtered_args+=("$arg") ;;
74+
esac
75+
done
8176
82-
cargoNightlyPkg = pkgs.writeShellScriptBin "cargo-nightly" ''
83-
#!${pkgs.bash}/bin/bash
77+
export PATH="${pkgs.lib.makeBinPath [ rustGPUToolchainPkg pkgs.spirv-tools ]}:$PATH"
78+
export RUSTC_CODEGEN_SPIRV_PATH="${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so"
8479
85-
exec ${rustNightlyPkg}/bin/cargo $@
80+
exec ${"\${filtered_args[@]}"}
8681
'';
8782

88-
8983
libcef = pkgs.libcef.overrideAttrs (finalAttrs: previousAttrs: {
9084
version = "139.0.17";
9185
gitRevision = "6c347eb";
@@ -98,7 +92,6 @@
9892
strip $out/lib/*
9993
'';
10094
});
101-
10295
libcefPath = pkgs.runCommand "libcef-path" {} ''
10396
mkdir -p $out
10497
@@ -145,9 +138,7 @@
145138
# Linker
146139
pkgs.mold
147140

148-
pkgs.spirv-tools
149-
cargoNightlyPkg
150-
cargoGpuPkg
141+
execWithRustGPUEnvironment
151142
];
152143
# Development tools that don't need to be in LD_LIBRARY_PATH
153144
devTools = with pkgs; [
@@ -170,8 +161,6 @@
170161
CEF_PATH = libcefPath;
171162
XDG_DATA_DIRS="${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
172163

173-
RUSTC_CODEGEN_SPIRV="${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
174-
175164
shellHook = ''
176165
alias cargo='mold --run cargo'
177166
'';

0 commit comments

Comments
 (0)