From b75a29cb6ca9b5d2e4823622be84d10a6b2e299f Mon Sep 17 00:00:00 2001 From: Arian van Putten Date: Fri, 1 Mar 2024 12:52:48 +0100 Subject: [PATCH] nixos/lib/make-disk-image.nix: fix systemd-boot-builder clobbering /homeless-shelter systemd-boot-builder.py calls nix-env --list-generations which creates $HOME/.nix-defexpr/channels/nixos if it doesn't exist. This would cause a folder /homeless-shelter to show up in the final image which in turn breaks nix builds in the target image if sandboxing is turned off (as /homeless-shelter is never allowed to exist). --- nixos/lib/make-disk-image.nix | 7 +++++++ nixos/tests/qemu-vm-external-disk-image.nix | 3 +++ 2 files changed, 10 insertions(+) diff --git a/nixos/lib/make-disk-image.nix b/nixos/lib/make-disk-image.nix index da94ef16654c..9bdbf4e0713d 100644 --- a/nixos/lib/make-disk-image.nix +++ b/nixos/lib/make-disk-image.nix @@ -609,6 +609,13 @@ let format' = format; in let ''} # Set up core system link, bootloader (sd-boot, GRUB, uboot, etc.), etc. + + # NOTE: systemd-boot-builder.py calls nix-env --list-generations which + # clobbers $HOME/.nix-defexpr/channels/nixos This would cause a folder + # /homeless-shelter to show up in the final image which in turn breaks + # nix builds in the target image if sandboxing is turned off (through + # __noChroot for example). + export HOME=$TMPDIR NIXOS_INSTALL_BOOTLOADER=1 nixos-enter --root $mountPoint -- /nix/var/nix/profiles/system/bin/switch-to-configuration boot # The above scripts will generate a random machine-id and we don't want to bake a single ID into all our images diff --git a/nixos/tests/qemu-vm-external-disk-image.nix b/nixos/tests/qemu-vm-external-disk-image.nix index a229fc5e3963..c481159511a0 100644 --- a/nixos/tests/qemu-vm-external-disk-image.nix +++ b/nixos/tests/qemu-vm-external-disk-image.nix @@ -69,5 +69,8 @@ in os.environ['NIX_DISK_IMAGE'] = tmp_disk_image.name machine.succeed("findmnt --kernel --source ${rootFsDevice} --target /") + + # Make sure systemd boot didn't clobber this + machine.succeed("[ ! -e /homeless-shelter ]") ''; }