From d820fe987ecc555f250633db6f78f0d3b72e010c Mon Sep 17 00:00:00 2001 From: nikstur Date: Thu, 22 Aug 2024 12:12:17 +0200 Subject: [PATCH 1/2] nixos/etc: wantedBy -> requiredBy for mounting overlay etc I've observed that sometimes the overlay mount unit does not get started when using wantedBy. requiredBy makes this relationship stricter and if necessary will restart the initrd-fs.target and thus ensure that when this target is reached /etc has alredy been mounted. This is in line with the description of initrd-fs.target in systemd.special: > Thus, once this target is reached the /sysroot/ hierarchy is fully set up --- nixos/modules/system/etc/etc-activation.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/system/etc/etc-activation.nix b/nixos/modules/system/etc/etc-activation.nix index f47fd771c659..ed9f50941771 100644 --- a/nixos/modules/system/etc/etc-activation.nix +++ b/nixos/modules/system/etc/etc-activation.nix @@ -64,7 +64,7 @@ ] ++ lib.optionals (!config.system.etc.overlay.mutable) [ "ro" ]); - wantedBy = [ "initrd-fs.target" ]; + requiredBy = [ "initrd-fs.target" ]; before = [ "initrd-fs.target" ]; requires = lib.mkIf config.system.etc.overlay.mutable [ "rw-etc.service" ]; after = lib.mkIf config.system.etc.overlay.mutable [ "rw-etc.service" ]; From 7845b89e24ff9e91e6e13f66ee5a1a73958d22fb Mon Sep 17 00:00:00 2001 From: nikstur Date: Thu, 22 Aug 2024 12:17:18 +0200 Subject: [PATCH 2/2] nixos/etc: unmount old /etc hierarchy lazily This should fix errors where /etc is reported to be busy and thus cannot be unmounted. Another solution we can consider if this doesn't work out as we expect is to forcefully unmount /etc. --- nixos/modules/system/etc/etc.nix | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/nixos/modules/system/etc/etc.nix b/nixos/modules/system/etc/etc.nix index 69f4ab92548f..ae186467ee6b 100644 --- a/nixos/modules/system/etc/etc.nix +++ b/nixos/modules/system/etc/etc.nix @@ -279,7 +279,7 @@ in ${pkgs.move-mount-beneath}/bin/move-mount --move --beneath $tmpEtcMount /etc # Unmount the top /etc mount to atomically reveal the new mount. - umount --recursive /etc + umount --lazy --recursive /etc fi '' else '' # Set up the statically computed bits of /etc.