|
203 | 203 | assert info["revision"] == "${nixpkgs.rev}", f"revision mismatch: {info['revision']} != ${nixpkgs.rev}"
|
204 | 204 | cat_log()
|
205 | 205 |
|
| 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 | +
|
206 | 227 | # ... otherwise it should use the API
|
207 | 228 | out = client.succeed("nix flake metadata private-flake --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0 --no-trust-tarballs-from-git-forges")
|
208 | 229 | print(out)
|
|
211 | 232 | assert info["fingerprint"]
|
212 | 233 | cat_log()
|
213 | 234 |
|
| 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 | +
|
214 | 253 | # Fetching with the resolved URL should produce the same result.
|
215 | 254 | info2 = json.loads(client.succeed(f"nix flake metadata {info['url']} --json --access-tokens github.com=ghp_000000000000000000000000000000000000 --tarball-ttl 0"))
|
216 | 255 | print(info["fingerprint"], info2["fingerprint"])
|
|
0 commit comments