Subject: bug#72259: guix system: "guix graph -t referrers" could be more helpful in some cases

From: Simon Tournier <[email-masked]>
Date: Wed, 24 Jul 2024 01:15:15 +0200

Hi,

On Tue, 23 Jul 2024 at 13:24, "Zack Weinberg" via Bug reports for GNU Guix <[email-masked]> wrote:

>               I would have expected "guix graph -t referrers"
> to report that the package was a direct dependency of the
> operating-system derivation itself

Hum, I do not think that “guix graph” operated on the level of
’operating-system’.  That said, indeed something seems unexpected: you
get,

> # guix graph -t referrers lsof
> digraph "Guix referrers" {
>   "/gnu/store/7fkgda85xj4dr2d0r8lafyvnx5b9xwzp-lsof-4.94.0"
>     [label = "lsof-4.94.0", shape = box, fontname = sans];
> }

and the manual reads [1],

        ‘referrers’
             This is the graph of the “referrers” of a store item, as returned
             by ‘guix gc --referrers’ (*note Invoking guix gc::).

             This relies exclusively on local information from your store.  For
             instance, let us suppose that the current Inkscape is available in
             10 profiles on your machine; ‘guix graph -t referrers inkscape’
             will show a graph rooted at Inkscape and with those 10 profiles
             linked to it.

             It can help determine what is preventing a store item from being
             garbage collected.

--8<---------------cut here---------------start------------->8---
$ guix package -p /tmp/one-profile -I
lsof	4.94.0	out	/gnu/store/6nyp9cvksvyfww5d7j7rvm43jb46p521-lsof-4.94.0

$ guix gc --referrers /gnu/store/6nyp9cvksvyfww5d7j7rvm43jb46p521-lsof-4.94.0
/gnu/store/5wmvmlba841wvy681840cjwjcdifcjq2-profile

$ guix graph -t referrers /gnu/store/6nyp9cvksvyfww5d7j7rvm43jb46p521-lsof-4.94.0
digraph "Guix referrers" {
  "/gnu/store/6nyp9cvksvyfww5d7j7rvm43jb46p521-lsof-4.94.0" [label = "lsof-4.94.0", shape = box, fontname = sans];
  "/gnu/store/6nyp9cvksvyfww5d7j7rvm43jb46p521-lsof-4.94.0" -> "/gnu/store/5wmvmlba841wvy681840cjwjcdifcjq2-profile" [color = red];
  "/gnu/store/5wmvmlba841wvy681840cjwjcdifcjq2-profile" [label = "profile", shape = box, fontname = sans];
  "/gnu/store/5wmvmlba841wvy681840cjwjcdifcjq2-profile" -> "/gnu/store/5wmvmlba841wvy681840cjwjcdifcjq2-profile" [color = darkgoldenrod];

}
--8<---------------cut here---------------end--------------->8---

So far, so good!  However, indeed:

--8<---------------cut here---------------start------------->8---
$ guix graph -t referrers lsof
digraph "Guix referrers" {
  "/gnu/store/7fkgda85xj4dr2d0r8lafyvnx5b9xwzp-lsof-4.94.0" [label = "lsof-4.94.0", shape = box, fontname = sans];

}
--8<---------------cut here---------------end--------------->8---

And the reason is because grafts.

--8<---------------cut here---------------start------------->8---
$ guix build lsof --no-grafts
/gnu/store/7fkgda85xj4dr2d0r8lafyvnx5b9xwzp-lsof-4.94.0

$ guix package -p /tmp/another-profile -i lsof --no-grafts

$ guix graph -t referrers lsof
digraph "Guix referrers" {
  "/gnu/store/7fkgda85xj4dr2d0r8lafyvnx5b9xwzp-lsof-4.94.0" [label = "lsof-4.94.0", shape = box, fontname = sans];
  "/gnu/store/7fkgda85xj4dr2d0r8lafyvnx5b9xwzp-lsof-4.94.0" -> "/gnu/store/hjgbwa566fwzmwvrdal5ycxzlzz3al6x-profile" [color = blue];
  "/gnu/store/hjgbwa566fwzmwvrdal5ycxzlzz3al6x-profile" [label = "profile", shape = box, fontname = sans];
  "/gnu/store/hjgbwa566fwzmwvrdal5ycxzlzz3al6x-profile" -> "/gnu/store/hjgbwa566fwzmwvrdal5ycxzlzz3al6x-profile" [color = darkgoldenrod];

}
--8<---------------cut here---------------end--------------->8---

Well, the fix should be to have the grafted item by default pointing to
the non-grafted one and potentially referencing the others as describe
by the manual.

Cheers,
simon

1: https://guix.gnu.org/manual/devel/en/guix.html#Invoking-guix-graph