2023-03-17 03:00:14 +00:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
2023-07-13 19:39:46 +00:00
|
|
|
# Avoid store dir being inside sandbox build-dir
|
|
|
|
unset NIX_STORE_DIR
|
|
|
|
unset NIX_STATE_DIR
|
|
|
|
|
2023-12-11 18:30:40 +00:00
|
|
|
setupStoreDirs
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-15 19:34:57 +00:00
|
|
|
initLowerStore
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-15 19:34:57 +00:00
|
|
|
mountOverlayfs
|
2023-05-08 18:47:39 +00:00
|
|
|
|
2023-05-08 20:00:47 +00:00
|
|
|
### Check status
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-08 20:00:47 +00:00
|
|
|
# Checking for path in lower layer
|
2023-12-11 18:48:42 +00:00
|
|
|
stat $(toRealPath "$storeA/nix/store" "$pathInLowerStore")
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-08 20:00:47 +00:00
|
|
|
# Checking for path in upper layer (should fail)
|
2023-12-11 18:48:42 +00:00
|
|
|
expect 1 stat $(toRealPath "$storeBTop" "$pathInLowerStore")
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-08 20:00:47 +00:00
|
|
|
# Checking for path in overlay store matching lower layer
|
2023-12-11 18:48:42 +00:00
|
|
|
diff $(toRealPath "$storeA/nix/store" "$pathInLowerStore") $(toRealPath "$storeBRoot/nix/store" "$pathInLowerStore")
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-09 21:20:58 +00:00
|
|
|
# Checking requisites query agreement
|
|
|
|
[[ \
|
|
|
|
$(nix-store --store $storeA --query --requisites $drvPath) \
|
|
|
|
== \
|
|
|
|
$(nix-store --store $storeB --query --requisites $drvPath) \
|
|
|
|
]]
|
|
|
|
|
|
|
|
# Checking referrers query agreement
|
|
|
|
busyboxStore=$(nix store --store $storeA add-path $busybox)
|
|
|
|
[[ \
|
|
|
|
$(nix-store --store $storeA --query --referrers $busyboxStore) \
|
|
|
|
== \
|
|
|
|
$(nix-store --store $storeB --query --referrers $busyboxStore) \
|
|
|
|
]]
|
|
|
|
|
2023-05-09 20:49:44 +00:00
|
|
|
# Checking derivers query agreement
|
|
|
|
[[ \
|
2023-12-11 18:48:42 +00:00
|
|
|
$(nix-store --store $storeA --query --deriver $pathInLowerStore) \
|
2023-05-09 20:49:44 +00:00
|
|
|
== \
|
2023-12-11 18:48:42 +00:00
|
|
|
$(nix-store --store $storeB --query --deriver $pathInLowerStore) \
|
2023-05-09 20:49:44 +00:00
|
|
|
]]
|
2023-03-17 03:00:14 +00:00
|
|
|
|
2023-05-09 20:49:44 +00:00
|
|
|
# Checking outputs query agreement
|
2023-05-09 20:42:28 +00:00
|
|
|
[[ \
|
|
|
|
$(nix-store --store $storeA --query --outputs $drvPath) \
|
|
|
|
== \
|
|
|
|
$(nix-store --store $storeB --query --outputs $drvPath) \
|
|
|
|
]]
|
|
|
|
|
2023-05-09 20:49:44 +00:00
|
|
|
# Verifying path in lower layer
|
2023-12-11 18:48:42 +00:00
|
|
|
nix-store --verify-path --store "$storeA" "$pathInLowerStore"
|
2023-05-09 20:49:44 +00:00
|
|
|
|
|
|
|
# Verifying path in merged-store
|
2023-12-11 18:48:42 +00:00
|
|
|
nix-store --verify-path --store "$storeB" "$pathInLowerStore"
|
2023-05-09 20:49:44 +00:00
|
|
|
|
2023-12-11 18:48:42 +00:00
|
|
|
hashPart=$(echo $pathInLowerStore | sed "s^${NIX_STORE_DIR:-/nix/store}/^^" | sed 's/-.*//')
|
2023-05-09 14:40:10 +00:00
|
|
|
|
|
|
|
# Lower store can find from hash part
|
2023-12-11 18:48:42 +00:00
|
|
|
[[ $(nix store --store $storeA path-from-hash-part $hashPart) == $pathInLowerStore ]]
|
2023-05-09 14:40:10 +00:00
|
|
|
|
|
|
|
# merged store can find from hash part
|
2023-12-11 18:48:42 +00:00
|
|
|
[[ $(nix store --store $storeB path-from-hash-part $hashPart) == $pathInLowerStore ]]
|