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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
|
{
lib,
runCommand,
testers,
fetchgit,
nix-prefetch-git,
jq,
cacert,
nix,
closureInfo,
...
}:
{
simple = testers.invalidateFetcherByDrvHash fetchgit {
name = "simple-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
};
collect-rev = testers.invalidateFetcherByDrvHash fetchgit {
name = "collect-rev-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
hash = "sha256-AUTX1K7J5+fojvKYJacXYVV5kio3hrWYz5MCekO6h68=";
postCheckout = ''
git -C "$out" rev-parse HEAD | tee "$out/revision.txt"
'';
};
simple-tag = testers.invalidateFetcherByDrvHash fetchgit {
name = "simple-tag-nix-source";
url = "https://github.com/NixOS/nix";
tag = "2.3.15";
hash = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
};
describe-tag = testers.invalidateFetcherByDrvHash fetchgit {
name = "describe-tag-nix-source";
url = "https://github.com/NixOS/nix";
tag = "2.3.15";
hash = "sha256-y7l+46lVP2pzJwGON5qEV0EoxWofRoWAym5q9VXvpc8=";
postCheckout = ''
{ git -C "$out" describe || echo "git describe failed"; } | tee "$out"/describe-output.txt
'';
};
sparseCheckout = testers.invalidateFetcherByDrvHash fetchgit {
name = "sparse-checkout-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sparseCheckout = [
"src"
"tests"
];
sha256 = "sha256-g1PHGTWgAcd/+sXHo1o6AjVWCvC6HiocOfMbMh873LQ=";
};
sparseCheckoutNonConeMode = testers.invalidateFetcherByDrvHash fetchgit {
name = "sparse-checkout-non-cone-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sparseCheckout = [
"src"
"tests"
];
nonConeMode = true;
sha256 = "sha256-FknO6C/PSnMPfhUqObD4vsW4PhkwdmPa9blNzcNvJQ4=";
};
leave-git = testers.invalidateFetcherByDrvHash fetchgit {
name = "leave-git-nix-source";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sha256 = "sha256-VmQ38+lr+rNPaTnjjV41uC2XSN4fkfZAfytE2uKyLfo=";
leaveDotGit = true;
};
submodule-simple = testers.invalidateFetcherByDrvHash fetchgit {
name = "submodule-simple-source";
url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule";
rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a";
sha256 = "sha256-rmP8PQT0wJBopdtr/hsB7Y/L1G+ZPdHC2r9LB05Qrj4=";
fetchSubmodules = true;
};
submodule-leave-git = testers.invalidateFetcherByDrvHash fetchgit {
name = "submodule-leave-git-source";
url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule";
rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a";
sha256 = "sha256-EC2PMEEtA7f5OFdsluHn7pi4QXhCZuFML8tib4pV7Ek=";
leaveDotGit = true;
fetchSubmodules = true;
};
submodule-deep = testers.invalidateFetcherByDrvHash fetchgit {
name = "submodule-deep-source";
url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule";
rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a";
sha256 = "sha256-3zWogs6EZBnzUfz6gBnigETTKGYl9KFKFgsy6Bl4DME=";
deepClone = true;
fetchSubmodules = true;
# deepClone implies leaveDotGit, so delete the .git directory after
# fetching to distinguish from the submodule-leave-git-deep test.
postFetch = "rm -r $out/.git";
};
submodule-revision-count = testers.invalidateFetcherByDrvHash fetchgit {
name = "submodule-revision-count-source";
url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule";
rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a";
hash = "sha256-ok1e6Pb0fII5TF8HXF8DXaRGSoq7kgRCoXqSEauh1wk=";
fetchSubmodules = true;
deepClone = true;
leaveDotGit = false;
postCheckout = ''
{ git -C "$out" rev-list --count HEAD || echo "git rev-list failed"; } | tee "$out/revision_count.txt"
{ git -C "$out/nix-test-repo-submodule" rev-list --count HEAD || echo "git rev-list failed"; } | tee "$out/nix-test-repo-submodule/revision_count.txt"
'';
};
submodule-leave-git-deep = testers.invalidateFetcherByDrvHash fetchgit {
name = "submodule-leave-git-deep-source";
url = "https://github.com/pineapplehunter/nix-test-repo-with-submodule";
rev = "26473335b84ead88ee0a3b649b1c7fa4a91cfd4a";
sha256 = "sha256-ieYn9I/0RgeSwQkSqwKaU3RgjKFlRqMg7zw0Nvu3azA=";
deepClone = true;
leaveDotGit = true;
fetchSubmodules = true;
};
dumb-http-signed-tag = testers.invalidateFetcherByDrvHash fetchgit {
name = "dumb-http-signed-tag-source";
url = "https://git.scottworley.com/pub/git/pinch";
rev = "v3.0.14";
sha256 = "sha256-bd0Lx75Gd1pcBJtwz5WGki7XoYSpqhinCT3a77wpY2c=";
};
fetchTags = testers.invalidateFetcherByDrvHash fetchgit {
name = "fetchgit-fetch-tags-test";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
fetchTags = true;
leaveDotGit = true;
sha256 = "sha256-y7l+46lVP2pzJwGON5qEV0EoxWofRoWAym5q9VXvpc8=";
postFetch = ''
cd $out && git describe --tags --always > describe-output.txt 2>&1 || echo "git describe failed" > describe-output.txt
# See https://github.com/NixOS/nixpkgs/issues/412967#issuecomment-2927452118
rm -rf .git
'';
};
rootDir = testers.invalidateFetcherByDrvHash fetchgit {
name = "fetchgit-with-rootdir";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
rootDir = "misc/systemd";
sha256 = "sha256-UhxHk4SrXYq7ZDMtXLig5SigpbITrVgkpFTmryuvpcM=";
};
# Make sure that if an expected hash is given and the corresponding store path exists already, no fetch is done
cached-prefetch-avoids-fetch =
let
name = "cached-prefetch-avoids-fetch";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
fetched = fetchgit {
inherit
name
url
rev
sha256
;
};
in
runCommand "cached-prefetch-avoids-fetch"
{
nativeBuildInputs = [
nix-prefetch-git
nix
];
}
''
export NIX_REMOTE=local?root=$(mktemp -d)
nix-store --load-db < ${closureInfo { rootPaths = fetched; }}/registration
nix-prefetch-git --name "${name}" "${url}" "${rev}" "${sha256}" > $out
'';
prefetch-git-no-add-path =
testers.invalidateFetcherByDrvHash
(
{
name,
url,
rev,
hash,
...
}:
runCommand name
{
buildInputs = [
nix-prefetch-git
nix
cacert
jq
];
outputHashMode = "recursive";
outputHashAlgo = null;
outputHash = hash;
inherit url rev;
}
''
store_root="$(mktemp -d)"
prefetch() { NIX_REMOTE="local?root=$store_root" nix-prefetch-git $@ "$url" --rev "$rev" | jq -r .path; }
path="$(prefetch --no-add-path)"
if test -e "$store_root/$path"; then
echo "$path exists in $NIX_REMOTE when it shouldn't" >&2
exit 1
fi
path_added="$(prefetch)"
if ! test -e "$store_root/$path"; then
echo "$path_added doesn't exist in NIX_REMOTE when it should" >&2
exit 1
fi
if test "$path" != "$path_added"; then
echo "Paths are different with and without --no-add-path: $path != $path_added" >&2
exit 1
fi
cp -r "$store_root/$path_added" "$out"
''
)
{
name = "nix-prefetch-git-no-add-path";
url = "https://github.com/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
hash = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
};
withGitConfig = testers.invalidateFetcherByDrvHash fetchgit {
name = "fetchgit-with-config";
url = "https://doesntexist.forsure/NixOS/nix";
rev = "9d9dbe6ed05854e03811c361a3380e09183f4f4a";
sha256 = "sha256-7DszvbCNTjpzGRmpIVAWXk20P0/XTrWZ79KSOGLrUWY=";
gitConfigFile = lib.toFile "gitconfig" (
lib.generators.toGitINI {
url."https://github.com".insteadOf = "https://doesntexist.forsure";
}
);
};
}
|