Skip to content

fetchurl: fix overrideAttrs working as expect with hash#459487

Closed
SuperSandro2000 wants to merge 1 commit intoNixOS:masterfrom
SuperSandro2000:fetchurl-overrideAtts-hash
Closed

fetchurl: fix overrideAttrs working as expect with hash#459487
SuperSandro2000 wants to merge 1 commit intoNixOS:masterfrom
SuperSandro2000:fetchurl-overrideAtts-hash

Conversation

@SuperSandro2000
Copy link
Copy Markdown
Member

@SuperSandro2000 SuperSandro2000 commented Nov 7, 2025

The following example did not work before and does with this change:

(fetchurl {
  url = "...";
  hash = "sha256-..."
}).overrideAttrs (_: {
  hash = lib.fakeHash;
}

Things done

  • Built on platform:
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • Tested, as applicable:
  • Ran nixpkgs-review on this PR. See nixpkgs-review usage.
  • Tested basic functionality of all binary files, usually in ./result/bin/.
  • Nixpkgs Release Notes
    • Package update: when the change is major or breaking.
  • NixOS Release Notes
    • Module addition: when adding a new NixOS module.
    • Module update: when the change is significant.
  • Fits CONTRIBUTING.md, pkgs/README.md, maintainers/README.md and other READMEs.

Add a 👍 reaction to pull requests you find important.

The following example did not work before and does with this change:

(fetchurl {
  url = "...";
  hash = "sha256-..."
}).overrideAttrs (_: {
  hash = lib.fakeHash;
}
@SuperSandro2000 SuperSandro2000 force-pushed the fetchurl-overrideAtts-hash branch from 645209b to f722841 Compare November 7, 2025 15:16
@nixpkgs-ci nixpkgs-ci bot requested a review from philiptaron November 7, 2025 15:22
@nixpkgs-ci nixpkgs-ci bot added 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux. 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) labels Nov 7, 2025
@SuperSandro2000 SuperSandro2000 changed the base branch from staging to master November 7, 2025 15:56
@nixpkgs-ci nixpkgs-ci bot closed this Nov 7, 2025
@nixpkgs-ci nixpkgs-ci bot reopened this Nov 7, 2025
Copy link
Copy Markdown
Contributor

@ShamrockLee ShamrockLee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current changes would prevent overriding with hash when fetchur has been called with sha256.

How about making only hash overridiable?

The suggested changes are tested locally with ci/eval and remote builders, and the changed packages are only test cases.

@@ -190,7 +190,7 @@
if hash != "" then
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if hash != "" then
if finalAttrs.hash != "" then

{
outputHashAlgo = "sha512";
outputHash = sha512;
outputHash = finalAttrs.sha512;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputHash = finalAttrs.sha512;
outputHash = sha512;

{
outputHashAlgo = "sha256";
outputHash = sha256;
outputHash = finalAttrs.sha256;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputHash = finalAttrs.sha256;
outputHash = sha256;

{
outputHashAlgo = "sha1";
outputHash = sha1;
outputHash = finalAttrs.sha1;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
outputHash = finalAttrs.sha1;
outputHash = sha1;

Comment on lines +264 to +270
# Make overrideAttrs behave as expected
inherit
hash
sha1
sha256
sha512
;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This could be done from the excludeDrvArgNames side, as we don't need them to be present all the time.

Suggested change
# Make overrideAttrs behave as expected
inherit
hash
sha1
sha256
sha512
;

Comment on lines 66 to 70
# Hash attributes will be map to the corresponding outputHash*
"hash"
"sha1"
"sha256"
"sha512"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pass hash when specified.

Suggested change
# Hash attributes will be map to the corresponding outputHash*
"sha1"
"sha256"
"sha512"

@SuperSandro2000
Copy link
Copy Markdown
Member Author

Closing in favor of the other PR.

@SuperSandro2000 SuperSandro2000 deleted the fetchurl-overrideAtts-hash branch November 26, 2025 17:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

6.topic: fetch Fetchers (e.g. fetchgit, fetchsvn, ...) 10.rebuild-darwin: 11-100 This PR causes between 11 and 100 packages to rebuild on Darwin. 10.rebuild-linux: 11-100 This PR causes between 11 and 100 packages to rebuild on Linux.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants