Subject: bug#74015: 'guix shell --export-manifest' fails for some transformations

From: Simon Tournier <[email-masked]>
Date: Fri, 25 Oct 2024 19:08:17 +0200

Hi,

I notice this:

--8<---------------cut here---------------start------------->8---
$ cat manifest.scm
(use-modules (guix transformations) (guix packages)
             (guix download) (guix build-system r))

(define r-knitr
  (specification->package "r-knitr"))

(define r-knitr-other
  (package
    (inherit r-knitr)
    (version "1.47")
    (source (origin
              (method url-fetch)
              (uri (cran-uri "knitr" version))
              (sha256
               (base32
                "1kx6g8ddbigwx3bmq771gwi3din3fxjn59l801904kjaz6dq9pgs"))))))

(define r-ggplot2
  (package
    (inherit
     ((package-input-rewriting `((,r-knitr . ,r-knitr-other)))
      (specification->package "r-ggplot2")))
    (name "my-ggplot")))

(define transform
  (options->transformation
    '((with-c-toolchain . "r-minimal=gcc-toolchain@12")
      (with-c-toolchain . "r=gcc-toolchain@12"))))

(packages->manifest
 (append
  (map specification->package
       (list "python" "python-numpy"))
  (map transform
       (list (specification->package "r")
             r-ggplot2))))

$ guix shell -m manifest.scm --export-manifest
guix shell: warning: transformation 'with-c-toolchain' had no effect on [email-masked].
;; What follows is a "manifest" equivalent to the command line you gave.
;; You can store it in a file that you may then pass to any 'guix' command
;; that accepts a '--manifest' (or '-m') option.

(use-modules (guix transformations))

(define transform1
  (options->transformation
    '((with-c-toolchain . "r-minimal=gcc-toolchain@12")
      (with-c-toolchain . "r=gcc-toolchain@12"))))

(packages->manifest
  (list (specification->package "python")
        (specification->package "python-numpy")
        (transform1 (specification->package "r"))
        (transform1 (specification->package "my-ggplot"))))
--8<---------------cut here---------------end--------------->8---

Well, this is incorrect.  While I understand the approximation when
dealing with profiles built over time in the imperative way, here I am
missing why the transformation of ’r-ggplot2’ is skipped.  And even the
export manifest is broken.

It’s skipped because:

--8<---------------cut here---------------start------------->8---
$ guix shell -m manifest.scm
$ grep ggplot $GUIX_ENVIRONMENT/manifest
     ("my-ggplot"
      "/gnu/store/x0jbmvg0nbl7lyk8zd938rq2c7c9qkn4-my-ggplot-3.5.1"
--8<---------------cut here---------------end--------------->8---

Please note that if the symbol ’r-ggplot2’ is not named “my-ggplot” but
kept as ’r-ggplot2“:

        (define r-ggplot2
          ((package-input-rewriting `((,r-knitr . ,r-knitr-other)))
              (specification->package "r-ggplot2")))

then the bug is maybe worse because the exported manifest “works” but
without the transformation… which can be misleading and hard to detect.

Well, I understand it’s hard to capture this kind of transformation.
Still, it appears to me as an half-baked feature. :-)

That’s annoying in some context as “guix pack --save-provenance” [1].
Even, it defeats the idea of a self-contained reproducible binary
container. ;-)

Maybe, aside the profile ’manifest’ file, we could store all the
manifests provided by the command line.  Something as:

    /gnu/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-profile/manifest
    /gnu/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-profile/manifest.orig1
    /gnu/store/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx-profile/manifest.orig2
    …

where manifest.orig1 and manifest.orig2 are the copy of files ’foo.scm’
and ’bar.scm’ from:

    -m foo.scm -m bar.scm

This way, the option --export-manifest could be improved.

WDYT?

Cheers,
simon

1: https://hpc.guix.info/blog/2021/10/when-docker-images-become-fixed-point