gpu: use tmpfiles.d to set up the /run/opengl-driver symlink

Signed-off-by: Esteve Fernandez <esteve@apache.org>
This commit is contained in:
Esteve Fernandez 2026-05-04 22:17:46 +02:00 committed by Matthieu Coudron
parent a89686d115
commit 5be632dab0
8 changed files with 43 additions and 31 deletions

View file

@ -20,12 +20,12 @@ stdenv.mkDerivation {
substituteInPlace non-nixos-gpu* \
--replace-quiet '@@resources@@' "$out/resources" \
--replace-quiet '@@statedir@@' '${nixStateDirectory}' \
--replace-quiet '@@systemddir@@' "$out/lib/systemd/system" \
--replace-quiet '@@tmpfilesdir@@' "$out/lib/tmpfiles.d" \
--replace-quiet '@@env@@' "${nonNixosGpuEnv}"
'';
installPhase = ''
mkdir -p $out/{bin,resources,lib/systemd/system}
mkdir -p $out/{bin,resources,lib/tmpfiles.d}
cp non-nixos-gpu-setup $out/bin
cp non-nixos-gpu.service $out/lib/systemd/system
cp non-nixos-gpu.conf $out/lib/tmpfiles.d
'';
}

View file

@ -2,12 +2,19 @@
set -e
# Install the systemd service file and ensure that the store path won't be
# garbage-collected as long as it's installed.
unit_path=/etc/systemd/system/non-nixos-gpu.service
ln -sf @@systemddir@@/non-nixos-gpu.service "$unit_path"
ln -sf "$unit_path" "@@statedir@@"/gcroots/non-nixos-gpu.service
# Migrate from old systemd service setup
old_unit=/etc/systemd/system/non-nixos-gpu.service
if [[ -L "$old_unit" || -f "$old_unit" ]]; then
systemctl disable --now non-nixos-gpu.service 2>/dev/null || true
rm -f "$old_unit"
rm -f "@@statedir@@/gcroots/non-nixos-gpu.service"
systemctl daemon-reload
fi
systemctl daemon-reload
systemctl enable non-nixos-gpu.service
systemctl restart non-nixos-gpu.service
# Install the tmpfiles.d config file and ensure that the store path won't be
# garbage-collected as long as it's installed.
conf_path=/etc/tmpfiles.d/non-nixos-gpu.conf
ln -sf @@tmpfilesdir@@/non-nixos-gpu.conf "$conf_path"
ln -sf "$conf_path" "@@statedir@@"/gcroots/non-nixos-gpu.conf
systemd-tmpfiles --create non-nixos-gpu.conf

View file

@ -0,0 +1 @@
L+ /run/opengl-driver - - - - @@env@@

View file

@ -1,10 +0,0 @@
[Unit]
Description=GPU driver setup for Nix on non-NixOS Linux systems
[Install]
WantedBy=multi-user.target
[Service]
Type=oneshot
ExecStart=ln -nsf @@env@@ /run/opengl-driver
RemainAfterExit=yes