Skip to content

Commit

Permalink
{activation-scripts,activate-system}: check gcroots before linking
Browse files Browse the repository at this point in the history
When `nix.enable` is off, we don’t necessarily have an active
Nix installation, so there won’t necessarily be an active
`/nix/var/nix/gcroots` directory to link things into. NixOS just skips
this unconditionally when `nix.enable` is off, but that doesn’t
work well with a context in which we usually expect `nix.enable`
to be coupled with an unmanaged system installation of Nix.

(cherry picked from commit 731910a)
  • Loading branch information
emilazy committed Feb 14, 2025
1 parent 67d262f commit d0f10e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion modules/services/activate-system/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
ln -sfn $(cat ${config.system.profile}/systemConfig) /run/current-system
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
if [[ -d /nix/var/nix/gcroots ]]; then
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
fi
${config.system.activationScripts.etcChecks.text}
${config.system.activationScripts.etc.text}
Expand Down
4 changes: 3 additions & 1 deletion modules/system/activation-scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,9 @@ in
ln -sfn "$(readlink -f "$systemConfig")" /run/current-system
# Prevent the current configuration from being garbage-collected.
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
if [[ -d /nix/var/nix/gcroots ]]; then
ln -sfn /run/current-system /nix/var/nix/gcroots/current-system
fi
exit $_status
'';
Expand Down

0 comments on commit d0f10e6

Please sign in to comment.