mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-07-13 05:38:57 +03:00
nixos/etc: handle mountpoints on top of /etc when switching
The activation script that remounts the /etc overlay now handles other mount points on top of /etc by bind mounting them to the new temporary /etc overlay and then atomically revealing it.
This commit is contained in:
parent
6b71621423
commit
6abbe725ca
3 changed files with 52 additions and 2 deletions
|
@ -247,6 +247,30 @@ in
|
|||
--options lowerdir=$tmpMetadataMount::${config.system.build.etcBasedir},${etcOverlayOptions} \
|
||||
$tmpEtcMount
|
||||
|
||||
# Before moving the new /etc overlay under the old /etc, we have to
|
||||
# move mounts on top of /etc to the new /etc mountpoint.
|
||||
findmnt /etc --submounts --list --noheading --kernel --output TARGET | while read -r mountPoint; do
|
||||
if [[ "$mountPoint" = "/etc" ]]; then
|
||||
continue
|
||||
fi
|
||||
|
||||
tmpMountPoint="$tmpEtcMount/''${mountPoint:5}"
|
||||
${if config.system.etc.overlay.mutable then ''
|
||||
if [[ -f "$mountPoint" ]]; then
|
||||
touch "$tmpMountPoint"
|
||||
elif [[ -d "$mountPoint" ]]; then
|
||||
mkdir -p "$tmpMountPoint"
|
||||
fi
|
||||
'' else ''
|
||||
if [[ ! -e "$tmpMountPoint" ]]; then
|
||||
echo "Skipping undeclared mountpoint in environment.etc: $mountPoint"
|
||||
continue
|
||||
fi
|
||||
''
|
||||
}
|
||||
mount --bind "$mountPoint" "$tmpMountPoint"
|
||||
done
|
||||
|
||||
# Move the new temporary /etc mount underneath the current /etc mount.
|
||||
#
|
||||
# This should eventually use util-linux to perform this move beneath,
|
||||
|
@ -255,8 +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 /etc
|
||||
|
||||
umount --recursive /etc
|
||||
fi
|
||||
'' else ''
|
||||
# Set up the statically computed bits of /etc.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue