forked from NixOS/nix
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathexport.sh
More file actions
executable file
·80 lines (60 loc) · 2.96 KB
/
export.sh
File metadata and controls
executable file
·80 lines (60 loc) · 2.96 KB
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
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env bash
source common.sh
TODO_NixOS
clearStore
outPath=$(nix-build dependencies.nix --no-out-link)
drvPath=$(nix path-info --json "$outPath" | jq -r .\""$outPath"\".deriver)
nix-store --export "$outPath" > "$TEST_ROOT"/exp
expectStderr 1 nix nario export "$outPath" | grepQuiet "required argument.*missing"
nix nario export --format 1 "$outPath" > "$TEST_ROOT/exp2"
cmp "$TEST_ROOT/exp" "$TEST_ROOT/exp2"
# shellcheck disable=SC2046
nix-store --export $(nix-store -qR "$outPath") > "$TEST_ROOT"/exp_all
nix nario export --format 1 -r "$outPath" > "$TEST_ROOT"/exp_all2
cmp "$TEST_ROOT/exp_all" "$TEST_ROOT/exp_all2"
if nix-store --export "$outPath" >/dev/full ; then
echo "exporting to a bad file descriptor should fail"
exit 1
fi
clearStore
if nix-store --import < "$TEST_ROOT"/exp; then
echo "importing a non-closure should fail"
exit 1
fi
clearStore
nix-store --import < "$TEST_ROOT"/exp_all
# shellcheck disable=SC2046
nix-store --export $(nix-store -qR "$outPath") > "$TEST_ROOT"/exp_all2
clearStore
# Regression test: the derivers in exp_all2 are empty, which shouldn't
# cause a failure.
nix-store --import < "$TEST_ROOT"/exp_all2
# Test `nix nario import` on files created by `nix-store --export`.
clearStore
expectStderr 1 nix nario import < "$TEST_ROOT"/exp_all | grepQuiet "lacks a signature"
nix nario import --no-check-sigs < "$TEST_ROOT"/exp_all
nix path-info "$outPath"
# Test `nix nario list`.
nix nario list < "$TEST_ROOT"/exp_all
nix nario list < "$TEST_ROOT"/exp_all | grepQuiet ".*dependencies-input-0.*bytes"
nix nario list -lR < "$TEST_ROOT"/exp_all | grepQuiet "dr-xr-xr-x .*0 $outPath"
nix nario list -lR < "$TEST_ROOT"/exp_all | grepQuiet "lrwxrwxrwx .*0 $outPath/self -> $outPath"
nix nario list -lR < "$TEST_ROOT"/exp_all | grepQuiet -- "-r--r--r-- .*7 $outPath/foobar"
# Test format 2 (including signatures).
nix key generate-secret --key-name my-key > "$TEST_ROOT"/secret
public_key=$(nix key convert-secret-to-public < "$TEST_ROOT"/secret)
nix store sign --key-file "$TEST_ROOT/secret" -r "$outPath"
nix nario export --format 2 -r "$outPath" > "$TEST_ROOT"/exp_all
clearStore
expectStderr 1 nix nario import < "$TEST_ROOT"/exp_all | grepQuiet "lacks a signature"
nix nario import --trusted-public-keys "$public_key" < "$TEST_ROOT"/exp_all
[[ $(nix path-info --json "$outPath" | jq -r .[].signatures[]) =~ my-key: ]]
# Test json listing.
json=$(nix nario list --json -R < "$TEST_ROOT/exp_all")
[[ $(printf "%s" "$json" | jq -r ".paths.\"$outPath\".deriver") = "$drvPath" ]]
[[ $(printf "%s" "$json" | jq -r ".paths.\"$outPath\".contents.type") = directory ]]
[[ $(printf "%s" "$json" | jq -r ".paths.\"$outPath\".contents.entries.foobar.type") = regular ]]
[[ $(printf "%s" "$json" | jq ".paths.\"$outPath\".contents.entries.foobar.size") = 7 ]]
json=$(nix nario list --json < "$TEST_ROOT/exp_all")
[[ $(printf "%s" "$json" | jq -r ".paths.\"$outPath\".deriver") = "$drvPath" ]]
[[ $(printf "%s" "$json" | jq -r ".paths.\"$outPath\".contents.type") = null ]]