Merge pull request #208643 from ncfavier/installer-test-tmp

This commit is contained in:
Naïm Favier 2023-01-09 13:20:02 +01:00 committed by GitHub
commit b8ee437596
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 2 deletions

5
nixos/modules/installer/tools/nixos-enter.sh Normal file → Executable file
View File

@ -100,8 +100,9 @@ chroot_add_resolv_conf "$mountPoint" || echo "$0: failed to set up resolv.conf"
# Run the activation script. Set $LOCALE_ARCHIVE to supress some Perl locale warnings.
LOCALE_ARCHIVE="$system/sw/lib/locale/locale-archive" IN_NIXOS_ENTER=1 chroot "$mountPoint" "$system/activate" 1>&2 || true
# Create /tmp
chroot "$mountPoint" "$system/sw/bin/systemd-tmpfiles" --create --remove --exclude-prefix=/dev 1>&2 || true
# Create /tmp. This is needed for nix-build and the NixOS activation script to work.
# Hide the unhelpful "failed to replace specifiers" errors caused by missing /etc/machine-id.
chroot "$mountPoint" "$system/sw/bin/systemd-tmpfiles" --create --remove -E 2> /dev/null || true
)
unset TMPDIR

View File

@ -49,6 +49,8 @@ let
boot.loader.systemd-boot.enable = true;
''}
boot.initrd.secrets."/etc/secret" = /etc/nixos/secret;
users.users.alice = {
isNormalUser = true;
home = "/home/alice";
@ -124,6 +126,7 @@ let
}",
"/mnt/etc/nixos/configuration.nix",
)
machine.copy_from_host("${pkgs.writeText "secret" "secret"}", "/mnt/etc/nixos/secret")
with subtest("Perform the installation"):
machine.succeed("nixos-install < /dev/null >&2")
@ -131,6 +134,19 @@ let
with subtest("Do it again to make sure it's idempotent"):
machine.succeed("nixos-install < /dev/null >&2")
with subtest("Check that we can build things in nixos-enter"):
machine.succeed(
"""
nixos-enter -- nix-build --option substitute false -E 'derivation {
name = "t";
builder = "/bin/sh";
args = ["-c" "echo nixos-enter build > $out"];
system = builtins.currentSystem;
preferLocalBuild = true;
}'
"""
)
with subtest("Shutdown system after installation"):
machine.succeed("umount /mnt/boot || true")
machine.succeed("umount /mnt")