Skip to content
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

NAR hash mismatch on zip file flake inputs only in Nix 2.21.0 #10649

Closed
ailocam opened this issue May 6, 2024 · 2 comments · Fixed by #10675
Closed

NAR hash mismatch on zip file flake inputs only in Nix 2.21.0 #10649

ailocam opened this issue May 6, 2024 · 2 comments · Fixed by #10675
Assignees
Labels
bug regression Something doesn't work anymore

Comments

@ailocam
Copy link

ailocam commented May 6, 2024

There seems to have been a change in how Zip files are hashed in flakes between 2.20.6 and 2.21.0.

error: NAR hash mismatch in input 'https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1204193/chrome-mac.zip?narHash=sha256-UjmOD5zMSZyZbb05bq1zJTGF1tAuF7oYcyzo4tVu7GQ%3D', expected 'sha256-UjmOD5zMSZyZbb05bq1zJTGF1tAuF7oYcyzo4tVu7GQ=' but got 'sha256-jsM51UJ8/2kfo4FnUjfxAFcWdVRw9BN3NcAu3zprUEY='

Steps To Reproduce

Save these files in working directory
flake.nix

{
  description = "A very basic flake";
  inputs = {
    chromiumBinaryMacArm = { url = "https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1204193/chrome-mac.zip"; flake = false; };
  };
  outputs = inputs: {
    packages.x86_64-linux.default = builtins.toFile "test.txt" "${inputs.chromiumBinaryMacArm}";
  };
}

flake.lock

{
  "nodes": {
    "chromiumBinaryMacArm": {
      "flake": false,
      "locked": {
        "lastModified": 1700534482,
        "narHash": "sha256-UjmOD5zMSZyZbb05bq1zJTGF1tAuF7oYcyzo4tVu7GQ=",
        "type": "tarball",
        "url": "https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1204193/chrome-mac.zip"
      },
      "original": {
        "type": "tarball",
        "url": "https://storage.googleapis.com/chromium-browser-snapshots/Mac_Arm/1204193/chrome-mac.zip"
      }
    },
    "root": {
      "inputs": {
        "chromiumBinaryMacArm": "chromiumBinaryMacArm"
      }
    }
  },
  "root": "root",
  "version": 7
}

The command docker run -it -v $PWD:/app nixos/nix:2.21.0 bash -c "cd /app && nix build --extra-experimental-features 'flakes nix-command'" throws the error

Yet docker run -it -v $PWD:/app nixos/nix:2.20.6 bash -c "cd /app && nix build --extra-experimental-features 'flakes nix-command'" works perfectly.

Expected behavior

The hash in the lock file should be accepted by all versions of Nix, or at least be forwards compatible.

nix-env --version output

nix-env (Nix) 2.21.0

Additional context

Workaround: use the URL scheme file+https:// which causes Nix to not unpack the zip, then handle the unzip manually inside mkDerivation

Priorities

Add 👍 to issues you find important.

@ailocam ailocam added the bug label May 6, 2024
@edolstra edolstra self-assigned this May 9, 2024
@edolstra edolstra added the regression Something doesn't work anymore label May 9, 2024
edolstra added a commit to edolstra/nix that referenced this issue May 9, 2024
In streaming mode, libarchive doesn't handle symlinks in zip files
correctly. So write the entire file to disk so libarchive can access
it in random-access mode.

Fixes NixOS#10649. This was broken in cabee98.
@edolstra
Copy link
Member

edolstra commented May 9, 2024

This is fixed in #10675. Note: you may need to rm ~/.cache/nix/fetcher-cache-v*.

github-actions bot pushed a commit that referenced this issue May 15, 2024
In streaming mode, libarchive doesn't handle symlinks in zip files
correctly. So write the entire file to disk so libarchive can access
it in random-access mode.

Fixes #10649. This was broken in cabee98.

(cherry picked from commit 9951e14)
github-actions bot pushed a commit that referenced this issue May 15, 2024
In streaming mode, libarchive doesn't handle symlinks in zip files
correctly. So write the entire file to disk so libarchive can access
it in random-access mode.

Fixes #10649. This was broken in cabee98.

(cherry picked from commit 9951e14)
@nixos-discourse
Copy link

This issue has been mentioned on NixOS Discourse. There might be relevant details there:

https://discourse.nixos.org/t/2024-05-15-nix-team-meeting-minutes-146/45491/1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug regression Something doesn't work anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants