nixos/etc: make re-mounting /etc overlay idempotent

This commit is contained in:
nikstur 2024-02-21 22:54:00 +01:00
parent 1e1efbcf8c
commit 5df8caced4
3 changed files with 25 additions and 11 deletions

View file

@ -238,7 +238,9 @@ in
# this should not run because /etc is mounted via a systemd mount unit
# instead. To a large extent this mimics what composefs does. Because
# it's relatively simple, however, we avoid the composefs dependency.
if [[ ! $IN_NIXOS_SYSTEMD_STAGE1 ]]; then
# Since this script is not idempotent, it should not run when etc hasn't
# changed.
if [[ ! $IN_NIXOS_SYSTEMD_STAGE1 ]] && [[ "${config.system.build.etc}/etc" != "$(readlink -f /run/current-system/etc)" ]]; then
echo "remounting /etc..."
tmpMetadataMount=$(mktemp --directory)

View file

@ -20,11 +20,17 @@
};
testScript = ''
machine.succeed("findmnt --kernel --type overlay /etc")
machine.fail("stat /etc/newgen")
with subtest("/etc is mounted as an overlay"):
machine.succeed("findmnt --kernel --type overlay /etc")
machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
with subtest("switching to the same generation"):
machine.succeed("/run/current-system/bin/switch-to-configuration test")
assert machine.succeed("cat /etc/newgen") == "newgen"
with subtest("switching to a new generation"):
machine.fail("stat /etc/newgen")
machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
assert machine.succeed("cat /etc/newgen") == "newgen"
'';
}

View file

@ -18,13 +18,19 @@
};
testScript = ''
machine.succeed("findmnt --kernel --type overlay /etc")
machine.fail("stat /etc/newgen")
machine.succeed("echo -n 'mutable' > /etc/mutable")
with subtest("/etc is mounted as an overlay"):
machine.succeed("findmnt --kernel --type overlay /etc")
machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
with subtest("switching to the same generation"):
machine.succeed("/run/current-system/bin/switch-to-configuration test")
assert machine.succeed("cat /etc/newgen") == "newgen"
assert machine.succeed("cat /etc/mutable") == "mutable"
with subtest("switching to a new generation"):
machine.fail("stat /etc/newgen")
machine.succeed("echo -n 'mutable' > /etc/mutable")
machine.succeed("/run/current-system/specialisation/new-generation/bin/switch-to-configuration switch")
assert machine.succeed("cat /etc/newgen") == "newgen"
assert machine.succeed("cat /etc/mutable") == "mutable"
'';
}