2023-05-15 19:34:57 +00:00
|
|
|
source ../common.sh
|
|
|
|
|
|
|
|
requireEnvironment () {
|
2023-05-16 03:00:18 +00: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 19:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
setupConfig () {
|
2023-07-18 09:49:44 +00:00
|
|
|
echo "require-drop-supplementary-groups = false" >> "$NIX_CONF_DIR"/nix.conf
|
2023-05-16 03:00:18 +00:00
|
|
|
echo "build-users-group = " >> "$NIX_CONF_DIR"/nix.conf
|
2023-05-15 19:34:57 +00:00
|
|
|
}
|
|
|
|
|
2023-07-20 09:27:11 +00:00
|
|
|
|
|
|
|
|
2023-05-15 19:34:57 +00:00
|
|
|
storeDirs () {
|
2023-07-20 09:27:11 +00: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"
|
|
|
|
storeB="local-overlay?root=$storeVolume/merged-store&lower-store=$storeA&upper-layer=$storeBTop"
|
2023-05-16 03:00:18 +00:00
|
|
|
# Creating testing directories
|
2023-07-20 09:27:11 +00:00
|
|
|
mkdir -p "$storeVolume"/{store-a/nix/store,store-b,merged-store/nix/store,workdir}
|
2023-05-15 19:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
# Mounting Overlay Store
|
|
|
|
mountOverlayfs () {
|
2023-07-20 09:27:11 +00:00
|
|
|
mergedStorePath="$storeVolume/merged-store/nix/store"
|
2023-05-15 19:34:57 +00:00
|
|
|
mount -t overlay overlay \
|
|
|
|
-o lowerdir="$storeA/nix/store" \
|
|
|
|
-o upperdir="$storeBTop" \
|
2023-07-20 09:27:11 +00:00
|
|
|
-o workdir="$storeVolume/workdir" \
|
2023-07-19 10:23:54 +00:00
|
|
|
"$mergedStorePath" \
|
2023-05-15 19:34:57 +00:00
|
|
|
|| skipTest "overlayfs is not supported"
|
|
|
|
|
|
|
|
cleanupOverlay () {
|
2023-07-20 09:27:11 +00:00
|
|
|
umount "$storeVolume/merged-store/nix/store"
|
|
|
|
rm -r $storeVolume/workdir
|
2023-05-15 19:34:57 +00:00
|
|
|
}
|
|
|
|
trap cleanupOverlay EXIT
|
|
|
|
}
|
|
|
|
|
2023-07-19 10:23:54 +00:00
|
|
|
remountOverlayfs () {
|
|
|
|
mount -o remount "$mergedStorePath"
|
|
|
|
}
|
|
|
|
|
2023-05-15 19:34:57 +00:00
|
|
|
toRealPath () {
|
|
|
|
storeDir=$1; shift
|
|
|
|
storePath=$1; shift
|
2023-07-20 09:27:35 +00:00
|
|
|
echo $storeDir$(echo $storePath | sed "s^${NIX_STORE_DIR:-/nix/store}^^")
|
2023-05-15 19:34:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
initLowerStore () {
|
|
|
|
# Init lower store with some stuff
|
|
|
|
nix-store --store "$storeA" --add ../dummy
|
|
|
|
|
|
|
|
# Build something in lower store
|
|
|
|
drvPath=$(nix-instantiate --store $storeA ../hermetic.nix --arg busybox "$busybox" --arg seed 1)
|
|
|
|
path=$(nix-store --store "$storeA" --realise $drvPath)
|
|
|
|
}
|
2023-05-16 03:00:18 +00:00
|
|
|
|
|
|
|
execUnshare () {
|
2023-07-19 12:25:37 +00:00
|
|
|
exec unshare --mount --map-root-user "$SHELL" "$@"
|
2023-05-16 03:00:18 +00:00
|
|
|
}
|
2023-07-19 14:09:58 +00:00
|
|
|
|
|
|
|
addTextToStore() {
|
|
|
|
storeDir=$1; shift
|
|
|
|
filename=$1; shift
|
|
|
|
content=$1; shift
|
|
|
|
filePath="$TEST_HOME/$filename"
|
|
|
|
echo "$content" > "$filePath"
|
|
|
|
nix-store --store "$storeDir" --add "$filePath"
|
|
|
|
}
|