diff --git a/src/libfetchers/github.cc b/src/libfetchers/github.cc index 1ca639419..8100afe4d 100644 --- a/src/libfetchers/github.cc +++ b/src/libfetchers/github.cc @@ -98,6 +98,10 @@ struct GitArchiveInputScheme : InputScheme if (ref) input.attrs.insert_or_assign("ref", *ref); if (host_url) input.attrs.insert_or_assign("host", *host_url); + auto narHash = url.query.find("narHash"); + if (narHash != url.query.end()) + input.attrs.insert_or_assign("narHash", narHash->second); + return input; } @@ -135,10 +139,13 @@ struct GitArchiveInputScheme : InputScheme assert(!(ref && rev)); if (ref) path += "/" + *ref; if (rev) path += "/" + rev->to_string(HashFormat::Base16, false); - return ParsedURL { + auto url = ParsedURL { .scheme = std::string { schemeName() }, .path = path, }; + if (auto narHash = input.getNarHash()) + url.query.insert_or_assign("narHash", narHash->to_string(HashFormat::SRI, true)); + return url; } Input applyOverrides( diff --git a/tests/nixos/github-flakes.nix b/tests/nixos/github-flakes.nix index a51689445..6f8a5b9d8 100644 --- a/tests/nixos/github-flakes.nix +++ b/tests/nixos/github-flakes.nix @@ -58,7 +58,7 @@ let mkdir -p $out/{commits,tarball} # Setup https://docs.github.com/en/rest/commits/commits#get-a-commit - echo '{"sha": "${private-flake-rev}"}' > $out/commits/HEAD + echo '{"sha": "${private-flake-rev}", "commit": {"tree": {"sha": "ffffffffffffffffffffffffffffffffffffffff"}}}' > $out/commits/HEAD # Setup tarball download via API dir=private-flake @@ -72,7 +72,7 @@ let mkdir -p $out/commits # Setup https://docs.github.com/en/rest/commits/commits#get-a-commit - echo '{"sha": "${nixpkgs.rev}"}' > $out/commits/HEAD + echo '{"sha": "${nixpkgs.rev}", "commit": {"tree": {"sha": "ffffffffffffffffffffffffffffffffffffffff"}}}' > $out/commits/HEAD ''; archive = pkgs.runCommand "nixpkgs-flake" {}