Skip to content

Commit 3264b8e

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

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/nixos/github-flakes.nix

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,12 @@ 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+
client.succeed(f'nix build --store /run/store --extra-experimental-features build-time-fetch-tree -L --expr \'derivation {{ name = "source"; builder = "builtin:fetch-tree"; system = "builtin"; __structuredAttrs = true; input = {{ type = "github"; owner = "NixOS"; repo = "nixpkgs"; }}; outputHashMode = "recursive"; outputHash = "{nar_hash}"; }}\' ')
211+
206212
# ... otherwise it should use the API
207213
out = client.succeed("nix flake metadata private-flake --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0 --no-trust-tarballs-from-git-forges")
208214
print(out)
@@ -211,6 +217,8 @@ in
211217
assert info["fingerprint"]
212218
cat_log()
213219
220+
client.succeed(f'nix build --store /run/store --extra-experimental-features build-time-fetch-tree --access-tokens github.com=ghp_000000000000000000000000000000000000 -L --expr \'derivation {{ name = "source"; builder = "builtin:fetch-tree"; system = "builtin"; __structuredAttrs = true; input = {{ type = "github"; owner = "fancy-enterprise"; repo = "private-flake"; }}; outputHashMode = "recursive"; outputHash = "{info['locked']['narHash']}"; }}\' ')
221+
214222
# Fetching with the resolved URL should produce the same result.
215223
info2 = json.loads(client.succeed(f"nix flake metadata {info['url']} --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0"))
216224
print(info["fingerprint"], info2["fingerprint"])

0 commit comments

Comments
 (0)