Skip to content

Commit 486c48a

Browse files
committed
Add tests for build-time fetching of GitHub flakes
1 parent 6f272c5 commit 486c48a

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

tests/nixos/github-flakes.nix

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,27 @@ in
203203
assert info["revision"] == "${nixpkgs.rev}", f"revision mismatch: {info['revision']} != ${nixpkgs.rev}"
204204
cat_log()
205205
206+
out = client.succeed("nix flake prefetch nixpkgs --json")
207+
nar_hash = json.loads(out)['hash']
208+
209+
# Test build-time fetching of public flakes.
210+
expr = f"""
211+
derivation {{
212+
name = "source";
213+
builder = "builtin:fetch-tree";
214+
system = "builtin";
215+
__structuredAttrs = true;
216+
input = {{
217+
type = "github";
218+
owner = "NixOS";
219+
repo = "nixpkgs";
220+
}};
221+
outputHashMode = "recursive";
222+
outputHash = "{nar_hash}";
223+
}}
224+
"""
225+
client.succeed(f"nix build --store /run/store --extra-experimental-features build-time-fetch-tree -L --expr '{expr}'")
226+
206227
# ... otherwise it should use the API
207228
out = client.succeed("nix flake metadata private-flake --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0 --no-trust-tarballs-from-git-forges")
208229
print(out)
@@ -211,6 +232,24 @@ in
211232
assert info["fingerprint"]
212233
cat_log()
213234
235+
# Test build-time fetching of private flakes.
236+
expr = f"""
237+
derivation {{
238+
name = "source";
239+
builder = "builtin:fetch-tree";
240+
system = "builtin";
241+
__structuredAttrs = true;
242+
input = {{
243+
type = "github";
244+
owner = "fancy-enterprise";
245+
repo = "private-flake";
246+
}};
247+
outputHashMode = "recursive";
248+
outputHash = "{info['locked']['narHash']}";
249+
}}
250+
"""
251+
client.succeed(f"nix build --store /run/store --extra-experimental-features build-time-fetch-tree --access-tokens github.com=ghp_000000000000000000000000000000000000 -L --expr '{expr}'")
252+
214253
# Fetching with the resolved URL should produce the same result.
215254
info2 = json.loads(client.succeed(f"nix flake metadata {info['url']} --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0"))
216255
print(info["fingerprint"], info2["fingerprint"])

0 commit comments

Comments
 (0)