From 741ed30e7738656c93b0d0dcb2be45623c8d3c64 Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 29 Aug 2023 20:09:47 +0000 Subject: [PATCH 1/7] fetchDebianPatch: init --- pkgs/build-support/fetchdebianpatch/default.nix | 13 +++++++++++++ pkgs/top-level/all-packages.nix | 2 ++ 2 files changed, 15 insertions(+) create mode 100644 pkgs/build-support/fetchdebianpatch/default.nix diff --git a/pkgs/build-support/fetchdebianpatch/default.nix b/pkgs/build-support/fetchdebianpatch/default.nix new file mode 100644 index 000000000000..c1230484f82b --- /dev/null +++ b/pkgs/build-support/fetchdebianpatch/default.nix @@ -0,0 +1,13 @@ +{ lib, fetchpatch }: + +lib.makeOverridable ( + { pname, version, debianRevision ? null, name, hash, area ? "main" }: + let versionString = + if debianRevision == null then version else "${version}-${debianRevision}"; + in fetchpatch { + url = + "https://sources.debian.org/data/${area}/${builtins.substring 0 1 pname}/" + + "${pname}/${versionString}/debian/patches/${name}.patch"; + inherit hash; + } +) diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index f5575dccdfa4..e53b1fe1c65b 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1173,6 +1173,8 @@ with pkgs; tests = pkgs.tests.fetchzip; }; + fetchDebianPatch = callPackage ../build-support/fetchdebianpatch { }; + fetchCrate = callPackage ../build-support/rust/fetchcrate.nix { }; fetchFromGitea = callPackage ../build-support/fetchgitea { }; From 822608398927b2e5a849abc0d28d6a74afeefed2 Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 29 Aug 2023 20:10:38 +0000 Subject: [PATCH 2/7] pythonPackages.pysimplesoap: simplify using `fetchDebianPatch` This can serve as both a first example, and confirmation the fetcher works. --- .../python-modules/pysimplesoap/default.nix | 42 +++++++++---------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/pkgs/development/python-modules/pysimplesoap/default.nix b/pkgs/development/python-modules/pysimplesoap/default.nix index 11ffdaa7aa58..b9b0bf506b8b 100644 --- a/pkgs/development/python-modules/pysimplesoap/default.nix +++ b/pkgs/development/python-modules/pysimplesoap/default.nix @@ -1,5 +1,5 @@ { lib -, fetchpatch +, fetchDebianPatch , fetchPypi , buildPythonPackage , m2crypto @@ -20,28 +20,24 @@ buildPythonPackage rec { m2crypto ]; - patches = - let - debianRevision = "5"; # The Debian package revision we get patches from - fetchDebianPatch = { name, hash }: fetchpatch { - url = "https://salsa.debian.org/python-team/packages/pysimplesoap/-/raw/debian/${version}-${debianRevision}/debian/patches/${name}.patch"; - inherit hash; - }; - in map fetchDebianPatch [ - # Merged upstream: f5f96210e1483f81cb5c582a6619e3ec4b473027 - { name = "Add-quotes-to-SOAPAction-header-in-SoapClient"; - hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; } - # Merged upstream: ad03a21cafab982eed321553c4bfcda1755182eb - { name = "fix-httplib2-version-check"; - hash = "sha256-zUeF3v0N/eMyRVRH3tQLfuUfMKOD/B/aqEwFh/7HxH4="; } - { name = "reorder-type-check-to-avoid-a-TypeError"; - hash = "sha256-2p5Cqvh0SPfJ8B38wb/xq7jWGYgpI9pavA6qkMUb6hA="; } - # Merged upstream: 033e5899e131a2c1bdf7db5852f816f42aac9227 - { name = "Support-integer-values-in-maxOccurs-attribute"; - hash = "sha256-IZ0DP7io+ihcnB5547cR53FAdnpRLR6z4J5KsNrkfaI="; } - { name = "PR204"; - hash = "sha256-JlxeTnKDFxvEMFBthZsaYRbNOoBvLJhBnXCRoiL/nVw="; } - ] ++ [ ./stringIO.patch ]; + patches = map (args: fetchDebianPatch ({ + inherit pname version; + debianRevision = "5"; + } // args)) [ + # Merged upstream: f5f96210e1483f81cb5c582a6619e3ec4b473027 + { name = "Add-quotes-to-SOAPAction-header-in-SoapClient"; + hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; } + # Merged upstream: ad03a21cafab982eed321553c4bfcda1755182eb + { name = "fix-httplib2-version-check"; + hash = "sha256-zUeF3v0N/eMyRVRH3tQLfuUfMKOD/B/aqEwFh/7HxH4="; } + { name = "reorder-type-check-to-avoid-a-TypeError"; + hash = "sha256-2p5Cqvh0SPfJ8B38wb/xq7jWGYgpI9pavA6qkMUb6hA="; } + # Merged upstream: 033e5899e131a2c1bdf7db5852f816f42aac9227 + { name = "Support-integer-values-in-maxOccurs-attribute"; + hash = "sha256-IZ0DP7io+ihcnB5547cR53FAdnpRLR6z4J5KsNrkfaI="; } + { name = "PR204"; + hash = "sha256-JlxeTnKDFxvEMFBthZsaYRbNOoBvLJhBnXCRoiL/nVw="; } + ] ++ [ ./stringIO.patch ]; meta = with lib; { description = "Python simple and lightweight SOAP Library"; From 7122aea5695e2d7bec80f2985e954eabe3874bd5 Mon Sep 17 00:00:00 2001 From: nicoo Date: Tue, 29 Aug 2023 22:01:30 +0000 Subject: [PATCH 3/7] fetchers: document fetchDebianPatch --- doc/builders/fetchers.chapter.md | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index 4d4f3f427cd4..d434806aa9b2 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -82,6 +82,53 @@ Note that because the checksum is computed after applying these effects, using o Most other fetchers return a directory rather than a single file. + +## `fetchDebianPatch` {#fetchdebianpatch} + +A wrapper around `fetchpatch`, which takes: +- `name` and `hash`: the patch's filename without the `.patch` suffix, + and its hash after normalization by `fetchpatch` ; +- `pname`: the Debian source package's name ; +- `version`: the upstream version number ; +- `debianRevision`: the [Debian revision number] if applicable ; +- the `area` of the Debian archive: `main` (default), `contrib`, or `non-free`. + +Here is an example of `fetchDebianPatch` in action: + +```nix +{ lib +, fetchDebianPatch +, buildPythonPackage +}: + +buildPythonPackage rec { + pname = "pysimplesoap"; + version = "1.16.2"; + src = ...; + + patches = [ + (fetchDebianPatch { + inherit pname version; + debianRevision = "5"; + name = "Add-quotes-to-SOAPAction-header-in-SoapClient"; + hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; + }) + ]; + + ... +} +``` + +Patches are fetched from `sources.debian.org`, and so must come from a +package version that was uploaded to the Debian archive. Packages may +be removed from there once that specific version isn't in any suite +anymore (stable, testing, unstable, etc.), so maintainers should use +`copy-tarballs.pl` to archive the patch if it needs to be available in +the very long-term. + +[Debian revision number]: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version + + ## `fetchsvn` {#fetchsvn} Used with Subversion. Expects `url` to a Subversion directory, `rev`, and `hash`. From d4e265327f9b98ee6bddd08f422bc0372c484193 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 30 Aug 2023 07:48:42 +0000 Subject: [PATCH 4/7] fetchDebianPatch: Rename `patch` parameter, make `name` overrideable This allows using the fetcher with `invalidateFetcherByDrvHash` for testing. --- doc/builders/fetchers.chapter.md | 2 +- pkgs/build-support/fetchdebianpatch/default.nix | 7 ++++--- .../python-modules/pysimplesoap/default.nix | 10 +++++----- 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index d434806aa9b2..02c2cfe2c191 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -86,7 +86,7 @@ Most other fetchers return a directory rather than a single file. ## `fetchDebianPatch` {#fetchdebianpatch} A wrapper around `fetchpatch`, which takes: -- `name` and `hash`: the patch's filename without the `.patch` suffix, +- `patch` and `hash`: the patch's filename without the `.patch` suffix, and its hash after normalization by `fetchpatch` ; - `pname`: the Debian source package's name ; - `version`: the upstream version number ; diff --git a/pkgs/build-support/fetchdebianpatch/default.nix b/pkgs/build-support/fetchdebianpatch/default.nix index c1230484f82b..ba6aa63a732b 100644 --- a/pkgs/build-support/fetchdebianpatch/default.nix +++ b/pkgs/build-support/fetchdebianpatch/default.nix @@ -1,13 +1,14 @@ { lib, fetchpatch }: lib.makeOverridable ( - { pname, version, debianRevision ? null, name, hash, area ? "main" }: + { pname, version, debianRevision ? null, patch, hash, + area ? "main", name ? "${patch}.patch" }: let versionString = if debianRevision == null then version else "${version}-${debianRevision}"; in fetchpatch { + inherit name hash; url = "https://sources.debian.org/data/${area}/${builtins.substring 0 1 pname}/" - + "${pname}/${versionString}/debian/patches/${name}.patch"; - inherit hash; + + "${pname}/${versionString}/debian/patches/${patch}.patch"; } ) diff --git a/pkgs/development/python-modules/pysimplesoap/default.nix b/pkgs/development/python-modules/pysimplesoap/default.nix index b9b0bf506b8b..eecf54425380 100644 --- a/pkgs/development/python-modules/pysimplesoap/default.nix +++ b/pkgs/development/python-modules/pysimplesoap/default.nix @@ -25,17 +25,17 @@ buildPythonPackage rec { debianRevision = "5"; } // args)) [ # Merged upstream: f5f96210e1483f81cb5c582a6619e3ec4b473027 - { name = "Add-quotes-to-SOAPAction-header-in-SoapClient"; + { patch = "Add-quotes-to-SOAPAction-header-in-SoapClient"; hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; } # Merged upstream: ad03a21cafab982eed321553c4bfcda1755182eb - { name = "fix-httplib2-version-check"; + { patch = "fix-httplib2-version-check"; hash = "sha256-zUeF3v0N/eMyRVRH3tQLfuUfMKOD/B/aqEwFh/7HxH4="; } - { name = "reorder-type-check-to-avoid-a-TypeError"; + { patch = "reorder-type-check-to-avoid-a-TypeError"; hash = "sha256-2p5Cqvh0SPfJ8B38wb/xq7jWGYgpI9pavA6qkMUb6hA="; } # Merged upstream: 033e5899e131a2c1bdf7db5852f816f42aac9227 - { name = "Support-integer-values-in-maxOccurs-attribute"; + { patch = "Support-integer-values-in-maxOccurs-attribute"; hash = "sha256-IZ0DP7io+ihcnB5547cR53FAdnpRLR6z4J5KsNrkfaI="; } - { name = "PR204"; + { patch = "PR204"; hash = "sha256-JlxeTnKDFxvEMFBthZsaYRbNOoBvLJhBnXCRoiL/nVw="; } ] ++ [ ./stringIO.patch ]; From e4162c9e7bc7f2a36a10e1c5e1f5ef80953d1b4b Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 30 Aug 2023 07:50:44 +0000 Subject: [PATCH 5/7] fetchDebianPatch: add test --- pkgs/build-support/fetchdebianpatch/tests.nix | 11 +++++++++++ pkgs/test/default.nix | 1 + pkgs/top-level/all-packages.nix | 5 ++++- 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 pkgs/build-support/fetchdebianpatch/tests.nix diff --git a/pkgs/build-support/fetchdebianpatch/tests.nix b/pkgs/build-support/fetchdebianpatch/tests.nix new file mode 100644 index 000000000000..2146f66ce709 --- /dev/null +++ b/pkgs/build-support/fetchdebianpatch/tests.nix @@ -0,0 +1,11 @@ +{ testers, fetchDebianPatch, ... }: + +{ + simple = testers.invalidateFetcherByDrvHash fetchDebianPatch { + pname = "pysimplesoap"; + version = "1.16.2"; + debianRevision = "5"; + patch = "Add-quotes-to-SOAPAction-header-in-SoapClient"; + hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; + }; +} diff --git a/pkgs/test/default.nix b/pkgs/test/default.nix index b9d75c790da6..d6fd75359fc4 100644 --- a/pkgs/test/default.nix +++ b/pkgs/test/default.nix @@ -35,6 +35,7 @@ with pkgs; fetchurl = callPackages ../build-support/fetchurl/tests.nix { }; fetchpatch = callPackages ../build-support/fetchpatch/tests.nix { }; fetchpatch2 = callPackages ../build-support/fetchpatch/tests.nix { fetchpatch = fetchpatch2; }; + fetchDebianPatch = callPackages ../build-support/fetchdebianpatch/tests.nix { }; fetchzip = callPackages ../build-support/fetchzip/tests.nix { }; fetchgit = callPackages ../build-support/fetchgit/tests.nix { }; fetchFirefoxAddon = callPackages ../build-support/fetchfirefoxaddon/tests.nix { }; diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index e53b1fe1c65b..72c906ec0258 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -1173,7 +1173,10 @@ with pkgs; tests = pkgs.tests.fetchzip; }; - fetchDebianPatch = callPackage ../build-support/fetchdebianpatch { }; + fetchDebianPatch = callPackage ../build-support/fetchdebianpatch { } + // { + tests = pkgs.tests.fetchDebianPatch; + }; fetchCrate = callPackage ../build-support/rust/fetchcrate.nix { }; From d613fb52c927a84b79039d239c3484b0e1740f70 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 30 Aug 2023 08:06:10 +0000 Subject: [PATCH 6/7] doc/fetchers: fetchDebianPatch: don't imply how long a patch remains available --- doc/builders/fetchers.chapter.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/builders/fetchers.chapter.md b/doc/builders/fetchers.chapter.md index 02c2cfe2c191..ba105764904c 100644 --- a/doc/builders/fetchers.chapter.md +++ b/doc/builders/fetchers.chapter.md @@ -123,8 +123,8 @@ Patches are fetched from `sources.debian.org`, and so must come from a package version that was uploaded to the Debian archive. Packages may be removed from there once that specific version isn't in any suite anymore (stable, testing, unstable, etc.), so maintainers should use -`copy-tarballs.pl` to archive the patch if it needs to be available in -the very long-term. +`copy-tarballs.pl` to archive the patch if it needs to be available +longer-term. [Debian revision number]: https://www.debian.org/doc/debian-policy/ch-controlfields.html#version From 76aedfaaeeae743c94efa6962bfadf0ec6919b48 Mon Sep 17 00:00:00 2001 From: nicoo Date: Wed, 30 Aug 2023 08:26:52 +0000 Subject: [PATCH 7/7] fetchDebianPatch: Handle the case of `lib*` packages --- pkgs/build-support/fetchdebianpatch/default.nix | 11 ++++++++--- pkgs/build-support/fetchdebianpatch/tests.nix | 8 ++++++++ 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/pkgs/build-support/fetchdebianpatch/default.nix b/pkgs/build-support/fetchdebianpatch/default.nix index ba6aa63a732b..c058b416d381 100644 --- a/pkgs/build-support/fetchdebianpatch/default.nix +++ b/pkgs/build-support/fetchdebianpatch/default.nix @@ -3,12 +3,17 @@ lib.makeOverridable ( { pname, version, debianRevision ? null, patch, hash, area ? "main", name ? "${patch}.patch" }: - let versionString = - if debianRevision == null then version else "${version}-${debianRevision}"; + let + inherit (lib.strings) hasPrefix substring; + prefix = + substring 0 (if hasPrefix "lib" pname then 4 else 1) pname; + versionString = + if debianRevision == null then version + else "${version}-${debianRevision}"; in fetchpatch { inherit name hash; url = - "https://sources.debian.org/data/${area}/${builtins.substring 0 1 pname}/" + "https://sources.debian.org/data/${area}/${prefix}/" + "${pname}/${versionString}/debian/patches/${patch}.patch"; } ) diff --git a/pkgs/build-support/fetchdebianpatch/tests.nix b/pkgs/build-support/fetchdebianpatch/tests.nix index 2146f66ce709..58f3b395d1fc 100644 --- a/pkgs/build-support/fetchdebianpatch/tests.nix +++ b/pkgs/build-support/fetchdebianpatch/tests.nix @@ -8,4 +8,12 @@ patch = "Add-quotes-to-SOAPAction-header-in-SoapClient"; hash = "sha256-xA8Wnrpr31H8wy3zHSNfezFNjUJt1HbSXn3qUMzeKc0="; }; + + libPackage = testers.invalidateFetcherByDrvHash fetchDebianPatch { + pname = "libfile-pid-perl"; + version = "1.01"; + debianRevision = "2"; + patch = "missing-pidfile"; + hash = "sha256-VBsIYyCnjcZLYQ2Uq2MKPK3kF2wiMKvnq0m727DoavM="; + }; }