Skip to content

nix copy --no-recursive: cannot add to the binary cache because the reference is not valid #12835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
2 tasks
andrewhamon opened this issue Mar 31, 2025 · 0 comments
Labels

Comments

@andrewhamon
Copy link
Contributor

andrewhamon commented Mar 31, 2025

Describe the bug

I am trying to copy incomplete closures to a binary cache.

In my specific case, the reason is because I want to copy to a temporary directory, then use a different tool (gcloud) to actually copy the files into the bucket. In order to save on unnecessary disk IO and nar serialization/compression overhead, I don't want to copy the recursive closure. Instead, i want to copy only the specific paths which I know are missing from the remote destination.

(getting off topic, but you might ask: why not just use S3 compatibility mode? the answer is, we do, but the way GCS HMAC tokens work really sucks if you care about security, so I'm trying to cut our dependency on writable HMAC tokens).

So the flow I was hoping for:

  • expand closure recursively
  • check which paths exist in the remote store
  • copy only the missing ones to a tmp dir nix copy --no-recursive --to file:///tmp/binary-cache/ some/path
  • sync tmp dir to gcs bucket with gcloud CLI

Another possible use case is a implementing a cachix-like mechanism to filter out paths already in public cache (tho I'm not a huge fan of that, feels like freeloading to me).

All of this is pretty easy to script with a little nix path-info and jq, except that copying incomplete closures fails.

Steps To Reproduce

nix copy --no-recursive --to file:///tmp/binary-cache/ /nix/store/qplid9wf2bfbl3i7w6xyh0769gz7v3a2-nix-2.18.2
error: cannot add '/nix/store/qplid9wf2bfbl3i7w6xyh0769gz7v3a2-nix-2.18.2' to the binary cache because the reference '/nix/store/1xqzb5zzj7ig47bpyybhv2l0hnib9ggk-nlohmann_json-3.11.3' is not valid

Expected behavior

If --no-recursive is specified and the target store is a binary cache, do not check that references are valid.

For other types of stores, allowing this might not make sense (e.g. a local store maintains a DB of valid paths, and I can't think of a circumstance where it is okay to violate the store integrity.)

Metadata

nix-env (Nix) 2.26.3

Additional context

Checklist


Add 👍 to issues you find important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant