2024-05-06 16:42:49 +03:00
|
|
|
source ../common/vars-and-functions.sh
|
2023-05-15 22:34:57 +03:00
|
|
|
|
2024-04-08 04:37:30 +03:00
|
|
|
# The new Linux mount interface does not seem to support remounting
|
|
|
|
# OverlayFS mount points.
|
|
|
|
#
|
|
|
|
# It is not clear whether this is intentional or not:
|
|
|
|
#
|
|
|
|
# The kernel source code [1] would seem to indicate merely remounting
|
|
|
|
# while *changing* mount options is now an error because it erroneously
|
|
|
|
# succeeded (by ignoring those new options) before. However, we are
|
|
|
|
# *not* trying to remount with changed options, and are still hitting
|
|
|
|
# the failure when using the new interface.
|
|
|
|
#
|
|
|
|
# For further details, see these `util-linux` issues:
|
|
|
|
#
|
|
|
|
# - https://github.com/util-linux/util-linux/issues/2528
|
|
|
|
# - https://github.com/util-linux/util-linux/issues/2576
|
|
|
|
#
|
|
|
|
# In the meantime, setting this environment variable to "always" will
|
|
|
|
# force the use of the old mount interface, keeping the remounting
|
|
|
|
# working and these tests passing.
|
|
|
|
#
|
|
|
|
# [1]: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/fs/overlayfs/params.c?id=3006adf3be79cde4d14b1800b963b82b6e5572e0#n549
|
2024-04-06 00:43:14 +03:00
|
|
|
export LIBMOUNT_FORCE_MOUNT2=always
|
|
|
|
|
2023-05-15 22:34:57 +03:00
|
|
|
requireEnvironment () {
|
2023-05-16 06:00:18 +03:00
|
|
|
requireSandboxSupport
|
|
|
|
[[ $busybox =~ busybox ]] || skipTest "no busybox"
|
|
|
|
if [[ $(uname) != Linux ]]; then skipTest "Need Linux for overlayfs"; fi
|
|
|
|
needLocalStore "The test uses --store always so we would just be bypassing the daemon"
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
|
2023-07-25 15:30:21 +03:00
|
|
|
addConfig () {
|
|
|
|
echo "$1" >> "$NIX_CONF_DIR/nix.conf"
|
|
|
|
}
|
|
|
|
|
2023-05-15 22:34:57 +03:00
|
|
|
setupConfig () {
|
2023-07-25 15:30:21 +03:00
|
|
|
addConfig "require-drop-supplementary-groups = false"
|
|
|
|
addConfig "build-users-group = "
|
2024-05-06 16:42:49 +03:00
|
|
|
enableFeatures "local-overlay-store"
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
|
2023-12-11 20:30:40 +02:00
|
|
|
setupStoreDirs () {
|
2023-07-20 12:27:11 +03:00
|
|
|
# Attempt to create store dirs on tmpfs volume.
|
|
|
|
# This ensures lowerdir, upperdir and workdir will be on
|
|
|
|
# a consistent filesystem that fully supports OverlayFS.
|
|
|
|
storeVolume="$TEST_ROOT/stores"
|
|
|
|
mkdir -p "$storeVolume"
|
|
|
|
mount -t tmpfs tmpfs "$storeVolume" || true # But continue anyway if that fails.
|
|
|
|
|
|
|
|
storeA="$storeVolume/store-a"
|
|
|
|
storeBTop="$storeVolume/store-b"
|
2023-07-20 13:03:14 +03:00
|
|
|
storeBRoot="$storeVolume/merged-store"
|
2023-10-25 22:29:11 +03:00
|
|
|
storeB="local-overlay://?root=$storeBRoot&lower-store=$storeA&upper-layer=$storeBTop"
|
2023-05-16 06:00:18 +03:00
|
|
|
# Creating testing directories
|
2023-07-20 12:27:11 +03:00
|
|
|
mkdir -p "$storeVolume"/{store-a/nix/store,store-b,merged-store/nix/store,workdir}
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
# Mounting Overlay Store
|
|
|
|
mountOverlayfs () {
|
|
|
|
mount -t overlay overlay \
|
|
|
|
-o lowerdir="$storeA/nix/store" \
|
|
|
|
-o upperdir="$storeBTop" \
|
2023-07-20 12:27:11 +03:00
|
|
|
-o workdir="$storeVolume/workdir" \
|
2023-07-20 13:03:14 +03:00
|
|
|
"$storeBRoot/nix/store" \
|
2023-05-15 22:34:57 +03:00
|
|
|
|| skipTest "overlayfs is not supported"
|
|
|
|
|
|
|
|
cleanupOverlay () {
|
2023-07-20 13:03:14 +03:00
|
|
|
umount "$storeBRoot/nix/store"
|
2023-07-20 12:27:11 +03:00
|
|
|
rm -r $storeVolume/workdir
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
trap cleanupOverlay EXIT
|
|
|
|
}
|
|
|
|
|
2023-07-19 13:23:54 +03:00
|
|
|
remountOverlayfs () {
|
2023-07-20 13:03:14 +03:00
|
|
|
mount -o remount "$storeBRoot/nix/store"
|
2023-07-19 13:23:54 +03:00
|
|
|
}
|
|
|
|
|
2023-05-15 22:34:57 +03:00
|
|
|
toRealPath () {
|
|
|
|
storeDir=$1; shift
|
|
|
|
storePath=$1; shift
|
2023-07-20 12:27:35 +03:00
|
|
|
echo $storeDir$(echo $storePath | sed "s^${NIX_STORE_DIR:-/nix/store}^^")
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
initLowerStore () {
|
|
|
|
# Init lower store with some stuff
|
|
|
|
nix-store --store "$storeA" --add ../dummy
|
|
|
|
|
|
|
|
# Build something in lower store
|
2024-02-29 17:06:53 +02:00
|
|
|
drvPath=$(nix-instantiate --store $storeA ../hermetic.nix --arg withFinalRefs true --arg busybox "$busybox" --arg seed 1)
|
2023-12-11 20:45:46 +02:00
|
|
|
pathInLowerStore=$(nix-store --store "$storeA" --realise $drvPath)
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
2023-05-16 06:00:18 +03:00
|
|
|
|
|
|
|
execUnshare () {
|
2023-07-19 15:25:37 +03:00
|
|
|
exec unshare --mount --map-root-user "$SHELL" "$@"
|
2023-05-16 06:00:18 +03:00
|
|
|
}
|
2023-07-19 17:09:58 +03:00
|
|
|
|
|
|
|
addTextToStore() {
|
|
|
|
storeDir=$1; shift
|
|
|
|
filename=$1; shift
|
|
|
|
content=$1; shift
|
|
|
|
filePath="$TEST_HOME/$filename"
|
|
|
|
echo "$content" > "$filePath"
|
|
|
|
nix-store --store "$storeDir" --add "$filePath"
|
|
|
|
}
|