Subject: [PATCH]: Use 'gtk-doc/stable' instead of 'gtk-doc' in native-inputs

From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 21:20:35 +0200

Hi Guix,

See: <https://lists.gnu.org/archive/html/guix-devel/2021-03/msg00538.html>

* Patch #1: Use 'gtk-doc/stable' instead of 'gtk-doc' in native-inputs

To test packages can still be built:

<start snip>
PACKAGES="thermald glimpse glib mate-desktop atril caja-extensions"
PACKAGES+=" mate-utils eom engrampa pluma mate-polkit"
PACKAGES+=" libgnt loudmouth denemo gsequencer libu2f-host libu2f-server"
PACKAGES+=" keybinder keybinder-3.0"

./pre-inst-env guix build $PACKAGES -M

# Output:
The following derivation will be built:
   /gnu/store/n84fwcigw3djfxv12iqv76bwp2gx9mnf-denemo-2.5.0.drv
The following files will be downloaded:
[...]

./pre-inst-env guix build denemo
[Bla bla.]
# Success!

<end snip>

To test no references to imagemagick or gtk-doc are retained:

./pre-inst-env guix graph --type=references $PACKAGES
# ^ search for imagemagick in output
# ^ TODO it should not be required to substitute $PACKAGES
#   first, as the 'references' information is in the narinfo.

* Patch #2: Export canonicalize-reference
* Patch #3: Add a '#:disallowed-references' argument to 'python-build'.

Used in later patches.

* Patch #4: Let 'python-sphinx' use 'imagemagick/stable'.

python-sphinx depends on imagemagick.  As (before this patch series),
many packages depend on 'python-sphinx' ...

<start snip>
guix refresh --list-dependent python-sphinx
Building the following 199 packages would ensure 427 dependent packages are rebuilt: [...]
<end snip>

... it may be worthwile to depend a /stable variant of python-sphinx,
and use it when sphinx is used only for generating the documentation.
However, defining a variant of python-sphinx is not required,
as python-sphinx does not retain its reference to imagemagick.

Thus, I simply replaced 'imagemagick' with 'imagemagick/stable' in the
inputs.  To make sure python-sphinx does not retain references to imagemagick/stable,
I added #:disallowed-references `(,imagemagick/stable) to #:arguments.

It is commented out in the patch to avoid rebuilds:

$ ./pre-inst-env guix build python-sphinx
> substitute: updating substitutes from 'https://ci.guix.gnu.org'... 100.0%
> 1.6 MB will be downloaded:
>    /gnu/store/sf2kdppaf8z2ri40rlp27l7ffkd8kvyf-python-sphinx-3.3.1
> substituting /gnu/store/sf2kdppaf8z2ri40rlp27l7ffkd8kvyf-python-sphinx-3.3.1...
> downloading from https://ci.guix.gnu.org/nar/lzip/sf2kdppaf8z2ri40rlp27l7ffkd8kvyf-python-sphinx-3.3.1 ...
>  python-sphinx-3.3.1  1.5MiB                                    121KiB/s 00:13 [##################] 100.0%
> [...]

When uncommented, 'python-sphinx' still builds.

* Patch #5 .. #10: I replaced imagemagick with imagemagick/stable in some packages

* After this patch series: how many packages would be rebuild if imagemagick
  is updated?

$ ./pre-inst-env guix refresh --list-dependent [email-masked]
> Building the following 47 packages would ensure 73 dependent packages are rebuilt: [..]

Also, I verified ./pre-inst-env guix build guix still succeeds.

Greetings,
Maxime.
From 70897e328a8c7314d9e2ad90ea3c5c55f690dc7c Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Sun, 28 Mar 2021 13:38:34 +0200
Subject: [PATCH 01/10] gnu: Use 'gtk-doc/stable' in native-inputs instead of
 'gtk-doc'.

Commit 9dea1618755891526f708aa335b4136c1302d16e only
replaced 'gtk-doc' with 'gtk-doc/stable' in the native-inputs
of some packages, but we may as well do this for all packages.

* gnu/packages/admin.scm (thermald)[native-inputs]:
  Replace 'gtk-doc' with 'gtk-doc/stable'.
  gnu/packages/gimp.scm (glimpse)[native-inputs]: Likewise.
  gnu/packages/glib.scm (glib-with-documentation): Likewise.
  gnu/packages/mate.scm (mate-desktop, atril, caja-extensions)
  (mate-utils, eom, engrampa, pluma, mate-polkit)[native-inputs]:
  Likewise.
  gnu/packages/messaging.scm
  (libgnt, loudmouth)[native-inputs]: Likewise.
  gnu/packages/music.scm
  (denemo, gsequencer)[native-inputs]: Likewise.
  gnu/packages/photo.scm (entangle)[native-inputs]: Likewise.
  gnu/packages/security-token.scm
  (libu2f-host,libu2f-server)[native-inputs]: Likewise.
  gnu/packages/wm.scm
  (keybinder, keybinder-3.0)[native-inputs]: Likewise.
---
 gnu/packages/admin.scm          |  3 ++-
 gnu/packages/gimp.scm           |  3 ++-
 gnu/packages/glib.scm           |  3 ++-
 gnu/packages/mate.scm           | 17 +++++++++--------
 gnu/packages/messaging.scm      |  5 +++--
 gnu/packages/music.scm          |  5 +++--
 gnu/packages/photo.scm          |  3 ++-
 gnu/packages/security-token.scm |  5 +++--
 gnu/packages/wm.scm             |  5 +++--
 9 files changed, 29 insertions(+), 20 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index df7973395d..3bafa71edc 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -39,6 +39,7 @@
 ;;; Copyright © 2021 Stefan Reichör <[email-masked]>
 ;;; Copyright © 2021 qblade <[email-masked]>
 ;;; Copyright © 2021 Hyunseok Kim <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -3580,7 +3581,7 @@ make it a perfect utility on modern distros.")
        ("autoconf-archive" ,autoconf-archive)
        ("automake" ,automake)
        ("glib" ,glib "bin")             ; for glib-genmarshal, etc.
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("pkg-config" ,pkg-config)))
     (inputs
      `(("dbus-glib" ,dbus-glib)
diff --git a/gnu/packages/gimp.scm b/gnu/packages/gimp.scm
index 5d005e0378..b81a679261 100644
--- a/gnu/packages/gimp.scm
+++ b/gnu/packages/gimp.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2018 Thorsten Wilms <[email-masked]>
 ;;; Copyright © 2020 Marius Bakke <[email-masked]>
 ;;; Copyright © 2020 Michael Rohleder <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -594,7 +595,7 @@ transferring the style of an image.")
     (native-inputs
      `(("autoconf" ,autoconf)
        ("automake" ,automake)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("intltool" ,intltool)
        ("libtool" ,libtool)
        ("libxslt" ,libxslt) ; for xsltproc
diff --git a/gnu/packages/glib.scm b/gnu/packages/glib.scm
index c04bd334e9..5f8186eabe 100644
--- a/gnu/packages/glib.scm
+++ b/gnu/packages/glib.scm
@@ -14,6 +14,7 @@
 ;;; Copyright © 2019, 2020 Marius Bakke <[email-masked]>
 ;;; Copyright © 2020 Nicolò Balzarotti <[email-masked]>
 ;;; Copyright © 2020 Arthur Margerit <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -426,7 +427,7 @@ dynamic loading, and an object system.")
     (properties (alist-delete 'hidden? (package-properties glib)))
     (outputs (cons "doc" (package-outputs glib))) ; 20 MiB of GTK-Doc reference
     (native-inputs
-     `(("gtk-doc" ,gtk-doc)             ; for the doc
+     `(("gtk-doc" ,gtk-doc/stable)           ; for the doc
        ("docbook-xml" ,docbook-xml)
        ("libxml2" ,libxml2)
        ,@(package-native-inputs glib)))
diff --git a/gnu/packages/mate.scm b/gnu/packages/mate.scm
index 44420147a3..5cee1bfe99 100644
--- a/gnu/packages/mate.scm
+++ b/gnu/packages/mate.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2019 Guy Fleury Iteriteka <[email-masked]>
 ;;; Copyright © 2020 Jonathan Brielmaier <[email-masked]>
 ;;; Copyright © 2020 Mathieu Othacehe <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -239,7 +240,7 @@ themes for both gtk+-2 and gtk+-3.")
        ("glib:bin" ,glib "bin")
        ("gobject-introspection" ,gobject-introspection)
        ("yelp-tools" ,yelp-tools)
-       ("gtk-doc" ,gtk-doc)))
+       ("gtk-doc" ,gtk-doc/stable)))
     (inputs
      `(("gtk+" ,gtk+)
        ("libxrandr" ,libxrandr)
@@ -761,7 +762,7 @@ infamous 'Wanda the Fish'.")
        ("yelp-tools" ,yelp-tools)
        ("glib:bin" ,glib "bin")
        ("gobject-introspection" ,gobject-introspection)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("xmllint" ,libxml2)
        ("zlib" ,zlib)))
     (inputs
@@ -896,7 +897,7 @@ icons on the MATE desktop.  It works on local and remote file systems.")
        ("gettext" ,gettext-minimal)
        ("glib:bin" ,glib "bin")
        ("gobject-introspection" ,gobject-introspection)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("libxml2" ,libxml2)
        ("pkg-config" ,pkg-config)))
     (inputs
@@ -1258,7 +1259,7 @@ can be used as backgrounds in the MATE Desktop environment.")
     (build-system glib-or-gtk-build-system)
     (native-inputs
      `(("gettext" ,gettext-minimal)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("intltool" ,intltool)
        ("libice" ,libice)
        ("libsm" ,libsm)
@@ -1310,7 +1311,7 @@ can be used as backgrounds in the MATE Desktop environment.")
     (build-system glib-or-gtk-build-system)
     (native-inputs
      `(("gettext" ,gettext-minimal)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("gobject-introspection" ,gobject-introspection)
        ("intltool" ,intltool)
        ("pkg-config" ,pkg-config)
@@ -1375,7 +1376,7 @@ can be used as backgrounds in the MATE Desktop environment.")
              #t)))))
     (native-inputs
      `(("gettext" ,gettext-minimal)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("intltool" ,intltool)
        ("pkg-config" ,pkg-config)
        ("yelp-tools" ,yelp-tools)))
@@ -1415,7 +1416,7 @@ can be used as backgrounds in the MATE Desktop environment.")
        #:tests? #f))
     (native-inputs
      `(("gettext" ,gettext-minimal)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("gobject-introspection" ,gobject-introspection)
        ("intltool" ,intltool)
        ("libtool" ,libtool)
@@ -1500,7 +1501,7 @@ MATE Desktop to monitor your system resources and usage.")
     (build-system glib-or-gtk-build-system)
     (native-inputs
      `(("gettext" ,gettext-minimal)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("intltool" ,intltool)
        ("libtool" ,libtool)
        ("pkg-config" ,pkg-config)))
diff --git a/gnu/packages/messaging.scm b/gnu/packages/messaging.scm
index 5c55e08fb2..a455eccef6 100644
--- a/gnu/packages/messaging.scm
+++ b/gnu/packages/messaging.scm
@@ -27,6 +27,7 @@
 ;;; Copyright © 2020, 2021 Michael Rohleder <[email-masked]>
 ;;; Copyright © 2020 Raghav Gururajan <[email-masked]>
 ;;; Copyright © 2020, 2021 Robert Karszniewicz <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -237,7 +238,7 @@ Its design goals are simplicity and stability.")
      `(("docbook-xml" ,docbook-xml-4.1.2)
        ("glib:bin" ,glib "bin")
        ("gobject-introspection" ,gobject-introspection)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("pkg-config" ,pkg-config)))
     (inputs
      `(("ncurses" ,ncurses)))
@@ -1886,7 +1887,7 @@ many bug fixes.")
      `(("pkg-config" ,pkg-config)
        ("check" ,check)
        ("glib" ,glib "bin")             ; gtester
-       ("gtk-doc" ,gtk-doc)))
+       ("gtk-doc" ,gtk-doc/stable)))
     (home-page "https://mcabber.com/")
     (description
      "Loudmouth is a lightweight and easy-to-use C library for programming
diff --git a/gnu/packages/music.scm b/gnu/packages/music.scm
index 98cd3583cc..ec603a7dd6 100644
--- a/gnu/packages/music.scm
+++ b/gnu/packages/music.scm
@@ -35,6 +35,7 @@
 ;;; Copyright © 2020 Ryan Prior <[email-masked]>
 ;;; Copyright © 2021 Leo Prikler <[email-masked]>
 ;;; Copyright © 2021 Vinicius Monego <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -638,7 +639,7 @@ many input formats and provides a customisable Vi-style user interface.")
     (native-inputs
      `(("diffutils" ,diffutils)
        ("glib:bin" ,glib "bin")         ; for gtester
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("intltool" ,intltool)
        ("libtool" ,libtool)
        ("pkg-config" ,pkg-config)))
@@ -4814,7 +4815,7 @@ studio.")
        ("cunit" ,cunit)
        ("gettext" ,gettext-minimal)
        ("gobject-introspection" ,gobject-introspection)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("libtool" ,libtool)
        ("libxslt" ,libxslt)
        ("pkg-config" ,pkg-config)
diff --git a/gnu/packages/photo.scm b/gnu/packages/photo.scm
index 4d679c7f02..11de91d103 100644
--- a/gnu/packages/photo.scm
+++ b/gnu/packages/photo.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2020 Sebastian Schott <[email-masked]>
 ;;; Copyright © 2020 Vincent Legoll <[email-masked]>
 ;;; Copyright © 2020. 2021 Vinicius Monego <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -665,7 +666,7 @@ such as Batch image processing.")
        ("gettext" ,gettext-minimal)
        ("glib:bin" ,glib "bin")
        ("gobject-introspection" ,gobject-introspection)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("perl" ,perl)
        ("pkg-config" ,pkg-config)
        ("xmllint" ,libxml2)))
diff --git a/gnu/packages/security-token.scm b/gnu/packages/security-token.scm
index accab82419..65c9f8e176 100644
--- a/gnu/packages/security-token.scm
+++ b/gnu/packages/security-token.scm
@@ -9,6 +9,7 @@
 ;;; Copyright © 2018, 2019 Chris Marusich <[email-masked]>
 ;;; Copyright © 2018 Arun Isaac <[email-masked]>
 ;;; Copyright © 2020 Raphaël Mélotte <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -483,7 +484,7 @@ PCSC API Python wrapper module.")
      `(("help2man" ,help2man)
        ("gengetopt" ,gengetopt)
        ("pkg-config" ,pkg-config)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("docbook-xml" ,docbook-xml-4.3)
        ("eudev" ,eudev)))
     (home-page "https://developers.yubico.com/libu2f-host/")
@@ -527,7 +528,7 @@ operations.")
        ("gengetopt" ,gengetopt)
        ("help2man" ,help2man)
        ("pkg-config" ,pkg-config)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("which" ,which)))
     (home-page "https://developers.yubico.com/libu2f-server/")
     ;; TRANSLATORS: The U2F protocol has a "server side" and a "host side".
diff --git a/gnu/packages/wm.scm b/gnu/packages/wm.scm
index 6105a98f14..8a4130b0b4 100644
--- a/gnu/packages/wm.scm
+++ b/gnu/packages/wm.scm
@@ -44,6 +44,7 @@
 ;;; Copyright © 2021 Zheng Junjie <[email-masked]>
 ;;; Copyright © 2021 Sharlatan Hellseher <[email-masked]>
 ;;; Copyright © 2021 qblade <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -1104,7 +1105,7 @@ all of them.  Currently supported window managers include:
        ("gtk+-2" ,gtk+-2)))
     (native-inputs
      `(("python2-pygtk" ,python2-pygtk)
-       ("gtk-doc" ,gtk-doc)
+       ("gtk-doc" ,gtk-doc/stable)
        ("pkg-config" ,pkg-config)))
     (synopsis "Library for registering global keyboard shortcuts")
     (description
@@ -1132,7 +1133,7 @@ Keybinder works with GTK-based applications using the X Window System.")
      `(("gtk+" ,gtk+)
        ("gobject-introspection" ,gobject-introspection)))
     (native-inputs
-     `(("gtk-doc" ,gtk-doc)
+     `(("gtk-doc" ,gtk-doc/stable)
        ("pkg-config" ,pkg-config)))
     (synopsis "Library for registering global keyboard shortcuts, Gtk3 version")
     (description
-- 
2.31.1

From 29f5ecf463ce17152af83e3107f3e6ce3b13f298 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 16:56:45 +0200
Subject: [PATCH 02/10] guix: build-system: gnu: Export canonicalize-reference.

This procedure will be used in 'qt-build-system' and
'python-build-system' in a later patch.

* guix/build-system/gnu.scm
  (gnu-build)[canonicalize-reference]: Extract to ...
  (canonicalize-reference): ... here, and document it.
  (gnu-cross-build)[canonicalize-reference]: Extract to ...
  (canonicalize-cross-reference): ... here, and document it.
---
 guix/build-system/gnu.scm | 77 +++++++++++++++++++++++++--------------
 1 file changed, 50 insertions(+), 27 deletions(-)

diff --git a/guix/build-system/gnu.scm b/guix/build-system/gnu.scm
index 6b481ad45c..cf334292be 100644
--- a/guix/build-system/gnu.scm
+++ b/guix/build-system/gnu.scm
@@ -1,5 +1,6 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2012, 2013, 2014, 2015, 2016, 2017, 2019, 2020 Ludovic Courtès <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -25,6 +26,7 @@
   #:use-module (guix build-system)
   #:use-module (guix packages)
   #:use-module (srfi srfi-1)
+  #:use-module (srfi srfi-26)
   #:use-module (ice-9 match)
   #:export (%gnu-build-system-modules
             gnu-build
@@ -36,7 +38,9 @@
             static-libgcc-package
             static-package
             dist-package
-            package-with-restricted-references))
+            package-with-restricted-references
+            canonicalize-reference
+            canonicalize-cross-reference))
 
 ;; Commentary:
 ;;
@@ -324,6 +328,43 @@ standard packages used as implicit inputs of the GNU build system."
   ;; Regexp matching license files.
   "^(COPYING.*|LICEN[CS]E.*|[Ll]icen[cs]e.*|Copy[Rr]ight(\\.(txt|md))?)$")
 
+(define (canonicalize-reference store system reference)
+  "Return as a string the store location where the ungrafted
+package referred to by REFERENCE and compiled for SYSTEM will
+end up.  REFERENCE is either a package object or a list of a
+package object and an output.  Alternatively, REFERENCE can
+simply be a string, in which case this string will be returned
+as-is."
+  (match reference
+    ((? package? p)
+     (derivation->output-path (package-derivation store p system
+                                                  #:graft? #f)))
+    (((? package? p) output)
+     (derivation->output-path (package-derivation store p system
+                                                  #:graft? #f)
+                              output))
+    ((? string? output)
+     output)))
+
+;; XXX why are grafts *not* disabled here, while they are
+;; in canonicalize-reference?
+(define (canonicalize-cross-reference store target system reference)
+  "Return as a string the store location where the package
+referred to by REFERENCE and cross-compiled on SYSTEM for
+TARGET will end up.  REFERENCE is either a package object or a
+list of a package object and an output.  Alternatively, REFERENCE
+can simply be a string, in which case this string will be returned."
+  (match reference
+    ((? package? p)
+     (derivation->output-path (package-cross-derivation store p
+                                                        target system)))
+    (((? package? p) output)
+     (derivation->output-path (package-cross-derivation store p
+                                                        target system)
+                              output))
+    ((? string? output)
+     output)))
+
 (define* (gnu-build store name input-drvs
                     #:key (guile #f)
                     (outputs '("out"))
@@ -370,17 +411,8 @@ returned derivations, or whether they should always build it locally.
 ALLOWED-REFERENCES can be either #f, or a list of packages that the outputs
 are allowed to refer to.  Likewise for DISALLOWED-REFERENCES, which lists
 packages that must not be referenced."
-  (define canonicalize-reference
-    (match-lambda
-     ((? package? p)
-      (derivation->output-path (package-derivation store p system
-                                                   #:graft? #f)))
-     (((? package? p) output)
-      (derivation->output-path (package-derivation store p system
-                                                   #:graft? #f)
-                               output))
-     ((? string? output)
-      output)))
+  (define specialized-canonicalize-reference
+    (cut canonicalize-reference store system <>))
 
   (define builder
     `(begin
@@ -433,11 +465,11 @@ packages that must not be referenced."
 
                                 #:allowed-references
                                 (and allowed-references
-                                     (map canonicalize-reference
+                                     (map specialized-canonicalize-reference
                                           allowed-references))
                                 #:disallowed-references
                                 (and disallowed-references
-                                     (map canonicalize-reference
+                                     (map specialized-canonicalize-reference
                                           disallowed-references))
                                 #:guile-for-build guile-for-build))
 
@@ -510,17 +542,8 @@ is one of `host' or `target'."
   "Cross-build NAME for TARGET, where TARGET is a GNU triplet.  INPUTS are
 cross-built inputs, and NATIVE-INPUTS are inputs that run on the build
 platform."
-  (define canonicalize-reference
-    (match-lambda
-     ((? package? p)
-      (derivation->output-path (package-cross-derivation store p
-                                                         target system)))
-     (((? package? p) output)
-      (derivation->output-path (package-cross-derivation store p
-                                                         target system)
-                               output))
-     ((? string? output)
-      output)))
+  (define specialized-canonicalize-reference
+    (cut canonicalize-cross-reference store target system <>))
 
   (define builder
     `(begin
@@ -599,11 +622,11 @@ platform."
 
                                 #:allowed-references
                                 (and allowed-references
-                                     (map canonicalize-reference
+                                     (map specialized-canonicalize-reference
                                           allowed-references))
                                 #:disallowed-references
                                 (and disallowed-references
-                                     (map canonicalize-reference
+                                     (map specialized-canonicalize-reference
                                           disallowed-references))
                                 #:guile-for-build guile-for-build))
 
-- 
2.31.1

From afef6d080ef5eec5538e8924d37ab9eb12bc7d50 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 12:52:56 +0200
Subject: [PATCH 03/10] build-system: python: Add #:disallowed-references.

* gnu/build-system/python.scm
  (python-build)[disallowed-references]: Add support for
  #:disallowed-references.
---
 guix/build-system/python.scm | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/python.scm b/guix/build-system/python.scm
index 80895162f8..41cf0999f6 100644
--- a/guix/build-system/python.scm
+++ b/guix/build-system/python.scm
@@ -173,9 +173,13 @@ pre-defined variants."
                        (guile #f)
                        (imported-modules %python-build-system-modules)
                        (modules '((guix build python-build-system)
-                                  (guix build utils))))
+                                  (guix build utils)))
+                       disallowed-references)
   "Build SOURCE using PYTHON, and with INPUTS.  This assumes that SOURCE
 provides a 'setup.py' file as its build system."
+  (define specialized-canonicalize-reference
+    (cut canonicalize-reference store system <>))
+
   (define builder
     `(begin
        (use-modules ,@modules)
@@ -212,7 +216,11 @@ provides a 'setup.py' file as its build system."
                                 #:system system
                                 #:modules imported-modules
                                 #:outputs outputs
-                                #:guile-for-build guile-for-build))
+                                #:guile-for-build guile-for-build
+                                #:disallowed-references
+                                (and disallowed-references
+                                     (map specialized-canonicalize-reference
+                                          disallowed-references))))
 
 (define python-build-system
   (build-system
-- 
2.31.1

From cb66411484eeb7b8423c31336275c5a70e4f57a8 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 12:58:42 +0200
Subject: [PATCH 04/10] gnu: sphinx: Use 'imagemagick/stable' variant.

As the store item does not retain a reference to imagemagick,
it should be safe to use the 'imagemagick/stable' variant.

* gnu/packages/sphinx.scm (python-sphinx):
  [arguments]<#:phases>: Suggest using #:disallowed-references
  to make sure no references to imagemagick are retained, but
  don't do that yet to avoid rebuilds.
  [native-inputs]: Use 'imagemagick/stable' instead of 'imagemagick'
  and explain why that's a safe thing to do.
---
 gnu/packages/sphinx.scm | 15 +++++++++++++--
 1 file changed, 13 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/sphinx.scm b/gnu/packages/sphinx.scm
index e85e4a0f7e..b3c5384f30 100644
--- a/gnu/packages/sphinx.scm
+++ b/gnu/packages/sphinx.scm
@@ -15,6 +15,7 @@
 ;;; Copyright © 2019 Brett Gilio <[email-masked]>
 ;;; Copyright © 2020 Giacomo Leidi <[email-masked]>
 ;;; Copyright © 2021 Eric Bavier <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -62,7 +63,13 @@
          "0023vc2i29pjxmvdqbz1wdbi7gbj56y1br1b2z8h8wa44li5k38y"))))
     (build-system python-build-system)
     (arguments
-     `(#:phases
+     `(;; Make sure it is safe to use 'imagemagick' instead
+       ;; of 'imagemagick/stable' (see the comment for the
+       ;; "imagemagick" input).
+       ;;
+       ;; TODO: uncomment this line on the next package update.
+       ;; #:disallowed-references (,imagemagick/stable)
+       #:phases
        (modify-phases %standard-phases
          (replace 'check
            (lambda _
@@ -92,7 +99,11 @@
         ,python-sphinxcontrib-serializinghtml)))
     (native-inputs
      `(("graphviz" ,graphviz)
-       ("imagemagick" ,imagemagick)                    ;for "convert"
+       ;; For "convert".  The store item does not retain a reference
+       ;; to imagemagick, so it should be safe to use 'imagemagick/stable'
+       ;; instead of 'imagemagick'.  This is enforced by the
+       ;; '#:disallowed-references' above.
+       ("imagemagick" ,imagemagick/stable)
        ("python-html5lib" ,python-html5lib)
        ("python-mock" ,python-mock)
        ("python-nose" ,python-nose)
-- 
2.31.1

From d372ac0ed52aa5f70a5da30dc7a8fa0efff2a821 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 13:47:01 +0200
Subject: [PATCH 05/10] gnu: wpa-supplicant-gui: Use 'imagemagick/stable'
 variant.

* gnu/packages/admin.scm (wpa-supplicant-gui):
  [native-inputs]: Use the 'imagemagick/stable' variant.
  [arguments]<#:disallowed-phases>: Prevent 'imagemagick/stable'
  from entering the closure.
---
 gnu/packages/admin.scm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index 3bafa71edc..b430528a39 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -1780,11 +1780,14 @@ command.")
               ,@(package-inputs wpa-supplicant)))
     (native-inputs
      ;; For icons.
-     `(("imagemagick" ,imagemagick)
+     `(("imagemagick" ,imagemagick/stable)
        ("inkscape" ,inkscape)
        ,@(package-native-inputs wpa-supplicant)))
     (arguments
-     `(#:phases (modify-phases %standard-phases
+     ;; Make sure the (rarely updated) package 'imagemagick/stable'
+     ;; does not end up in the closure.
+     `(#:disallowed-references (,imagemagick/stable)
+       #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'chdir
                     (lambda _
                       (chdir "wpa_supplicant/wpa_gui-qt4")
-- 
2.31.1

From ac0c5309968bb62110171893fd3ac8fc680b0de1 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 16:01:53 +0200
Subject: [PATCH 06/10] gnu: wpa-supplicant-gui: Don't return #t from phases.

* gnu/packages/admin.scm
  (wpa-supplicant-gui)[argument]<#:phases>: Don't return #t from
  phases, as returning #t isn't required anymore.
---
 gnu/packages/admin.scm | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/gnu/packages/admin.scm b/gnu/packages/admin.scm
index b430528a39..542651a355 100644
--- a/gnu/packages/admin.scm
+++ b/gnu/packages/admin.scm
@@ -1790,8 +1790,7 @@ command.")
        #:phases (modify-phases %standard-phases
                   (add-after 'unpack 'chdir
                     (lambda _
-                      (chdir "wpa_supplicant/wpa_gui-qt4")
-                      #t))
+                      (chdir "wpa_supplicant/wpa_gui-qt4")))
                   (delete 'configure)
                   (replace 'build
                     (lambda _
@@ -1812,8 +1811,7 @@ command.")
                             ,(map (lambda (label)
                                     (string-append (assoc-ref inputs label)
                                                    "/lib/qt5/plugins/"))
-                                  qt)))
-                        #t))))))
+                                  qt)))))))))
     (synopsis "Graphical user interface for WPA supplicant")))
 
 (define-public hostapd
-- 
2.31.1

From 3c656c4423a209d092734c3c1533c7aadefe37c2 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 17:14:08 +0200
Subject: [PATCH 07/10] guix: build-system: qt: Support
 #:disallowed-references.

* guix/build-system/qt.scm
  (qt-build): Support #:disallowed-references,
  using 'canonicalize-reference'.
  (qt-cross-build): Support #:disallowed-references,
  using 'canonicalize-cross-reference'.
---
 guix/build-system/qt.scm | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/qt.scm b/guix/build-system/qt.scm
index 118022ec45..ad9309af11 100644
--- a/guix/build-system/qt.scm
+++ b/guix/build-system/qt.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2013 Cyril Roelandt <[email-masked]>
 ;;; Copyright © 2017 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2019 Hartmut Goebel <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -29,6 +30,7 @@
   #:use-module (guix build-system gnu)
   #:use-module (guix packages)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
   #:export (%qt-build-system-modules
             qt-build
             qt-build-system))
@@ -127,9 +129,13 @@
                    (system (%current-system))
                    (imported-modules %qt-build-system-modules)
                    (modules '((guix build qt-build-system)
-                              (guix build utils))))
+                              (guix build utils)))
+                   disallowed-references)
   "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
 provides a 'CMakeLists.txt' file as its build system."
+  (define specialized-canonicalize-reference
+    (cut canonicalize-reference store system <>))
+
   (define builder
     `(begin
        (use-modules ,@modules)
@@ -175,6 +181,10 @@ provides a 'CMakeLists.txt' file as its build system."
                                 #:inputs inputs
                                 #:modules imported-modules
                                 #:outputs outputs
+                                #:disallowed-references
+                                (and disallowed-references
+                                     (map specialized-canonicalize-reference
+                                          disallowed-references))
                                 #:guile-for-build guile-for-build))
 
 
@@ -209,10 +219,14 @@ provides a 'CMakeLists.txt' file as its build system."
                          (build (nix-system->gnu-triplet system))
                          (imported-modules %qt-build-system-modules)
                          (modules '((guix build qt-build-system)
-                                    (guix build utils))))
+                                    (guix build utils)))
+                         disallowed-references)
   "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
 with INPUTS.  This assumes that SOURCE provides a 'CMakeLists.txt' file as its
 build system."
+  (define specialized-canonicalize-reference
+    (cut canonicalize-cross-reference store target system <>))
+
   (define builder
     `(begin
        (use-modules ,@modules)
@@ -284,6 +298,10 @@ build system."
                                 #:inputs (append native-drvs target-drvs)
                                 #:outputs outputs
                                 #:modules imported-modules
+                                #:disallowed-references
+                                (and disallowed-references
+                                     (map specialized-canonicalize-reference
+                                          disallowed-references))
                                 #:guile-for-build guile-for-build))
 
 (define qt-build-system
-- 
2.31.1

From 9bbac1da0cd30eac1c42ff42d0b8460852e03510 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 17:46:36 +0200
Subject: [PATCH 08/10] gnu: bandage: Do not yet use the 'imagemagick/stable'
 variant.
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Once <https://issues.guix.gnu.org/47475>
(‘Closure of bandage is way too large’) has been fixed,
the variant will probably be usable.

* gnu/packages/bioinformatics.scm (bandage):
  [arguments]<#:disallowed-references>: Once the issue
  has been fixed, prevent the imagemagick/stable package
  from ending up in the closure.
  [native-inputs]: Note that 'imagemagick/stable' cannot
  be used yet.
---
 gnu/packages/bioinformatics.scm | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/gnu/packages/bioinformatics.scm b/gnu/packages/bioinformatics.scm
index a81c873371..290946455a 100644
--- a/gnu/packages/bioinformatics.scm
+++ b/gnu/packages/bioinformatics.scm
@@ -12548,7 +12548,13 @@ Thus the per-base error rate is similar to the raw input reads.")
         (base32 "1bbsn5f5x8wlspg4pbibqz6m5vin8c19nl224f3z3km0pkc97rwv"))))
     (build-system qt-build-system)
     (arguments
-     `(#:phases
+     ;; TODO: Once <https://issues.guix.gnu.org/47475> is fixed,
+     ;; consider uncommenting the following:
+     ;;
+     ;; Prevent the (rarely updated) imagemagick/stable package
+     ;; from ending up in the closure.
+     `(;;#:disallowed-references (,imagemagick/stable)
+       #:phases
        (modify-phases %standard-phases
          (replace 'configure
            (lambda _
@@ -12572,6 +12578,8 @@ Thus the per-base error rate is similar to the raw input reads.")
      `(("qtbase" ,qtbase)
        ("qtsvg" ,qtsvg)))
     (native-inputs
+     ;; imagemagick/stable cannot be used here, as it will end up in the
+     ;; closure.  See <https://issues.guix.gnu.org/47475>.
      `(("imagemagick" ,imagemagick)))
     (home-page "https://rrwick.github.io/Bandage/")
     (synopsis
-- 
2.31.1

From 97fd9a8ab7e37602f5d857dd37fceeba399f43de Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 19:20:04 +0200
Subject: [PATCH 09/10] guix: build-system: cmake: Support
 #:disallowed-references.

* guix/build-system/cmake.scm
  (cmake-build): Add #:disallowed-references.
  (cmake-cross-build): Likewise.
---
 guix/build-system/cmake.scm | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/guix/build-system/cmake.scm b/guix/build-system/cmake.scm
index f590b6ea42..c15197508a 100644
--- a/guix/build-system/cmake.scm
+++ b/guix/build-system/cmake.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2013 Cyril Roelandt <[email-masked]>
 ;;; Copyright © 2017 Ricardo Wurmus <[email-masked]>
 ;;; Copyright © 2020 Efraim Flashner <[email-masked]>
+;;; Copyright © 2021 Maxime Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -28,6 +29,7 @@
   #:use-module (guix build-system gnu)
   #:use-module (guix packages)
   #:use-module (ice-9 match)
+  #:use-module (srfi srfi-26)
   #:export (%cmake-build-system-modules
             cmake-build
             cmake-build-system))
@@ -117,9 +119,13 @@
                       (substitutable? #t)
                       (imported-modules %cmake-build-system-modules)
                       (modules '((guix build cmake-build-system)
-                                 (guix build utils))))
+                                 (guix build utils)))
+                      disallowed-references)
   "Build SOURCE using CMAKE, and with INPUTS. This assumes that SOURCE
 provides a 'CMakeLists.txt' file as its build system."
+  (define specialized-canonicalize-reference
+    (cut canonicalize-reference store system <>))
+
   (define builder
     `(begin
        (use-modules ,@modules)
@@ -165,6 +171,10 @@ provides a 'CMakeLists.txt' file as its build system."
                                 #:modules imported-modules
                                 #:outputs outputs
                                 #:substitutable? substitutable?
+                                #:disallowed-references
+                                (and disallowed-references
+                                     (map specialized-canonicalize-reference
+                                          disallowed-references))
                                 #:guile-for-build guile-for-build))
 
 
@@ -200,10 +210,14 @@ provides a 'CMakeLists.txt' file as its build system."
                             (build (nix-system->gnu-triplet system))
                             (imported-modules %cmake-build-system-modules)
                             (modules '((guix build cmake-build-system)
-                                       (guix build utils))))
+                                       (guix build utils)))
+                            disallowed-references)
   "Cross-build NAME using CMAKE for TARGET, where TARGET is a GNU triplet and
 with INPUTS.  This assumes that SOURCE provides a 'CMakeLists.txt' file as its
 build system."
+  (define specialized-canonicalize-reference
+    (cut canonicalize-cross-reference store target system <>))
+
   (define builder
     `(begin
        (use-modules ,@modules)
@@ -276,6 +290,10 @@ build system."
                                 #:outputs outputs
                                 #:modules imported-modules
                                 #:substitutable? substitutable?
+                                #:disallowed-references
+                                (and disallowed-references
+                                     (map specialized-canonicalize-reference
+                                          disallowed-references))
                                 #:guile-for-build guile-for-build))
 
 (define cmake-build-system
-- 
2.31.1

From d7e7187f2387424d6b37e903efe4aed809733dd4 Mon Sep 17 00:00:00 2001
From: Maxime Devos <[email-masked]>
Date: Mon, 29 Mar 2021 20:14:35 +0200
Subject: [PATCH 10/10] gnu: inkscape-1.0: Do *not* yet use
 'imagemagick/stable'.

First, <https://issues.guix.gnu.org/47479> will have to be fixed.

* gnu/packages/inkscape (inkscape-1.0)[native-inputs]: Do not yet
  replace 'imagemagick' with 'imagemagick/stable', as 'imagemagick'
  ends up in the closure.
---
 gnu/packages/inkscape.scm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/gnu/packages/inkscape.scm b/gnu/packages/inkscape.scm
index 075f901b2d..3b774ceaa1 100644
--- a/gnu/packages/inkscape.scm
+++ b/gnu/packages/inkscape.scm
@@ -7,6 +7,7 @@
 ;;; Copyright © 2020 Maxim Cournoyer <[email-masked]>
 ;;; Copyright © 2020 Boris A. Dekshteyn <[email-masked]>
 ;;; Copyright © 2020 Ekaitz Zarraga <[email-masked]>
+;;; Copyright © 2021 Maxim Devos <[email-masked]>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -221,6 +222,11 @@ endif()~%~%"
        #:modules ((guix build cmake-build-system)
                   ((guix build glib-or-gtk-build-system) #:prefix glib-or-gtk:)
                   (guix build utils))
+       ;; TODO: uncomment this when <https://issues.guix.gnu.org/47479>
+       ;; has been fixed.
+       ;; Prevent the 'imagemagick/stable' package from ending
+       ;; up in the closure.
+       ;; #:disallowed-references (,imagemagick/stable)
        #:phases
        (modify-phases %standard-phases
          (add-after 'unpack 'patch-icon-cache-generator
@@ -291,6 +297,9 @@ endif()~%~%"
        ("python-numpy" ,python-numpy)
        ("python-lxml" ,python-lxml)))
     (native-inputs
+     ;; TODO: it would be nice to use 'imagemagick/stable' here,
+     ;; but that is not possible yet.  See
+     ;; <https://issues.guix.gnu.org/47479>.
      `(("imagemagick" ,imagemagick)     ;for tests
        ("intltool" ,intltool)
        ("glib" ,glib "bin")
-- 
2.31.1