aboutsummaryrefslogtreecommitdiff
path: root/tests/functional/nix-copy-ssh-common.sh
blob: cc8314ff7fa52206e6e94acaa18e806543b2ef5d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
proto=$1
shift
(( $# == 0 ))

clearStore
clearCache

mkdir -p $TEST_ROOT/stores

# Create path to copy back and forth
outPath=$(nix-build --no-out-link dependencies.nix)

storeQueryParam="store=${NIX_STORE_DIR}"

realQueryParam () {
    echo "real=$1$NIX_STORE_DIR"
}

remoteRoot="$TEST_ROOT/stores/$proto"

clearRemoteStore () {
    chmod -R u+w "$remoteRoot" || true
    rm -rf "$remoteRoot"
}

clearRemoteStore

remoteStore="${proto}://localhost?${storeQueryParam}&remote-store=${remoteRoot}%3f${storeQueryParam}%26$(realQueryParam "$remoteRoot")"

# Copy to store

args=()
if [[ "$proto" == "ssh-ng" ]]; then
    # TODO investigate discrepancy
    args+=(--no-check-sigs)
fi

[ ! -f ${remoteRoot}${outPath}/foobar ]
nix copy "${args[@]}" --to "$remoteStore" $outPath
[ -f ${remoteRoot}${outPath}/foobar ]

# Copy back from store

clearStore

[ ! -f $outPath/foobar ]
nix copy --no-check-sigs --from "$remoteStore" $outPath
[ -f $outPath/foobar ]

# Check --substitute-on-destination, avoid corrupted store

clearRemoteStore

corruptedRoot=$TEST_ROOT/stores/corrupted
corruptedStore="${corruptedRoot}?${storeQueryParam}&$(realQueryParam "$corruptedRoot")"

# Copy it to the corrupted store
nix copy --no-check-sigs "$outPath" --to "$corruptedStore"

# Corrupt it in there
corruptPath="${corruptedRoot}${outPath}"
chmod +w "$corruptPath"
echo "not supposed to be here" > "$corruptPath/foobarbaz"
chmod -w "$corruptPath"

# Copy from the corrupted store with the regular store as a
# substituter. It must use the substituter not the source store in
# order to avoid errors.
NIX_CONFIG=$(echo -e "substituters = local\nrequire-sigs = false") \
    nix copy --no-check-sigs --from "$corruptedStore" --to "$remoteStore" --substitute-on-destination "$outPath"