Subject: bug#58859: profile contents depends on package order

From: John Kehayias <[email-masked]>
Date: Sat, 29 Oct 2022 04:36:07 +0000

Hi Guix,

(I'm cc'ing the devel list for this bug report as I think some wider input and commentary would be worthwhile.)

While investigating a bug with the --emulate-fhs option (bug report forthcoming) I noticed that the profile contents can depend on the order of packages given as input to guix shell. The FHS bug is also due to argument order, but I think is clearly a bug and not expected behavior (wrong glibc included in the container). Though maybe we want to look around for other argument order problems or have some tests?

Actually, this is true for profiles more generally, as I just quickly tested the first example with "guix install" rather than just shell. My examples are all with shell, but I guess it comes down to the same thing. I think this is trickier with shell and the -D option, as we'll see in the second example.

First example, where we might expect something to happen, though personally I expected a profile collision error:

--8<---------------cut here---------------start------------->8---
❯ guix shell ffmpeg@4 ffmpeg@5

❯ ls -la $(which ffmpeg)
lrwxrwxrwx 1 root root 67 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/bin/ffmpeg -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/bin/ffmpeg*

❯ ls -la $GUIX_ENVIRONMENT/lib/libavdevice.so*
lrwxrwxrwx 1 root root 75 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/lib/libavdevice.so -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/lib/libavdevice.so*
lrwxrwxrwx 1 root root 78 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/lib/libavdevice.so.58 -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/lib/libavdevice.so.58*
lrwxrwxrwx 1 root root 85 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/lib/libavdevice.so.58.13.100 -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/lib/libavdevice.so.58.13.100*
lrwxrwxrwx 1 root root 78 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/lib/libavdevice.so.59 -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/lib/libavdevice.so.59*
lrwxrwxrwx 1 root root 84 Dec 31  1969 /gnu/store/ivfa3mjhqiqc91m5h27sr9gfyzwnv1d0-profile/lib/libavdevice.so.59.7.100 -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/lib/libavdevice.so.59.7.100*
--8<---------------cut here---------------end--------------->8---

Note that the last specified package, ffmpeg@5, takes precedence here for bin, and the lib directory contains a mixture (as there are some unique filenames as well).

To compare, we do the same thing with the order of ffmpeg versions switched. As we might guess, the profile was not cached; this is a different profile.

--8<---------------cut here---------------start------------->8---
❯ guix shell ffmpeg@5 ffmpeg@4
The following derivation will be built:
  /gnu/store/2273cnn0wpgid93na7wbhzijrz0r0hlx-profile.drv

building CA certificate bundle...
listing Emacs sub-directories...
building fonts directory...
generating GLib schema cache...
building directory of Info manuals...
building XDG desktop file cache...
building XDG MIME database...
building profile with 2 packages...

❯ ls -la $(which ffmpeg)
lrwxrwxrwx 1 root root 67 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/bin/ffmpeg -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/bin/ffmpeg*

❯ ls -la $GUIX_ENVIRONMENT/lib/libavdevice.so*
lrwxrwxrwx 1 root root 75 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/lib/libavdevice.so -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/lib/libavdevice.so*
lrwxrwxrwx 1 root root 78 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/lib/libavdevice.so.58 -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/lib/libavdevice.so.58*
lrwxrwxrwx 1 root root 85 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/lib/libavdevice.so.58.13.100 -> /gnu/store/hx4xf70yjgycx0asv1k1h33p7xms15m8-ffmpeg-4.4.2/lib/libavdevice.so.58.13.100*
lrwxrwxrwx 1 root root 78 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/lib/libavdevice.so.59 -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/lib/libavdevice.so.59*
lrwxrwxrwx 1 root root 84 Dec 31  1969 /gnu/store/c3r3n5fxjs5r4lbjvz1x6rdlgbi8bv8a-profile/lib/libavdevice.so.59.7.100 -> /gnu/store/51gal8hjxilk1f26f3m3ggdhg9rykz6s-ffmpeg-5.1.2/lib/libavdevice.so.59.7.100*
--8<---------------cut here---------------end--------------->8---

This confirms the ordering of inputs to guix shell matters.

As a rather contrived example we might expect the user is paying attention with this explicit package input conflict. However, this also happens when that is not clear from the package names without inspecting package definitions.

See this second example, where the sdl2 package given to guix shell does not match the sdl2-2.0 input of ffmpeg@4 (with the -D argument):

--8<---------------cut here---------------start------------->8---
❯ guix shell -D ffmpeg@4 sdl2

❯ ls $GUIX_ENVIRONMENT/lib/libSDL2* -la
lrwxrwxrwx 1 root root 76 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2-2.0.so.0 -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2-2.0.so.0*
lrwxrwxrwx 1 root root 81 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2-2.0.so.0.14.0 -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2-2.0.so.0.14.0*
lrwxrwxrwx 1 root root 83 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2-2.0.so.0.2400.0 -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2-2.0.so.0.2400.0*
lrwxrwxrwx 1 root root 69 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2.a -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2.a
lrwxrwxrwx 1 root root 70 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2.la -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2.la*
lrwxrwxrwx 1 root root 73 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2main.a -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2main.a
lrwxrwxrwx 1 root root 74 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2main.la -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2main.la*
lrwxrwxrwx 1 root root 70 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2.so -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2.so*
lrwxrwxrwx 1 root root 74 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2_test.a -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2_test.a
lrwxrwxrwx 1 root root 75 Dec 31  1969 /gnu/store/2hhpchr2xv01sbmjlngxhaq5znbvsckj-profile/lib/libSDL2_test.la -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2_test.la*
--8<---------------cut here---------------end--------------->8---

Compare to

--8<---------------cut here---------------start------------->8---
❯ guix shell sdl2 -D ffmpeg@4

❯ ls $GUIX_ENVIRONMENT/lib/libSDL2* -la
lrwxrwxrwx 1 root root 76 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2-2.0.so.0 -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2-2.0.so.0*
lrwxrwxrwx 1 root root 81 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2-2.0.so.0.14.0 -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2-2.0.so.0.14.0*
lrwxrwxrwx 1 root root 83 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2-2.0.so.0.2400.0 -> /gnu/store/f3bx0lad4w42035mlch9vnbl94q62yl0-sdl2-2.24.0/lib/libSDL2-2.0.so.0.2400.0*
lrwxrwxrwx 1 root root 69 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2.a -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2.a
lrwxrwxrwx 1 root root 70 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2.la -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2.la*
lrwxrwxrwx 1 root root 73 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2main.a -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2main.a
lrwxrwxrwx 1 root root 74 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2main.la -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2main.la*
lrwxrwxrwx 1 root root 70 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2.so -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2.so*
lrwxrwxrwx 1 root root 74 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2_test.a -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2_test.a
lrwxrwxrwx 1 root root 75 Dec 31  1969 /gnu/store/5qha912xpch2qswvc7clm3v08zab3zl9-profile/lib/libSDL2_test.la -> /gnu/store/m2p4dymf3s001kqmclr8dcysxdplz2b6-sdl2-2.0.14/lib/libSDL2_test.la*
--8<---------------cut here---------------end--------------->8---

We see that a needed and expected library, libSDL2-2.0.so.0, points to sdl2-2.24.0 in the first case and sdl2-2.014 in the second, matching the "later package argument takes precedence rule." We might expect this can get rather confusing given a few inputs and different versions.

Is this the expected behavior? In discussing with nckxhexen on #guix, it seemed something that should be messaged to the user. Perhaps a warning that there is a potential conflict/collision as one package is overriding or shadowing the other. And documented. The behavior itself seems predictable and perhaps the best choice here, if it is communicated.

Thoughts? Patches?

Thanks!
John