Skip to content

ca-derivations can create malformed NAR serializations #8113

Open
@Kiskae

Description

Describe the bug

Currently the ca-derivations feature implements its hash rewriting as a context-free replace over the NAR serialization of the output, but if any filename in the nar archive includes the hash this can break the lexical order of entries in the nar archive.

Steps To Reproduce

The following derivation creates a package that is very sensitive to changes in entry order:

runCommand "break-ca" {} ''
  mkdir -p $out
  touch $out/$(basename $out)
  touch $out/$(basename $out | head -c 2)
  touch $out/$(basename $out | head -c 2)zzz
  ls -la $out
''

On my machine trying to make this content-addressed results in the following error:

nix store make-content-addressed /nix/store/kpjx0d09414zwc76xyg57b4kx64b7z9b-break-ca
error: ca hash mismatch importing path '/nix/store/kxfp1fqd8xq2iksqk2id6gfvmn867yxl-break-ca';
         specified: sha256:1n1lkhdaaxgf0f35a8if4smh9d8k8ylr4q19zwy9jlbljjqm47hc
         got:       sha256:1ah0w6nnkc8z0r8ph1klv3gd879n0n7f8dbn1s42hj7w0p96q3ns

Expected behavior

I expect this to be broken since the requirements of the NAR serialization conflict with the context-free hash rewriting. One way to solve this is to ignore filenames during hash rewriting, but that will complicate the rewriting process. I'm mostly creating this issue so the behavior can be documented.

nix-env --version output

nix-env --version
nix-env (Nix) 2.13.3

Priorities

Add 👍 to issues you find important.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugca-derivationsDerivations with content addressed outputs

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions