Skip to content

Commit 3ee94e1

Browse files
author
cfhammill
committed
add the dynamic nixGL wrapper
1 parent 9d3784a commit 3ee94e1

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Diff for: dynamicWrapper.nix

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
pkgs,
3+
writeTextFile,
4+
runtimeShell,
5+
gnugrep,
6+
gnused,
7+
shellcheck,
8+
pcre
9+
}:
10+
11+
writeTextFile rec {
12+
name = "nixGL";
13+
text = ''#!${runtimeShell}
14+
15+
driver_file=/proc/driver/nvidia/version
16+
17+
vers=$(${gnugrep}/bin/grep "Module" "$driver_file" |\
18+
${gnused}/bin/sed -E "s/.*Module ([0-9.]+) .*/\1/")
19+
if [ -z "$vers" ]; then
20+
echo "Failed to parse your driver version from $driver_file. Does $driver_file exist?"
21+
echo "Consider using nixGLNvidia-<version> directly instead."
22+
exit 1
23+
fi
24+
25+
if ! command -v nixGLNvidia-"$vers" &> /dev/null; then
26+
echo "nixGLNvidia wrapper not found for $vers"
27+
exit 1
28+
fi
29+
30+
exec nixGLNvidia-"$vers" "$@"
31+
'';
32+
executable = true;
33+
destination = "/bin/${name}";
34+
checkPhase = ''
35+
${shellcheck}/bin/shellcheck "$out/bin/${name}"
36+
37+
# Check that all the files listed in the output binary exists
38+
for i in $(${pcre}/bin/pcregrep -o0 '/nix/store/.*?/[^ ":]+' $out/bin/${name})
39+
do
40+
ls $i > /dev/null || (echo "File $i, referenced in $out/bin/${name} does not exists."; exit -1)
41+
done
42+
'';
43+
}

Diff for: flake.nix

+3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
enable32bits = isIntelX86Platform;
1414
enableIntelX86Extensions = isIntelX86Platform;
1515
};
16+
1617
in rec {
1718

1819
packages = {
@@ -39,6 +40,8 @@
3940
pkgs = final;
4041
enable32bits = isIntelX86Platform;
4142
enableIntelX86Extensions = isIntelX86Platform;
43+
} // {
44+
nixGLDynamic = final.callPackage ./dynamicWrapper.nix {};
4245
};
4346
};
4447
};

0 commit comments

Comments
 (0)