Skip to content

Commit

Permalink
feat(back): #1128 avoid hitting max arg limit
Browse files Browse the repository at this point in the history
- Make _nix_hashes receive bytes so it is compatible with stdin
- Make _nix_hashes process provided paths using xargs to avoid
hitting ARG_MAX limit
- Add findutils to runtime so xargs is available
  • Loading branch information
dsalaza4 committed Aug 10, 2023
1 parent 2244b2b commit d5f30e6
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions makes/cli/env/runtime/main.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
makeSearchPaths {
bin = [
__nixpkgs__.cachix
__nixpkgs__.findutils
__nixpkgs__.git
__nixpkgs__.gnutar
__nixpkgs__.gzip
Expand Down
10 changes: 5 additions & 5 deletions src/cli/main/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,14 +326,14 @@ def _nix_build(
]


def _nix_hashes(*paths: str) -> List[str]:
def _nix_hashes(paths: bytes) -> List[str]:
cmd = [
"xargs",
f"{__NIX_STABLE__}/bin/nix-store",
"--query",
"--hash",
*paths,
]
out, stdout, _ = _run_outputs(cmd, stderr=None)
out, stdout, _ = _run_outputs(cmd, stdin=paths, stderr=None)
if out != 0:
raise SystemExit(out)

Expand All @@ -360,7 +360,7 @@ def _nix_build_requisites(path: str) -> List[Tuple[str, str]]:

requisites: List[str] = stdout.decode().splitlines()

hashes: List[str] = _nix_hashes(*requisites)
hashes: List[str] = _nix_hashes(stdout)

return list(zip(requisites, hashes))

Expand Down Expand Up @@ -769,7 +769,7 @@ def write_provenance(
attestation["subject"] = [
{
"uri": realpath(out),
"hash": dict([_nix_hashes(out)[0].split(":")]),
"hash": dict([_nix_hashes(out.encode())[0].split(":")]),
}
]

Expand Down

0 comments on commit d5f30e6

Please sign in to comment.