2023-05-15 22:34:57 +03:00
|
|
|
source ../common.sh
|
|
|
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
setupConfig () {
|
2023-07-18 12:49:44 +03:00
|
|
|
echo "require-drop-supplementary-groups = false" >> "$NIX_CONF_DIR"/nix.conf
|
2023-05-16 06:00:18 +03:00
|
|
|
echo "build-users-group = " >> "$NIX_CONF_DIR"/nix.conf
|
2023-05-15 22:34:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
storeDirs () {
|
2023-05-16 06:00:18 +03:00
|
|
|
storeA="$TEST_ROOT/store-a"
|
|
|
|
storeBTop="$TEST_ROOT/store-b"
|
|
|
|
storeB="local-overlay?root=$TEST_ROOT/merged-store&lower-store=$storeA&upper-layer=$storeBTop"
|
|
|
|
# Creating testing directories
|
|
|
|
mkdir -p "$TEST_ROOT"/{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" \
|
|
|
|
-o workdir="$TEST_ROOT/workdir" \
|
|
|
|
"$TEST_ROOT/merged-store/nix/store" \
|
|
|
|
|| skipTest "overlayfs is not supported"
|
|
|
|
|
|
|
|
cleanupOverlay () {
|
|
|
|
umount "$TEST_ROOT/merged-store/nix/store"
|
|
|
|
rm -r $TEST_ROOT/workdir
|
|
|
|
}
|
|
|
|
trap cleanupOverlay EXIT
|
|
|
|
}
|
|
|
|
|
|
|
|
toRealPath () {
|
|
|
|
storeDir=$1; shift
|
|
|
|
storePath=$1; shift
|
|
|
|
echo $storeDir$(echo $storePath | sed "s^$NIX_STORE_DIR^^")
|
|
|
|
}
|
|
|
|
|
|
|
|
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 06:00:18 +03:00
|
|
|
|
|
|
|
execUnshare () {
|
|
|
|
exec unshare --mount --map-root-user "$@"
|
|
|
|
}
|
2023-07-18 12:49:44 +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"
|
|
|
|
}
|