Subject: Re: bug#57680: [PATCH 0/2] image: Add tarball support.

From: Ludovic Courtès <[email-masked]>
Date: Sat, 24 Sep 2022 15:52:05 +0200

Hi,

Mathieu Othacehe <[email-masked]> skribis:

> From: Alex Griffin <[email-masked]>
>
> * gnu/image.scm (<image>)[fields]: Add tarball to the supported formats.
> * gnu/system/image.scm (tarball-image, tarball-image-type): New variables.
> (system-tarball-image): New procedure.
> (image->root-file-system): Add tarball image support.
> (system-image): Ditto.
>
> Signed-off-by: Mathieu Othacehe <[email-masked]>

Nice!

Perhaps we need to mention it in the manual?

> +;;
> +;; Tarball image.
> +;;

Three semicolons maybe?  :-)

> +(define* (system-tarball-image image
> +                               #:key
> +                               (name "image")
> +                               (compressor (srfi-1:first %compressors)))
> +  "Build a tarball of IMAGE.  NAME is the base name to use for the
> +output file."
> +  (let* ((os (image-operating-system image))
> +         (substitutable? (image-substitutable? image))
> +         (schema (local-file (search-path %load-path
> +                                          "guix/store/schema.sql")))
> +         (name (string-append name ".tar" (compressor-extension compressor)))
> +         (graph "system-graph"))
> +    (define builder
> +      (with-extensions gcrypt-sqlite3&co          ;for (guix store database)
> +        (with-imported-modules `(,@(source-module-closure
> +                                    '((guix build pack)
> +                                      (guix build store-copy)
> +                                      (guix build utils)
> +                                      (guix store database)
> +                                      (gnu build image))
> +                                    #:select? not-config?)
> +                                 ((guix config) => ,(make-config.scm)))
> +          #~(begin
> +              (use-modules (guix build pack)
> +                           (guix build store-copy)
> +                           (guix build utils)
> +                           (guix store database)
> +                           (gnu build image))
> +
> +              ;; Set the SQL schema location.
> +              (sql-schema #$schema)
> +
> +              ;; Allow non-ASCII file names--e.g., 'nss-certs'--to be decoded.
> +              (setenv "GUIX_LOCPATH"
> +                      #+(file-append glibc-utf8-locales "/lib/locale"))
> +              (setlocale LC_ALL "en_US.utf8")
> +
> +              (let ((image-root (string-append (getcwd) "/tmp-root"))
> +                    (tar #+(file-append tar "/bin/tar")))
> +
> +                (mkdir-p image-root)
> +                (initialize-root-partition image-root
> +                                           #:references-graphs '(#$graph)
> +                                           #:deduplicate? #f
> +                                           #:system-directory #$os)
> +
> +                (with-directory-excursion image-root
> +                  (apply invoke tar "-cvf" #$output "."
> +                         (tar-base-options
> +                          #:tar tar
> +                          #:compressor
> +                          #+(and=> compressor compressor-command)))))))))
> +
> +    (computed-file name builder
> +                   ;; Allow offloading so that this I/O-intensive process
> +                   ;; doesn't run on the build farm's head node.
> +                   #:local-build? #f
> +                   #:options `(#:references-graphs ((,graph ,os))
> +                               #:substitutable? ,substitutable?))))

There’s probably something to be factorized with (guix scripts pack),
but that can be left for later with a TODO.

Otherwise LGTM, thank you & Alex!

Ludo’.