Subject: Likely cause found, excess library grafting

From: Richard Sent <[email-masked]>
Date: Mon, 27 May 2024 02:54:03 -0400

Hi Guix!

Once again I sunk more time into this issue when I should have been
sleeping. Here's what I found:

Building a grafted stumpwm directly creates one stumpwm:lib output.
Building it /indirectly/ as a dependency of, say, sbcl-stumpwm-cpu,
creates another, distinct stumpwm:lib output. This difference in
stumpwm:lib outputs is reflected in 50-stumpwm.conf being incoherent.

Packages that depend on say, A:lib graft their own copies of A:lib that
is distinct from grafting A:out and A:lib together. This behavior
confuses asdf-build-system and leads to breakage.

Here's a link to an issue discussing excess library grafts:
https://issues.guix.gnu.org/47115#23

The simplest way to resolve this I feel is to either:

1. Remove stumpwm:lib entirely and just have stumpwm:out
   1. Realistically is anyone out there using stumpwm:lib but NOT
   stumpwm:out? What would the point of that be?
2. Add stumpwm as an input to to any package that just uses stumpwm:lib.

Between the two, I strongly prefer 1.

Below is a bunch of debug output to show how I reached the conclusion
that I did.

--8<---------------cut here---------------start------------->8---
richard@gibraltar ~/code/cloned/guix [env]$ ./pre-inst-env guix build stumpwm --check
The following graft will be made:
/gnu/store/bsxspzrhfwsl4qp0n01mgcaqcp1934dj-stumpwm-22.11.drv
applying 9 grafts for stumpwm-22.11 ...
grafting '/gnu/store/j73w1n1sf3gqgx8qx3cx9csbrndddq0b-stumpwm-22.11-lib' -> '/gnu/store/r4sc5ylh2g30zgr10q35phd80cb3llqy-stumpwm-22.11-lib'...
grafting '/gnu/store/2rd3r0m8q11icwhhbwfl20ali3w5mwf4-stumpwm-22.11' -> '/gnu/store/azj1nchh8b9h9bssyzs15qbpd9p1zf7h-stumpwm-22.11'...
successfully built /gnu/store/bsxspzrhfwsl4qp0n01mgcaqcp1934dj-stumpwm-22.11.drv
successfully built /gnu/store/bsxspzrhfwsl4qp0n01mgcaqcp1934dj-stumpwm-22.11.drv
successfully built /gnu/store/bsxspzrhfwsl4qp0n01mgcaqcp1934dj-stumpwm-22.11.drv
/gnu/store/r4sc5ylh2g30zgr10q35phd80cb3llqy-stumpwm-22.11-lib
/gnu/store/azj1nchh8b9h9bssyzs15qbpd9p1zf7h-stumpwm-22.11

# ^ here 50-stumpwm.conf refers to r4sc5ylh..., as it should
# whereas
# below 50-stumpwm.conf refers to y8fd8yirq. Notice how stumpwm is
# grafted differently

richard@gibraltar ~/code/cloned/guix [env]$ ./pre-inst-env guix build sbcl-stumpwm-cpu
The following grafts will be made:
/gnu/store/w8fbnjz3a8rzigldazhqn75v1ncrwnmr-sbcl-stumpwm-cpu-0.0.1-5.4613a95.drv
/gnu/store/w5027r2xlf88pfafw9dsx38cya01la83-stumpwm-22.11.drv
applying 5 grafts for stumpwm-22.11 ...
grafting '/gnu/store/j73w1n1sf3gqgx8qx3cx9csbrndddq0b-stumpwm-22.11-lib' -> '/gnu/store/y8fd8yirq8n87sl7pv2wliwihrrbv820-stumpwm-22.11-lib'...
successfully built /gnu/store/w5027r2xlf88pfafw9dsx38cya01la83-stumpwm-22.11.drv
applying 2 grafts for sbcl-stumpwm-cpu-0.0.1-5.4613a95 ...
grafting '/gnu/store/r3l0dxxlcdh73092q9fmjj629klayxhq-sbcl-stumpwm-cpu-0.0.1-5.4613a95' -> '/gnu/store/nvp9y9qgpv4w22dqbjmdyc0l41gymims-sbcl-stumpwm-cpu-0.0.1-5.4613a95'...
successfully built /gnu/store/w8fbnjz3a8rzigldazhqn75v1ncrwnmr-sbcl-stumpwm-cpu-0.0.1-5.4613a95.drv
/gnu/store/nvp9y9qgpv4w22dqbjmdyc0l41gymims-sbcl-stumpwm-cpu-0.0.1-5.4613a95
--8<---------------cut here---------------end--------------->8---

Now that there are two distinct derivations for two distinct stumpwm:lib
outputs, we can look at the builders.

--8<---------------cut here---------------start------------->8---
;; guix build stumpwm, stumpwm graft builder
(begin (use-modules (guix build graft) (guix build utils) (ice-9 match))
       (define %outputs (list (cons "lib" ((@ (guile) getenv) "lib")) (cons "out" ((@ (guile) getenv) "out"))))
       (begin (setenv "GUIX_LOCPATH" "/gnu/store/visfdda934gvivwihwhlm63fdqhhcc8a-glibc-utf8-locales-2.35/lib/locale")
              (setlocale LC_ALL "en_US.utf8"))
       (let* ((old-outputs (quote (("lib" . "/gnu/store/j73w1n1sf3gqgx8qx3cx9csbrndddq0b-stumpwm-22.11-lib")
                                   ("out" . "/gnu/store/2rd3r0m8q11icwhhbwfl20ali3w5mwf4-stumpwm-22.11"))))
              (mapping (append (quote (("/gnu/store/hqxzgbbbnxl8l9q8bcsvzvmyw1mjws4r-zstd-1.5.2-lib" . "/gnu/store/x35wy730jwwmwwypvzy2nmqvcb3hc3ba-zstd-1.5.2-lib")
                                       ("/gnu/store/930nwsiysdvy2x5zv1sf6v7ym75z8ayk-gcc-11.3.0-lib" . "/gnu/store/6ncav55lbk5kqvwwflrzcr41hp5jbq0c-gcc-11.3.0-lib")
                                       ("/gnu/store/gsjczqir1wbz8p770zndrpw4rnppmxi3-glibc-2.35" . "/gnu/store/ln6hxqjvz6m9gdd9s97pivlqck7hzs99-glibc-2.35")
                                       ("/gnu/store/hbzlh3zjss4w80jscwfkivpyqc2sqbm3-sbcl-alexandria-1.4-0.009b7e5" . "/gnu/store/p8iagp15zzj5ivh3j8443jjpq6wmmzpw-sbcl-alexandria-1.4-0.009b7e5")
                                       ("/gnu/store/jd34ay8cyyl2dag62n94m15gg1b4s1sw-sbcl-2.4.0" . "/gnu/store/vj5jdgz6dajq25f6arjw976h6awwblgh-sbcl-2.4.0")
                                       ("/gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16" . "/gnu/store/v9p25q9l5nnaixkhpap5rnymmwbhf9rp-bash-minimal-5.1.16")
                                       ("/gnu/store/kf04j56xzh2pglwz3d8ybiz7wxwrs4df-sbcl-clx-0.7.5-1.3840045" . "/gnu/store/3sbrd8gj3ddq3cya2fygj0q788wp0kbr-sbcl-clx-0.7.5-1.3840045")
                                       ("/gnu/store/1xpjw51n2alaszrvwwm2f78k3nnnlrk1-sbcl-fiasco-0.0.1-2.bb47d2f" . "/gnu/store/z4l73b6b1a6ijfd5chpijjbi37mbq5wl-sbcl-fiasco-0.0.1-2.bb47d2f")
                                       ("/gnu/store/7xiwhrv7x4isj2860par69xas9lrk4av-sbcl-cl-ppcre-2.1.1" . "/gnu/store/h7r9c6wxm7d3yk803jyw86c0pr86rxcj-sbcl-cl-ppcre-2.1.1")))
                               (map (match-lambda ((name . file) (cons (assoc-ref old-outputs name) file))) %outputs)))) (graft old-outputs %outputs mapping)))

;; guix build sbcl-stumpwm-cpu, stumpwm-graft builder
(begin (use-modules (guix build graft) (guix build utils) (ice-9 match))
       (define %outputs (list (cons "lib" ((@ (guile) getenv) "lib"))))
       (begin (setenv "GUIX_LOCPATH" "/gnu/store/visfdda934gvivwihwhlm63fdqhhcc8a-glibc-utf8-locales-2.35/lib/locale")
              (setlocale LC_ALL "en_US.utf8"))
       (let* ((old-outputs (quote (("lib" . "/gnu/store/j73w1n1sf3gqgx8qx3cx9csbrndddq0b-stumpwm-22.11-lib"))))
              (mapping (append (quote (("/gnu/store/kf04j56xzh2pglwz3d8ybiz7wxwrs4df-sbcl-clx-0.7.5-1.3840045" . "/gnu/store/3sbrd8gj3ddq3cya2fygj0q788wp0kbr-sbcl-clx-0.7.5-1.3840045")
                                       ("/gnu/store/rib9g2ig1xf3kclyl076w28parmncg4k-bash-minimal-5.1.16" . "/gnu/store/v9p25q9l5nnaixkhpap5rnymmwbhf9rp-bash-minimal-5.1.16")
                                       ("/gnu/store/1xpjw51n2alaszrvwwm2f78k3nnnlrk1-sbcl-fiasco-0.0.1-2.bb47d2f" . "/gnu/store/z4l73b6b1a6ijfd5chpijjbi37mbq5wl-sbcl-fiasco-0.0.1-2.bb47d2f")
                                       ("/gnu/store/jd34ay8cyyl2dag62n94m15gg1b4s1sw-sbcl-2.4.0" . "/gnu/store/vj5jdgz6dajq25f6arjw976h6awwblgh-sbcl-2.4.0")
                                       ("/gnu/store/7xiwhrv7x4isj2860par69xas9lrk4av-sbcl-cl-ppcre-2.1.1" . "/gnu/store/h7r9c6wxm7d3yk803jyw86c0pr86rxcj-sbcl-cl-ppcre-2.1.1")))
                               (map (match-lambda ((name . file) (cons (assoc-ref old-outputs name) file))) %outputs)))) (graft old-outputs %outputs mapping)))--8<---------------cut here---------------end--------------->8---

Different builders? Different outputs. Different outputs? Different
50-stumpwm.conf files. Different 50-stumpwm.conf files? Sadness.

-- 
Take it easy,
Richard Sent
Making my computer weirder one commit at a time.