Subject: [bug#74500] pack: add ‘--file=FILE’ with the same meaning as for guix build

From: "Dr. Arne Babenhauserheide" <[email-masked]>
Date: Sun, 24 Nov 2024 00:37:46 +0100

Hi,

the attached patch adds the option to use `guix pack --file=guix.scm` just
like you’d use `guix build --file=guix.scm` or `guix shell
--file=guix.scm`.

guix pack -f ... still means --format to preserve backwards
compatibility. Only the long option --file is added.

From a1956bea3a33fed9a01246c9e5e394a7dd9daf6c Mon Sep 17 00:00:00 2001
Message-ID: <[email-masked]>
From: Arne Babenhauserheide <[email-masked]>
Date: Sun, 24 Nov 2024 00:32:36 +0100
Subject: [PATCH] =?UTF-8?q?pack:=20add=20=E2=80=98--file=3DFILE=E2=80=99?=
 =?UTF-8?q?=20with=20the=20same=20meaning=20as=20for=20guix=20build?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

* guix/scripts/pack.scm (%options): add --file=FILE, but no
  shorthand (that’s already taken for format).
* doc/guix.texi (Invoking guix pack): document --file

Change-Id: I87797fccdf218ead3b7f471a84034e8a8d566245
---
 doc/guix.texi         |  8 ++++++++
 guix/scripts/pack.scm | 11 +++++++++++
 2 files changed, 19 insertions(+)

diff --git a/doc/guix.texi b/doc/guix.texi
index 29bce718d4..aea8bf6063 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -7217,6 +7217,14 @@ Invoking guix pack
 build} (@pxref{Additional Build Options, @option{--expression} in
 @command{guix build}}).
 
+@item --file=@var{file}
+build a pack the code within @var{file} evaluates to.
+
+This has the same purpose as the same-named option in @command{guix
+build} (@pxref{Additional Build Options, @option{--file} in
+@command{guix build}}), but it has no shorthand, because @option{-f}
+already means @option{--format}.
+
 @anchor{pack-manifest}
 @item --manifest=@var{file}
 @itemx -m @var{file}
diff --git a/guix/scripts/pack.scm b/guix/scripts/pack.scm
index 7c5fe76fe0..d588f40257 100644
--- a/guix/scripts/pack.scm
+++ b/guix/scripts/pack.scm
@@ -28,6 +28,7 @@
 
 (define-module (guix scripts pack)
   #:use-module (guix scripts)
+  #:autoload   (guix import json) (json->scheme-file)
   #:use-module (guix ui)
   #:use-module (guix gexp)
   #:use-module (guix utils)
@@ -1430,6 +1431,9 @@ (define %options
                  (lambda (opt name arg result)
                    (alist-cons 'derivation-only? #t result)))
 
+         (option '("file") #t #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'file arg result)))
          (option '(#\f "format") #t #f
                  (lambda (opt name arg result)
                    (alist-cons 'format (string->symbol arg) result)))
@@ -1520,6 +1524,8 @@ (define (show-help)
   (show-deb-format-options)
   (show-rpm-format-options)
   (newline)
+  (display (G_ "
+      --file=FORMAT      build a pack the code within FILE evaluates to"))
   (display (G_ "
   -f, --format=FORMAT    build a pack in the given FORMAT"))
   (display (G_ "
@@ -1584,6 +1590,11 @@ (define-command (guix-pack . args)
            list))
         (('expression . exp)
          (read/eval-package-expression exp))
+        (('file . file)
+         (let ((file (or (and (string-suffix? ".json" file)
+                              (json->scheme-file file))
+                         file)))
+           (load* file (make-user-module '()))))
         (x #f)))
 
     (define (manifest-from-args store opts)

base-commit: 7c93145d9e027cb571bf7634192dfae5468ecde2
prerequisite-patch-id: 088a72da8c11e5d1c7087b4a5e8bb9c4a3b9b2af
prerequisite-patch-id: a092dba2c994aba4c74f1484621cebe53f548492
prerequisite-patch-id: 09ee3fdfcc708aeec9e6a7a54e2993e857e19aca
prerequisite-patch-id: 7957383d6685c848a7cbfa78e930adeaf528a2e1
prerequisite-patch-id: aa5d5050c29bbacf33790ca89f8c2690337f3ac7
prerequisite-patch-id: 2883dba4155a5a883cf03d43a130cb5f31de189c
prerequisite-patch-id: d14add7cc2f54106903ee5427a510b4204fb636f
prerequisite-patch-id: 2beca5d9522ccdc5c6751681bbf00d5107380fd8
-- 
2.46.0

Best wishes,
Arne
-- 
Unpolitisch sein
heißt politisch sein,
ohne es zu merken.
draketo.de