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

fetchurl: disallow specifying both sha256 and hash #182953

Merged
merged 6 commits into from
Aug 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkgs/applications/networking/powerdns-admin/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ let
src = oldAttrs.src.override {
inherit version;
hash = "sha256-yKhbKNN3zHc35G4tnytPRO48Dh3qxr9G3e/HGH0weXo=";
sha256 = "";
};

SETUPTOOLS_SCM_PRETEND_VERSION = version;
Expand Down
3 changes: 3 additions & 0 deletions pkgs/build-support/fetchurl/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ let
else throw "fetchurl requires either `url` or `urls` to be set";

hash_ =
# Many other combinations don't make sense, but this is the most common one:
if hash != "" && sha256 != "" then throw "multiple hashes passed to fetchurl" else
Comment on lines +120 to +121
Copy link
Member

@SuperSandro2000 SuperSandro2000 Jul 26, 2022

Choose a reason for hiding this comment

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

Suggested change
# Many other combinations don't make sense, but this is the most common one:
if hash != "" && sha256 != "" then throw "multiple hashes passed to fetchurl" else
if hash != "" && sha1 != "" && sha256 != "" && sha512 != "" then throw "multiple hashes passed to fetchurl" else

might as well. Also what about we drop sha1 like md5?

Copy link
Member

@mweinelt mweinelt Jul 26, 2022

Choose a reason for hiding this comment

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

That's not how you check for existance of more than one hash though. And the proposed solution is at least pareto optimal.

❯ rg "sha256 =" -l | wc -l
19006
❯ rg "sha512 =" -l | wc -l
155
❯ rg "sha1 =" -l | wc -l
55

Copy link
Member Author

@vcunat vcunat Jul 26, 2022

Choose a reason for hiding this comment

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

You suggest wrong conditions. (uh, comment race, GitHub didn't update the thread for me)

Copy link
Contributor

@viraptor viraptor Jul 26, 2022

Choose a reason for hiding this comment

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

That will only fail on all of them present, so it would have to be a hash & sha1 || hash & sha256 || hash & sha512 || sha1 & sha256.... or some kind of (count-non-empty-in [hash sha1 sha256 sha512]) > 1

Copy link
Member Author

Choose a reason for hiding this comment

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

Before outright dropping the support I'd go through some time when it just prints an annoying warning. And I haven't checked the current usage in nixpkgs and tools. Anyway, that's way bigger than this PR and there's an issue already: #77238


if hash != "" then { outputHashAlgo = null; outputHash = hash; }
else if md5 != "" then throw "fetchurl does not support md5 anymore, please use sha256 or sha512"
else if (outputHash != "" && outputHashAlgo != "") then { inherit outputHashAlgo outputHash; }
Expand Down
24 changes: 12 additions & 12 deletions pkgs/servers/home-assistant/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ let
(self: super: {
pytest-aiohttp = super.pytest-aiohttp.overridePythonAttrs (oldAttrs: rec {
version = "0.3.0";
src = oldAttrs.src.override {
src = self.fetchPypi {
inherit version;
pname = "pytest-aiohttp";
hash = "sha256-ySmFQzljeXc3WDhwO2L+9jUoWYvAqdRRY566lfSqpE8=";
};
propagatedBuildInputs = with python3.pkgs; [ aiohttp pytest ];
Expand Down Expand Up @@ -86,7 +87,16 @@ let
})

# Pinned due to API changes in 0.1.0
(mkOverride "poolsense" "0.0.8" "sha256-17MHrYRmqkH+1QLtgq2d6zaRtqvb9ju9dvPt9gB2xCc=")
(self: super: {
poolsense = super.poolsense.overridePythonAttrs (oldAttrs: rec {
version = "0.0.8";
src = super.fetchPypi {
pname = "poolsense";
inherit version;
hash = "sha256-17MHrYRmqkH+1QLtgq2d6zaRtqvb9ju9dvPt9gB2xCc=";
};
});
})

# Pinned due to API changes >0.3.5.3
(self: super: {
Expand Down Expand Up @@ -144,16 +154,6 @@ let
})
];

mkOverride = attrName: version: hash:
self: super: {
${attrName} = super.${attrName}.overridePythonAttrs (oldAttrs: {
inherit version;
src = oldAttrs.src.override {
inherit version hash;
};
});
};

python = python3.override {
# Put packageOverrides at the start so they are applied after defaultOverrides
packageOverrides = lib.foldr lib.composeExtensions (self: super: { }) ([ packageOverrides ] ++ defaultOverrides);
Expand Down
2 changes: 2 additions & 0 deletions pkgs/tools/admin/oci-cli/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ let
src = oldAttrs.src.override {
inherit version;
hash = "sha256-0rUlXHxjSbwb0eWeCM0SrLvWPOZJ8liHVXg6qU37axo=";
sha256 = "";
};
});

Expand All @@ -21,6 +22,7 @@ let
src = oldAttrs.src.override {
inherit version;
sha256 = "b85d0567b8666149a93172712e68920734333c0ce7e89b78b3e987f71e5ed4f9";
hash = "";
vcunat marked this conversation as resolved.
Show resolved Hide resolved
};
});

Expand Down
3 changes: 2 additions & 1 deletion pkgs/tools/audio/tts/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ let
# TypeError: mel() takes 0 positional arguments but 2 positional arguments (and 3 keyword-only arguments) were given
librosa = super.librosa.overridePythonAttrs (oldAttrs: rec {
version = "0.8.1";
src = oldAttrs.src.override {
src = super.fetchPypi {
pname = "librosa";
inherit version;
sha256 = "c53d05e768ae4a3e553ae21c2e5015293e5efbfd5c12d497f1104cb519cca6b3";
};
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15235,6 +15235,7 @@ with pkgs;
src = oldAttrs.src.override {
inherit version;
hash = "sha256-XzZuhRFZ2Pcs5o0yuMDt2lbuU3wB6faOyjgr0VEK9l0=";
sha256 = "";
};
meta.changelog = "https://github.com/ansible/ansible/blob/v${version}/changelogs/CHANGELOG-v${lib.versions.majorMinor version}.rst";
}));
Expand Down