From 452102db8fe678aea06eb6904895ec2e4f842c4b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Janne=20He=C3=9F?= Date: Thu, 24 Mar 2022 21:00:37 +0100 Subject: [PATCH] nixos/stage-2-init: Clean up legacy commands We can perform most of the mkdir/ln/rm using systemd-tmpfiles instead which cleans up the script. /bin and /home are created by their activation script snippets usbfs is deprecated and unused. hwclock seems to be automatically executed by systemd on startup. The mkswap to prevent hibernation cycles seems to be executed by systemd as well since the provided regression tests succeeds. --- nixos/modules/system/boot/stage-2-init.sh | 53 +------------------ .../modules/system/boot/systemd/tmpfiles.nix | 17 ++++++ nixos/tests/hibernate.nix | 5 ++ 3 files changed, 23 insertions(+), 52 deletions(-) diff --git a/nixos/modules/system/boot/stage-2-init.sh b/nixos/modules/system/boot/stage-2-init.sh index a90f58042d2..1713efb06c2 100755 --- a/nixos/modules/system/boot/stage-2-init.sh +++ b/nixos/modules/system/boot/stage-2-init.sh @@ -12,10 +12,6 @@ for o in $(&1 {logErrFd}>&2 @@ -133,22 +95,9 @@ echo "running activation script..." $systemConfig/activate -# Restore the system time from the hardware clock. We do this after -# running the activation script to be sure that /etc/localtime points -# at the current time zone. -if [ -e /dev/rtc ]; then - hwclock --hctosys -fi - - # Record the boot configuration. ln -sfn "$systemConfig" /run/booted-system -# Prevent the booted system from being garbage-collected. If it weren't -# a gcroot, if we were running a different kernel, switched system, -# and garbage collected all, we could not load kernel modules anymore. -ln -sfn /run/booted-system /nix/var/nix/gcroots/booted-system - # Run any user-specified commands. @shell@ @postBootCommands@ diff --git a/nixos/modules/system/boot/systemd/tmpfiles.nix b/nixos/modules/system/boot/systemd/tmpfiles.nix index 57d44c8591e..edbe5996556 100644 --- a/nixos/modules/system/boot/systemd/tmpfiles.nix +++ b/nixos/modules/system/boot/systemd/tmpfiles.nix @@ -100,5 +100,22 @@ in ''; }) ]; + + systemd.tmpfiles.rules = [ + "d /etc/nixos 0755 root root - -" + "d /nix/var 0755 root root - -" + "L+ /nix/var/nix/gcroots/booted-system 0755 root root - /run/booted-system" + "d /run/lock 0755 root root - -" + "d /var/db 0755 root root - -" + "L /etc/mtab - - - - ../proc/mounts" + "L /var/lock - - - - ../run/lock" + # Boot-time cleanup + "R! /etc/group.lock - - - - -" + "R! /etc/passwd.lock - - - - -" + "R! /etc/shadow.lock - - - - -" + "R! /etc/mtab* - - - - -" + "R! /nix/var/nix/gcroots/tmp - - - - -" + "R! /nix/var/nix/temproots - - - - -" + ]; }; } diff --git a/nixos/tests/hibernate.nix b/nixos/tests/hibernate.nix index 3880f1649bd..032ac6527bc 100644 --- a/nixos/tests/hibernate.nix +++ b/nixos/tests/hibernate.nix @@ -117,6 +117,11 @@ in makeTest { resume = create_named_machine("resume") resume.start() resume.succeed("grep 'not persisted to disk' /run/test/suspended") + + # Ensure we don't restore from hibernation when booting again + resume.crash() + resume.wait_for_unit("default.target") + resume.fail("grep 'not persisted to disk' /run/test/suspended") ''; }