1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-19 23:03:53 -04:00

First round of testing, with todos

This commit is contained in:
John Ericson 2023-05-08 16:00:47 -04:00
parent 9c9f5f0d12
commit d80fc2ac1b
3 changed files with 64 additions and 36 deletions

View file

@ -1,4 +1,4 @@
{ busybox }: { busybox, seed }:
with import ./config.nix; with import ./config.nix;
@ -21,19 +21,19 @@ let
input1 = mkDerivation { input1 = mkDerivation {
shell = busybox; shell = busybox;
name = "build-remote-input-1"; name = "hermetic-input-1";
buildCommand = "echo hi-input1; echo FOO > $out"; buildCommand = "echo hi-input1 seed=${toString seed}; echo FOO > $out";
}; };
input2 = mkDerivation { input2 = mkDerivation {
shell = busybox; shell = busybox;
name = "build-remote-input-2"; name = "hermetic-input-2";
buildCommand = "echo hi; echo BAR > $out"; buildCommand = "echo hi; echo BAR > $out";
}; };
input3 = mkDerivation { input3 = mkDerivation {
shell = busybox; shell = busybox;
name = "build-remote-input-3"; name = "hermetic-input-3";
buildCommand = '' buildCommand = ''
echo hi-input3 echo hi-input3
read x < ${input2} read x < ${input2}
@ -45,7 +45,7 @@ in
mkDerivation { mkDerivation {
shell = busybox; shell = busybox;
name = "build-remote"; name = "hermetic";
passthru = { inherit input1 input2 input3; }; passthru = { inherit input1 input2 input3; };
buildCommand = buildCommand =
'' ''

View file

@ -3,5 +3,8 @@ source common.sh
requireSandboxSupport requireSandboxSupport
[[ $busybox =~ busybox ]] || skipTest "no busybox" [[ $busybox =~ busybox ]] || skipTest "no busybox"
if [[ $(uname) != Linux ]]; then skipTest "Need Linux for overlayfs"; fi if [[ $(uname) != Linux ]]; then skipTest "Need Linux for overlayfs"; fi
needLocalStore "The test uses --store always so we would just be bypassing the daemon"
echo "drop-supplementary-groups = false" >> "$NIX_CONF_DIR"/nix.conf
exec unshare --mount --map-root-user overlay-local-store/inner.sh exec unshare --mount --map-root-user overlay-local-store/inner.sh

View file

@ -10,52 +10,77 @@ export NIX_CONFIG='build-users-group = '
# Creating testing directories # Creating testing directories
storeA="$TEST_ROOT/store_a" storeA="$TEST_ROOT/store-a"
storeB="local-overlay?root=$TEST_ROOT/store_b&lower-store=$TEST_ROOT/merged-store" storeBTop="$TEST_ROOT/store-b"
storeBTop="$TEST_ROOT/store_b" storeB="local-overlay?root=$TEST_ROOT/merged-store&lower-store=$TEST_ROOT/store-a"
mkdir -p "$TEST_ROOT"/{store_a,store_b,merged-store,workdir} mkdir -p "$TEST_ROOT"/{store-a,store-b,merged-store/nix/store,workdir}
# Mounting Overlay Store # Mounting Overlay Store
## Restore normal, because we are using these chroot stores # Init lower store with some stuff
#NIX_STORE_DIR=/nix/store nix-store --store "$storeA" --add dummy
nix-store --store "$TEST_ROOT/store_a" --add dummy # Build something in lower store
nix-store --store "$TEST_ROOT/store_b" --add dummy path=$(nix-build ./hermetic.nix --arg busybox "$busybox" --arg seed 1 --store "$storeA")
mount -t overlay overlay \ mount -t overlay overlay \
-o lowerdir="$TEST_ROOT/store_a/nix/store" \ -o lowerdir="$storeA/nix/store" \
-o upperdir="$TEST_ROOT/store_b/nix/store" \ -o upperdir="$storeBTop" \
-o workdir="$TEST_ROOT/workdir" \ -o workdir="$TEST_ROOT/workdir" \
"$TEST_ROOT/merged-store" || skipTest "overlayfs is not supported" "$TEST_ROOT/merged-store/nix/store" \
|| skipTest "overlayfs is not supported"
# Add in lower cleanupOverlay () {
NIX_REMOTE=$storeA source add.sh umount "$TEST_ROOT/merged-store/nix/store"
rm -r $TEST_ROOT/workdir
}
trap cleanupOverlay EXIT
# Add in layered toRealPath () {
NIX_REMOTE=$storeB source add.sh storeDir=$1; shift
storePath=$1; shift
echo $storeDir$(echo $storePath | sed "s^$NIX_STORE_DIR^^")
}
#busyboxExpr="\"\${$(dirname "$busybox")}/$(basename "$busybox")\"" ### Check status
path_a=$(nix-build ./hermetic.nix --arg busybox "$busybox" --store "$storeA")
# Checking for Path in store_a # Checking for path in lower layer
stat "$TEST_ROOT/store_a/$path_a" stat $(toRealPath "$storeA/nix/store" "$path")
# Checking for Path in store_b # Checking for path in upper layer (should fail)
expect 1 stat "$TEST_ROOT/store_b/$path_a" expect 1 stat $(toRealPath "$storeBTop" "$path")
# Checking for Path in merged-store # Checking for path in overlay store matching lower layer
ls "$TEST_ROOT/merged-store/$(echo "$path_a" | sed 's|/nix/store/||g')" diff $(toRealPath "$storeA/nix/store" "$path") $(toRealPath "$TEST_ROOT/merged-store/nix/store" "$path")
# Verifying path in lower layer
nix-store --verify-path --store "$storeA" "$path"
# Verifying path in store_a # Verifying path in merged-store
nix-store --verify-path --store "$storeA" "$path_a" # FIXME should succeed
expect 1 nix-store --verify-path --store "$storeB" "$path"
# Verifiying path in merged-store (Should fail) ### Do a redundant add
expect 1 nix-store --verify-path --store "$storeB" "$path_a"
# Verifying path in store_b (Should fail) path=$(nix-store --store "$storeB" --add dummy)
expect 1 nix-store --verify-path --store "$storeBTop" "$path_a"
path_b=$(nix-build ./hermetic.nix --arg busybox $busybox --store "$storeB") # lower store should have it from before
stat $(toRealPath "$storeA/nix/store" "$path")
# upper store should not have redundant copy
# 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"