selinux fix

This commit is contained in:
randogoth 2026-01-14 19:45:46 +02:00
parent 8e33e4fa3f
commit f65c6846f7
4 changed files with 23 additions and 2 deletions

View file

@ -0,0 +1,2 @@
/nix(/.*)? system_u:object_r:bin_t:s0
/var/lib/nix-store(/.*)? system_u:object_r:bin_t:s0

View file

@ -0,0 +1,5 @@
[Service]
# Run the daemon unconfined to avoid SELinux denials on the Nix store binaries.
SELinuxContext=system_u:system_r:unconfined_service_t:s0
ExecStart=
ExecStart=/usr/bin/nix-daemon-wrapper.sh --daemon

View file

@ -14,6 +14,13 @@ copy_seed_store() {
fi
}
sync_missing_store() {
# Ensure any baked store paths exist in /var without clobbering user additions.
if command -v rsync >/dev/null 2>&1; then
rsync -aH --ignore-existing /usr/share/nix-store/store/ /var/lib/nix-store/store/
fi
}
ensure_system_profile() {
local seed_profile="/usr/share/nix-store/var/nix/profiles/system"
local target_profile="/var/lib/nix-store/var/nix/profiles/system"
@ -21,7 +28,7 @@ ensure_system_profile() {
mkdir -p /var/lib/nix-store/var/nix/profiles
if { [ ! -e "$target_profile" ] || [ -L "$target_profile" ] && [ ! -e "$(readlink -f "$target_profile")" ]; } \
&& [ -e "$seed_profile" ]; then
&& { [ -e "$seed_profile" ] || [ -L "$seed_profile" ]; }; then
cp -a "$seed_profile" "$target_profile"
fi
}
@ -32,9 +39,14 @@ if ! mountpoint -q /nix; then
fi
ensure_system_profile
sync_missing_store
mount --bind /var/lib/nix-store /nix
# Force an executable SELinux context on the bind mount so systemd can exec nix-daemon.
# Use a permissive fallback if the label option is rejected.
if ! mount -o remount,bind,exec,context=system_u:object_r:bin_t:s0 /nix 2>/dev/null; then
mount -o remount,bind,exec /nix
fi
# Ensure daemon paths exist and labels are sane.
if command -v systemd-tmpfiles >/dev/null 2>&1; then

View file

@ -0,0 +1,2 @@
#!/usr/bin/env bash
exec /nix/var/nix/profiles/system/bin/nix-daemon "$@"