2023-03-17 05:00:14 +02:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
export NIX_CONFIG='build-users-group = '
|
|
|
|
|
|
|
|
# Creating testing directories
|
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
storeA="$TEST_ROOT/store-a"
|
|
|
|
storeBTop="$TEST_ROOT/store-b"
|
|
|
|
storeB="local-overlay?root=$TEST_ROOT/merged-store&lower-store=$TEST_ROOT/store-a"
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
mkdir -p "$TEST_ROOT"/{store-a,store-b,merged-store/nix/store,workdir}
|
2023-03-17 05:00:14 +02:00
|
|
|
|
|
|
|
# Mounting Overlay Store
|
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Init lower store with some stuff
|
|
|
|
nix-store --store "$storeA" --add dummy
|
2023-05-08 21:47:39 +03:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Build something in lower store
|
|
|
|
path=$(nix-build ./hermetic.nix --arg busybox "$busybox" --arg seed 1 --store "$storeA")
|
2023-03-17 05:00:14 +02:00
|
|
|
|
|
|
|
mount -t overlay overlay \
|
2023-05-08 23:00:47 +03:00
|
|
|
-o lowerdir="$storeA/nix/store" \
|
|
|
|
-o upperdir="$storeBTop" \
|
2023-03-17 05:00:14 +02:00
|
|
|
-o workdir="$TEST_ROOT/workdir" \
|
2023-05-08 23:00:47 +03:00
|
|
|
"$TEST_ROOT/merged-store/nix/store" \
|
|
|
|
|| skipTest "overlayfs is not supported"
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
cleanupOverlay () {
|
|
|
|
umount "$TEST_ROOT/merged-store/nix/store"
|
|
|
|
rm -r $TEST_ROOT/workdir
|
|
|
|
}
|
|
|
|
trap cleanupOverlay EXIT
|
2023-05-08 21:47:39 +03:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
toRealPath () {
|
|
|
|
storeDir=$1; shift
|
|
|
|
storePath=$1; shift
|
|
|
|
echo $storeDir$(echo $storePath | sed "s^$NIX_STORE_DIR^^")
|
|
|
|
}
|
2023-05-08 21:47:39 +03:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
### Check status
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Checking for path in lower layer
|
|
|
|
stat $(toRealPath "$storeA/nix/store" "$path")
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Checking for path in upper layer (should fail)
|
|
|
|
expect 1 stat $(toRealPath "$storeBTop" "$path")
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Checking for path in overlay store matching lower layer
|
|
|
|
diff $(toRealPath "$storeA/nix/store" "$path") $(toRealPath "$TEST_ROOT/merged-store/nix/store" "$path")
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Verifying path in lower layer
|
|
|
|
nix-store --verify-path --store "$storeA" "$path"
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# Verifying path in merged-store
|
2023-05-09 00:37:40 +03:00
|
|
|
nix-store --verify-path --store "$storeB" "$path"
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
### Do a redundant add
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:03:32 +03:00
|
|
|
# upper layer should not have it
|
|
|
|
expect 1 stat $(toRealPath "$storeBTop/nix/store" "$path")
|
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
path=$(nix-store --store "$storeB" --add dummy)
|
2023-03-17 05:00:14 +02:00
|
|
|
|
2023-05-08 23:00:47 +03:00
|
|
|
# lower store should have it from before
|
|
|
|
stat $(toRealPath "$storeA/nix/store" "$path")
|
|
|
|
|
2023-05-08 23:03:32 +03:00
|
|
|
# upper layer should still not have it (no redundant copy)
|
2023-05-08 23:00:47 +03:00
|
|
|
# FIXME should fail
|
|
|
|
stat $(toRealPath "$storeA/nix/store" "$path")
|
|
|
|
|
|
|
|
### Do a build in overlay store
|
|
|
|
|
|
|
|
path=$(nix-build ./hermetic.nix --arg busybox $busybox --arg seed 2 --store "$storeB")
|
|
|
|
|
|
|
|
# Checking for path in lower layer (should fail)
|
|
|
|
expect 1 stat $(toRealPath "$storeA/nix/store" "$path")
|
|
|
|
|
|
|
|
# Checking for path in upper layer
|
|
|
|
stat $(toRealPath "$storeBTop" "$path")
|
|
|
|
|
|
|
|
# Verifying path in overlay store
|
|
|
|
nix-store --verify-path --store "$storeB" "$path"
|