fix(nix): normalize after all bootstrap writes

This commit is contained in:
Phoebus 2026-09-28 06:25:09 -07:00
parent 030e87edf5
commit bc0c4b8b2c

View file

@ -188,11 +188,11 @@ fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> {
// Every user must traverse the store and read profiles: the client // Every user must traverse the store and read profiles: the client
// binary, the daemon socket and per-user generations all live under // binary, the daemon socket and per-user generations all live under
// /nix. Staging (`cp -a`) preserves tarball modes and the live shell's // /nix. Staging (`cp -a`) preserves tarball modes and the live shell's
// umask may be restrictive, so normalize the top-level integration // umask may be restrictive, so the top-level integration paths are
// directories explicitly (never the store contents themselves). Proven // normalized at the END of the bootstrap (after every write below).
// by VM boot: without this, `nix` is "command not found" for the user // Proven by VM boot: without this, `nix` is "command not found" for the
// and `sys list --nix` reports Nix as not installed. // user and `sys list --nix` reports Nix as not installed; /etc/nix and
normalize_integration_permissions(root); // /etc/profile.d/nix.sh are unreadable for the same reason.
{ {
use std::os::unix::fs::PermissionsExt; use std::os::unix::fs::PermissionsExt;
let sock = target_path(root, "nix/var/nix/daemon-socket"); let sock = target_path(root, "nix/var/nix/daemon-socket");
@ -258,6 +258,9 @@ fn bootstrap(exec: &Exec, root: &Path, tarball: &Path) -> Result<()> {
} }
let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.service"]); let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.service"]);
let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.socket"]); let _ = crate::portage::chroot(exec, root, "systemctl", &["enable", "nix-daemon.socket"]);
// Normalize AFTER every write above: the config, profile links and unit
// symlinks did not exist when the state directories were created.
normalize_integration_permissions(root);
exec.logger exec.logger
.info(format!("Nix {NIX_VERSION} bootstrapped into the target")); .info(format!("Nix {NIX_VERSION} bootstrapped into the target"));