2023-07-18 15:59:22 +03:00
|
|
|
#!/usr/bin/env bash
|
|
|
|
|
|
|
|
set -eu -o pipefail
|
|
|
|
|
|
|
|
set -x
|
|
|
|
|
|
|
|
source common.sh
|
|
|
|
|
|
|
|
# Avoid store dir being inside sandbox build-dir
|
|
|
|
unset NIX_STORE_DIR
|
|
|
|
unset NIX_STATE_DIR
|
|
|
|
|
2023-12-11 20:30:40 +02:00
|
|
|
setupStoreDirs
|
2023-07-18 15:59:22 +03:00
|
|
|
|
|
|
|
initLowerStore
|
|
|
|
|
|
|
|
mountOverlayfs
|
|
|
|
|
2023-07-19 13:23:54 +03:00
|
|
|
# Create a file to add to store
|
2023-07-20 12:27:11 +03:00
|
|
|
dupFilePath="$TEST_ROOT/dup-file"
|
2023-07-19 13:23:54 +03:00
|
|
|
echo Duplicate > "$dupFilePath"
|
|
|
|
|
|
|
|
# Add it to the overlay store (it will be written to the upper layer)
|
|
|
|
dupFileStorePath=$(nix-store --store "$storeB" --add "$dupFilePath")
|
|
|
|
|
|
|
|
# Now add it to the lower store so the store path is duplicated
|
|
|
|
nix-store --store "$storeA" --add "$dupFilePath"
|
|
|
|
|
|
|
|
# Ensure overlayfs and layers and synchronised
|
|
|
|
remountOverlayfs
|
|
|
|
|
|
|
|
dupFilename="${dupFileStorePath#/nix/store}"
|
|
|
|
lowerPath="$storeA/$dupFileStorePath"
|
|
|
|
upperPath="$storeBTop/$dupFilename"
|
2023-07-20 13:27:28 +03:00
|
|
|
overlayPath="$storeBRoot/nix/store/$dupFilename"
|
2023-07-19 13:23:54 +03:00
|
|
|
|
|
|
|
# Check store path exists in both layers and overlay
|
|
|
|
lowerInode=$(stat -c %i "$lowerPath")
|
|
|
|
upperInode=$(stat -c %i "$upperPath")
|
|
|
|
overlayInode=$(stat -c %i "$overlayPath")
|
|
|
|
[[ $upperInode == $overlayInode ]]
|
|
|
|
[[ $upperInode != $lowerInode ]]
|
|
|
|
|
|
|
|
# Run optimise to deduplicate store paths
|
2023-07-18 15:59:22 +03:00
|
|
|
nix-store --store "$storeB" --optimise
|
2023-07-19 13:23:54 +03:00
|
|
|
remountOverlayfs
|
|
|
|
|
2023-07-19 14:32:32 +03:00
|
|
|
# Check path only exists in lower store
|
2023-07-19 13:23:54 +03:00
|
|
|
stat "$lowerPath"
|
|
|
|
stat "$overlayPath"
|
|
|
|
expect 1 stat "$upperPath"
|