diff --git a/nixos/modules/system/etc/etc.nix b/nixos/modules/system/etc/etc.nix index 7547f4304709..e8eeae03a360 100644 --- a/nixos/modules/system/etc/etc.nix +++ b/nixos/modules/system/etc/etc.nix @@ -276,6 +276,22 @@ in # Unmount the top /etc mount to atomically reveal the new mount. umount --lazy --recursive /etc + + # Unmount the temporary mount + umount --lazy "$tmpEtcMount" + rmdir "$tmpEtcMount" + + # Unmount old metadata mounts + # For some reason, `findmnt /tmp --submounts` does not show the nested + # mounts. So we'll just find all mounts of type erofs and filter on the + # name of the mountpoint. + findmnt --type erofs --list --kernel --output TARGET | while read -r mountPoint; do + if [[ "$mountPoint" =~ ^/tmp/nixos-etc-metadata\..{10}$ && + "$mountPoint" != "$tmpMetadataMount" ]]; then + umount --lazy $mountPoint + rmdir "$mountPoint" + fi + done fi '' else '' # Set up the statically computed bits of /etc.