[PATCH] home: Add -I, --list-installed option.

  • Done
  • quality assurance status badge
Details
3 participants
  • Andrew Tropin
  • Antero Mejr
  • Ludovic Courtès
Owner
unassigned
Submitted by
Antero Mejr
Severity
normal
A
A
Antero Mejr wrote on 6 Jul 2022 21:13
(address . guix-patches@gnu.org)
20220706191311.14662-1-antero@mailbox.org
* guix/scripts/package.scm (list-installed): New procedure.
* guix/scripts/home.scm: Use it.
---
guix/scripts/home.scm | 13 +++++++++++++
guix/scripts/package.scm | 30 +++++++++++++++++-------------
2 files changed, 30 insertions(+), 13 deletions(-)

Toggle diff (95 lines)
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 0f5c3388a1..7a5078fe3b 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -4,6 +4,7 @@
;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -143,6 +144,10 @@ (define (show-help)
use BACKEND for 'extension-graph' and 'shepherd-graph'"))
(newline)
(display (G_ "
+ -I, --list-installed[=REGEXP]
+ list installed packages matching REGEXP"))
+ (newline)
+ (display (G_ "
-h, --help display this help and exit"))
(display (G_ "
-V, --version display version information and exit"))
@@ -183,6 +188,14 @@ (define %options
(option '("graph-backend") #t #f
(lambda (opt name arg result)
(alist-cons 'graph-backend arg result)))
+ (option '(#\I "list-installed") #f #t
+ (lambda (opt name arg result)
+ (pretty-print-table
+ (reverse
+ (list-installed (or arg "")
+ (list
+ (string-append %guix-home "/profile")))))
+ (exit 0)))
;; Container options.
(option '(#\N "network") #f #f
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 99a6cfaa29..144d18a626 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -11,6 +11,7 @@
;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -773,6 +774,21 @@ (define absolute
(add-indirect-root store absolute))
+(define-public (list-installed regexp profiles)
+ (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
+ (manifest (concatenate-manifests
+ (map profile-manifest profiles)))
+ (installed (manifest-entries manifest)))
+ (leave-on-EPIPE
+ (let ((rows (filter-map
+ (match-lambda
+ (($ <manifest-entry> name version output path _)
+ (and (regexp-exec regexp name)
+ (list name (or version "?") output path))))
+ installed)))
+ ;; Show most recently installed packages last.
+ (reverse rows)))))
+
;;;
;;; Queries and actions.
@@ -824,19 +840,7 @@ (define (diff-profiles profile numbers)
#t)
(('list-installed regexp)
- (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
- (manifest (concatenate-manifests
- (map profile-manifest profiles)))
- (installed (manifest-entries manifest)))
- (leave-on-EPIPE
- (let ((rows (filter-map
- (match-lambda
- (($ <manifest-entry> name version output path _)
- (and (regexp-exec regexp name)
- (list name (or version "?") output path))))
- installed)))
- ;; Show most recently installed packages last.
- (pretty-print-table (reverse rows)))))
+ (pretty-print-table (list-installed regexp profiles))
#t)
(('list-available regexp)
--
2.36.1
A
A
Antero Mejr wrote on 7 Jul 2022 17:06
(address . 56428@debbugs.gnu.org)
20220707150644.2349-1-antero@mailbox.org
* guix/scripts/package.scm (list-installed): New procedure.
* guix/scripts/home.scm: Use it.
---
Remove extra (reverse...) from last patch.

guix/scripts/home.scm | 12 ++++++++++++
guix/scripts/package.scm | 30 +++++++++++++++++-------------
2 files changed, 29 insertions(+), 13 deletions(-)

Toggle diff (94 lines)
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 0f5c3388a1..b0b8412d8c 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -4,6 +4,7 @@
;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -143,6 +144,10 @@ (define (show-help)
use BACKEND for 'extension-graph' and 'shepherd-graph'"))
(newline)
(display (G_ "
+ -I, --list-installed[=REGEXP]
+ list installed packages matching REGEXP"))
+ (newline)
+ (display (G_ "
-h, --help display this help and exit"))
(display (G_ "
-V, --version display version information and exit"))
@@ -183,6 +188,13 @@ (define %options
(option '("graph-backend") #t #f
(lambda (opt name arg result)
(alist-cons 'graph-backend arg result)))
+ (option '(#\I "list-installed") #f #t
+ (lambda (opt name arg result)
+ (pretty-print-table
+ (list-installed (or arg "")
+ (list
+ (string-append %guix-home "/profile"))))
+ (exit 0)))
;; Container options.
(option '(#\N "network") #f #f
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 99a6cfaa29..02e91a0ee1 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -11,6 +11,7 @@
;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -773,6 +774,20 @@ (define absolute
(add-indirect-root store absolute))
+(define-public (list-installed regexp profiles)
+ (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
+ (manifest (concatenate-manifests
+ (map profile-manifest profiles)))
+ (installed (manifest-entries manifest)))
+ (leave-on-EPIPE
+ (let ((rows (filter-map
+ (match-lambda
+ (($ <manifest-entry> name version output path _)
+ (and (regexp-exec regexp name)
+ (list name (or version "?") output path))))
+ installed)))
+ rows))))
+
;;;
;;; Queries and actions.
@@ -824,19 +839,8 @@ (define (diff-profiles profile numbers)
#t)
(('list-installed regexp)
- (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
- (manifest (concatenate-manifests
- (map profile-manifest profiles)))
- (installed (manifest-entries manifest)))
- (leave-on-EPIPE
- (let ((rows (filter-map
- (match-lambda
- (($ <manifest-entry> name version output path _)
- (and (regexp-exec regexp name)
- (list name (or version "?") output path))))
- installed)))
- ;; Show most recently installed packages last.
- (pretty-print-table (reverse rows)))))
+ ;; Show most recently installed packages last.
+ (pretty-print-table (reverse (list-installed regexp profiles)))
#t)
(('list-available regexp)
--
2.36.1
A
A
Andrew Tropin wrote on 12 Jul 2022 12:13
87o7xu1vve.fsf@trop.in
On 2022-07-07 15:06, Antero Mejr via Guix-patches via wrote:

Hi Antero,

this is a good addition, thank you very much!

A hint: use reroll-count when generating new revision of the patch and
subject will become [PATCH v2], [PATCH v3] etc.

Toggle quote (28 lines)
> * guix/scripts/package.scm (list-installed): New procedure.
> * guix/scripts/home.scm: Use it.
> ---
> Remove extra (reverse...) from last patch.
>
> guix/scripts/home.scm | 12 ++++++++++++
> guix/scripts/package.scm | 30 +++++++++++++++++-------------
> 2 files changed, 29 insertions(+), 13 deletions(-)
>
> diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
> index 0f5c3388a1..b0b8412d8c 100644
> --- a/guix/scripts/home.scm
> +++ b/guix/scripts/home.scm
> @@ -4,6 +4,7 @@
> ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
> ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
> ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -143,6 +144,10 @@ (define (show-help)
> use BACKEND for 'extension-graph' and 'shepherd-graph'"))
> (newline)
> (display (G_ "
> + -I, --list-installed[=REGEXP]
> + list installed packages matching REGEXP"))

1. guix home/system and guix package has slightly different cli:
guix package --list-generations vs guix home/system list-generations

I think that later is more apropriate, because:

`guix package --remove=htop --list-installed` is possible, but doesn't
make too much sense, and `guix home reconfigure ./he.scm list-installed`
is not possible, because only one action at time can be specicified.

Implementing this functionality as --argument makes it possible to type
`guix home reconfigure ./he.scm --list-installed`, which again doesn't
make much sense as in the example above. I advice either implement
list-installed as a separate action or as an additional --argument to
describe/list-generations action.

2. Would be good to mention it in doc/guix.texi.

3. It would be nice to implement the same for guix system.

Toggle quote (31 lines)
> + (newline)
> + (display (G_ "
> -h, --help display this help and exit"))
> (display (G_ "
> -V, --version display version information and exit"))
> @@ -183,6 +188,13 @@ (define %options
> (option '("graph-backend") #t #f
> (lambda (opt name arg result)
> (alist-cons 'graph-backend arg result)))
> + (option '(#\I "list-installed") #f #t
> + (lambda (opt name arg result)
> + (pretty-print-table
> + (list-installed (or arg "")
> + (list
> + (string-append %guix-home "/profile"))))
> + (exit 0)))
>
> ;; Container options. (option '(#\N "network") #f #f diff
> --git a/guix/scripts/package.scm b/guix/scripts/package.scm index
> 99a6cfaa29..02e91a0ee1 100644 --- a/guix/scripts/package.scm +++
> b/guix/scripts/package.scm @@ -11,6 +11,7 @@ ;;; Copyright © 2020
> Simon Tournier <zimon.toutoune@gmail.com> ;;; Copyright © 2018 Steve
> Sprang <scs@stevesprang.com> ;;; Copyright © 2022 Josselin Poiret
> <dev@jpoiret.xyz> +;;; Copyright © 2022 Antero Mejr
> <antero@mailbox.org> ;;; ;;; This file is part of GNU Guix. ;;; @@
> -773,6 +774,20 @@ (define absolute
>
> (add-indirect-root store absolute))
>
> +(define-public (list-installed regexp profiles)

To make it consistent with the rest of the module, I think it will
better to use define and explicitly export list-installed in module
definition at the top of the file.

Toggle quote (39 lines)
> + (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> + (manifest (concatenate-manifests
> + (map profile-manifest profiles)))
> + (installed (manifest-entries manifest)))
> + (leave-on-EPIPE
> + (let ((rows (filter-map
> + (match-lambda
> + (($ <manifest-entry> name version output path _)
> + (and (regexp-exec regexp name)
> + (list name (or version "?") output path))))
> + installed)))
> + rows))))
> +
>
> ;;;
> ;;; Queries and actions.
> @@ -824,19 +839,8 @@ (define (diff-profiles profile numbers)
> #t)
>
> (('list-installed regexp)
> - (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> - (manifest (concatenate-manifests
> - (map profile-manifest profiles)))
> - (installed (manifest-entries manifest)))
> - (leave-on-EPIPE
> - (let ((rows (filter-map
> - (match-lambda
> - (($ <manifest-entry> name version output path _)
> - (and (regexp-exec regexp name)
> - (list name (or version "?") output path))))
> - installed)))
> - ;; Show most recently installed packages last.
> - (pretty-print-table (reverse rows)))))
> + ;; Show most recently installed packages last.
> + (pretty-print-table (reverse (list-installed regexp profiles)))
> #t)
>
> (('list-available regexp)

Tested the patch, guix package -I, guix home -I filter-regex works good,
but see my comments above.

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmLNSWUACgkQIgjSCVjB
3rBUGA/8CEASxPKUccYwJNNO5vC6L2MewwKCrB7SbTJEQURaii79yqcKAiO9CIus
A6u/S+7v7zM23v2HVym8BsCk2JOqoIJM1kL3DJmqZ4fsRqHWSdnyX43eQ4mdtp6J
/JziR+tZvFLtljtPMs1V1tMeiLKd25XioNysId4zBHOArEEymE5tLhcnvocaDX6/
bl4Rx2tsOwL2R8J/+lOFnGEbphI+yp5W2U+kt+QGlx3lMBM/PO7ol+BmJLflP5Od
qQEDIZ8D4j5zPccNNvfw9ojUmi/RKXyMJpkFDNaHFQt2gT0mWjMPhH+c4sqnU5xw
AF7gdizJzNCUzdsMx7YluZ5rPhtPsYZU4MNMoBTGbQac+YkgEhTypcVb4o1gnxHd
I6hXbCIRSavtoGHthfgwmjk21TpP9b08e55ItWiA5s4BDIBMvTwHJguJVWTCqfc3
1uacjhwuXt2GAxoGptM2/cYW8vOyjISi/mnY8RRz6Ajohw5X5pcBHgrvFhS9pgqP
l+LKc/amihCqSMF9Kcb+0cPu/iIYnn0jVnkfV24DqUBzKP5rmaozXw/vXDB4hxFs
KbIWtWHz195apUN7yzUfOpJk1fxmKyPDg51+1JOFYoD9iunivPLhULDmlvhNKQvf
dwAd2w0/ndn/TaTKOD5gN7CSUlzkagLqTSqtxDex/RJRlAD6zhs=
=8wb9
-----END PGP SIGNATURE-----

A
A
Antero Mejr wrote on 13 Jul 2022 00:50
[PATCH v3] home: Add -I, --list-installed option.
(address . 56428@debbugs.gnu.org)(address . andrew@trop.in)
20220712225007.23875-1-antero@mailbox.org
* guix/scripts/package.scm (list-installed): New procedure.
* guix/scripts/home.scm: Use it.
* guix/scripts/utils.scm (pretty-print-table): New argument "left-pad".
* doc/guix.texi (Invoking Guix Home): Add information and example for
--list-installed flag.
---
doc/guix.texi | 15 ++++++++++++
guix/scripts/home.scm | 52 +++++++++++++++++++++++++++++-----------
guix/scripts/package.scm | 31 ++++++++++++++----------
guix/utils.scm | 4 ++--
4 files changed, 73 insertions(+), 29 deletions(-)

Toggle diff (234 lines)
diff --git a/doc/guix.texi b/doc/guix.texi
index 097e4a362b..fc3a2d962d 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -40312,6 +40312,17 @@ install anything.
Describe the current home generation: its file name, as well as
provenance information when available.
+To show installed packages in the current home generation's profile,
+the @code{--list-installed} flag is provided, with the same syntax that
+is used in @command{guix package --list-installed}
+(@pxref{Invoking guix package}). For instance, the following command
+shows a table of all emacs-related packages installed in the
+current home generation's profile, at the end of the description:
+
+@example
+guix home describe --list-installed=emacs
+@end example
+
@item list-generations
List a summary of each generation of the home environment available on
disk, in a human-readable way. This is similar to the
@@ -40327,6 +40338,10 @@ generations that are up to 10 days old:
$ guix home list-generations 10d
@end example
+The @code{--list-installed} flag may also be specified, with the same
+syntax that is used in @command{guix home describe}. This may be helpful
+if trying to determine when a package was added to the home profile.
+
@item import
Generate a @dfn{home environment} from the packages in the default
profile and configuration files found in the user's home directory. The
diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
index 0f5c3388a1..97d626114a 100644
--- a/guix/scripts/home.scm
+++ b/guix/scripts/home.scm
@@ -4,6 +4,7 @@
;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -143,6 +144,11 @@ (define (show-help)
use BACKEND for 'extension-graph' and 'shepherd-graph'"))
(newline)
(display (G_ "
+ -I, --list-installed[=REGEXP]
+ for 'describe' or 'list-generations', list installed
+ packages matching REGEXP"))
+ (newline)
+ (display (G_ "
-h, --help display this help and exit"))
(display (G_ "
-V, --version display version information and exit"))
@@ -183,6 +189,9 @@ (define %options
(option '("graph-backend") #t #f
(lambda (opt name arg result)
(alist-cons 'graph-backend arg result)))
+ (option '(#\I "list-installed") #f #t
+ (lambda (opt name arg result)
+ (alist-cons 'list-installed (or arg "") result)))
;; Container options.
(option '(#\N "network") #f #f
@@ -569,17 +578,20 @@ (define-syntax-rule (with-store* store exp ...)
deploy the home environment described by these files.\n")
destination))))
((describe)
- (match (generation-number %guix-home)
- (0
- (leave (G_ "no home environment generation, nothing to describe~%")))
- (generation
- (display-home-environment-generation generation))))
+ (let ((list-installed-regex (assoc-ref opts 'list-installed)))
+ (match (generation-number %guix-home)
+ (0
+ (leave (G_ "no home environment generation, nothing to describe~%")))
+ (generation
+ (display-home-environment-generation
+ generation #:list-installed-regex list-installed-regex)))))
((list-generations)
- (let ((pattern (match args
+ (let ((list-installed-regex (assoc-ref opts 'list-installed))
+ (pattern (match args
(() #f)
((pattern) pattern)
(x (leave (G_ "wrong number of arguments~%"))))))
- (list-generations pattern)))
+ (list-generations pattern #:list-installed-regex list-installed-regex)))
((switch-generation)
(let ((pattern (match args
((pattern) pattern)
@@ -748,7 +760,8 @@ (define (search . args)
(define* (display-home-environment-generation
number
- #:optional (profile %guix-home))
+ #:optional (profile %guix-home)
+ #:key (list-installed-regex #f))
"Display a summary of home-environment generation NUMBER in a
human-readable format."
(define (display-channel channel)
@@ -782,9 +795,16 @@ (define-values (channels config-file)
(format #t (G_ " configuration file: ~a~%")
(if (supports-hyperlinks?)
(file-hyperlink config-file)
- config-file))))))
-
-(define* (list-generations pattern #:optional (profile %guix-home))
+ config-file)))
+ (when list-installed-regex
+ (format #t (G_ " packages:\n"))
+ (pretty-print-table (list-installed
+ list-installed-regex
+ (list (string-append generation "/profile")))
+ #:left-pad 4)))))
+
+(define* (list-generations pattern #:optional (profile %guix-home)
+ #:key (list-installed-regex #f))
"Display in a human-readable format all the home environment
generations matching PATTERN, a string. When PATTERN is #f, display
all the home environment generations."
@@ -792,14 +812,18 @@ (define* (list-generations pattern #:optional (profile %guix-home))
(raise (condition (&profile-not-found-error
(profile profile)))))
((not pattern)
- (for-each display-home-environment-generation (profile-generations profile)))
+ (for-each (cut display-home-environment-generation <>
+ #:list-installed-regex list-installed-regex)
+ (profile-generations profile)))
((matching-generations pattern profile)
=>
(lambda (numbers)
(if (null-list? numbers)
(exit 1)
- (leave-on-EPIPE
- (for-each display-home-environment-generation numbers)))))))
+ (leave-on-EPIPE (for-each
+ (cut display-home-environment-generation <>
+ #:list-installed-regex list-installed-regex)
+ numbers)))))))
;;;
diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
index 99a6cfaa29..af61b50222 100644
--- a/guix/scripts/package.scm
+++ b/guix/scripts/package.scm
@@ -11,6 +11,7 @@
;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
+;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -67,6 +68,7 @@ (define-module (guix scripts package)
delete-generations
delete-matching-generations
guix-package
+ list-installed
search-path-environment-variables
manifest-entry-version-prefix
@@ -773,6 +775,20 @@ (define absolute
(add-indirect-root store absolute))
+(define (list-installed regexp profiles)
+ (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
+ (manifest (concatenate-manifests
+ (map profile-manifest profiles)))
+ (installed (manifest-entries manifest)))
+ (leave-on-EPIPE
+ (let ((rows (filter-map
+ (match-lambda
+ (($ <manifest-entry> name version output path _)
+ (and (regexp-exec regexp name)
+ (list name (or version "?") output path))))
+ installed)))
+ rows))))
+
;;;
;;; Queries and actions.
@@ -824,19 +840,8 @@ (define (diff-profiles profile numbers)
#t)
(('list-installed regexp)
- (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
- (manifest (concatenate-manifests
- (map profile-manifest profiles)))
- (installed (manifest-entries manifest)))
- (leave-on-EPIPE
- (let ((rows (filter-map
- (match-lambda
- (($ <manifest-entry> name version output path _)
- (and (regexp-exec regexp name)
- (list name (or version "?") output path))))
- installed)))
- ;; Show most recently installed packages last.
- (pretty-print-table (reverse rows)))))
+ ;; Show most recently installed packages last.
+ (pretty-print-table (reverse (list-installed regexp profiles)))
#t)
(('list-available regexp)
diff --git a/guix/utils.scm b/guix/utils.scm
index 745da98a79..8484442b29 100644
--- a/guix/utils.scm
+++ b/guix/utils.scm
@@ -1124,7 +1124,7 @@ (define* (string-closest trial tests #:key (threshold 3))
;;; Prettified output.
;;;
-(define* (pretty-print-table rows #:key (max-column-width 20))
+(define* (pretty-print-table rows #:key (max-column-width 20) (left-pad 0))
"Print ROWS in neat columns. All rows should be lists of strings and each
row should have the same length. The columns are separated by a tab
character, and aligned using spaces. The maximum width of each column is
@@ -1143,7 +1143,7 @@ (define* (pretty-print-table rows #:key (max-column-width 20))
(map (cut min <> max-column-width)
column-widths)))
(fmt (string-append (string-join column-formats "\t") "\t~a")))
- (for-each (cut format #t "~?~%" fmt <>) rows)))
+ (for-each (cut format #t "~v_~?~%" left-pad fmt <>) rows)))
;;; Local Variables:
;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1)
--
2.36.1
A
A
Antero Mejr wrote on 13 Jul 2022 00:50
Re: [bug#56428] [PATCH] home: Add -I, --list-installed option.
(name . Andrew Tropin)(address . andrew@trop.in)(address . 56428@debbugs.gnu.org)
87pmiaj5vx.fsf@mailbox.org
Andrew Tropin <andrew@trop.in> writes:

Toggle quote (6 lines)
> Implementing this functionality as --argument makes it possible to type
> `guix home reconfigure ./he.scm --list-installed`, which again doesn't
> make much sense as in the example above. I advice either implement
> list-installed as a separate action or as an additional --argument to
> describe/list-generations action.

I added it to both guix home describe and list-generations. Adding it to
describe seems most intuitive to me, and adding it to list-generations
is useful for tracking when a package was added to the profile.

If --list-installed is specified for an invalid subcommand, the flag is
ignored.
Same behavior as when using --network with a guix home describe, for
example.

Toggle quote (2 lines)
> 2. Would be good to mention it in doc/guix.texi.

Done.

Toggle quote (2 lines)
> 3. It would be nice to implement the same for guix system.

I will do that in another patch/issue.

Toggle quote (4 lines)
> To make it consistent with the rest of the module, I think it will
> better to use define and explicitly export list-installed in module
> definition at the top of the file.

Done.

Thanks for the review, and also thanks for guix home!
A
A
Andrew Tropin wrote on 14 Jul 2022 11:21
Re: [PATCH v3] home: Add -I, --list-installed option.
87wncgoxrg.fsf@trop.in
On 2022-07-12 22:50, Antero Mejr wrote:

Toggle quote (245 lines)
> * guix/scripts/package.scm (list-installed): New procedure.
> * guix/scripts/home.scm: Use it.
> * guix/scripts/utils.scm (pretty-print-table): New argument "left-pad".
> * doc/guix.texi (Invoking Guix Home): Add information and example for
> --list-installed flag.
> ---
> doc/guix.texi | 15 ++++++++++++
> guix/scripts/home.scm | 52 +++++++++++++++++++++++++++++-----------
> guix/scripts/package.scm | 31 ++++++++++++++----------
> guix/utils.scm | 4 ++--
> 4 files changed, 73 insertions(+), 29 deletions(-)
>
> diff --git a/doc/guix.texi b/doc/guix.texi
> index 097e4a362b..fc3a2d962d 100644
> --- a/doc/guix.texi
> +++ b/doc/guix.texi
> @@ -40312,6 +40312,17 @@ install anything.
> Describe the current home generation: its file name, as well as
> provenance information when available.
>
> +To show installed packages in the current home generation's profile,
> +the @code{--list-installed} flag is provided, with the same syntax that
> +is used in @command{guix package --list-installed}
> +(@pxref{Invoking guix package}). For instance, the following command
> +shows a table of all emacs-related packages installed in the
> +current home generation's profile, at the end of the description:
> +
> +@example
> +guix home describe --list-installed=emacs
> +@end example
> +
> @item list-generations
> List a summary of each generation of the home environment available on
> disk, in a human-readable way. This is similar to the
> @@ -40327,6 +40338,10 @@ generations that are up to 10 days old:
> $ guix home list-generations 10d
> @end example
>
> +The @code{--list-installed} flag may also be specified, with the same
> +syntax that is used in @command{guix home describe}. This may be helpful
> +if trying to determine when a package was added to the home profile.
> +
> @item import
> Generate a @dfn{home environment} from the packages in the default
> profile and configuration files found in the user's home directory. The
> diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
> index 0f5c3388a1..97d626114a 100644
> --- a/guix/scripts/home.scm
> +++ b/guix/scripts/home.scm
> @@ -4,6 +4,7 @@
> ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
> ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
> ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -143,6 +144,11 @@ (define (show-help)
> use BACKEND for 'extension-graph' and 'shepherd-graph'"))
> (newline)
> (display (G_ "
> + -I, --list-installed[=REGEXP]
> + for 'describe' or 'list-generations', list installed
> + packages matching REGEXP"))
> + (newline)
> + (display (G_ "
> -h, --help display this help and exit"))
> (display (G_ "
> -V, --version display version information and exit"))
> @@ -183,6 +189,9 @@ (define %options
> (option '("graph-backend") #t #f
> (lambda (opt name arg result)
> (alist-cons 'graph-backend arg result)))
> + (option '(#\I "list-installed") #f #t
> + (lambda (opt name arg result)
> + (alist-cons 'list-installed (or arg "") result)))
>
> ;; Container options.
> (option '(#\N "network") #f #f
> @@ -569,17 +578,20 @@ (define-syntax-rule (with-store* store exp ...)
> deploy the home environment described by these files.\n")
> destination))))
> ((describe)
> - (match (generation-number %guix-home)
> - (0
> - (leave (G_ "no home environment generation, nothing to describe~%")))
> - (generation
> - (display-home-environment-generation generation))))
> + (let ((list-installed-regex (assoc-ref opts 'list-installed)))
> + (match (generation-number %guix-home)
> + (0
> + (leave (G_ "no home environment generation, nothing to describe~%")))
> + (generation
> + (display-home-environment-generation
> + generation #:list-installed-regex list-installed-regex)))))
> ((list-generations)
> - (let ((pattern (match args
> + (let ((list-installed-regex (assoc-ref opts 'list-installed))
> + (pattern (match args
> (() #f)
> ((pattern) pattern)
> (x (leave (G_ "wrong number of arguments~%"))))))
> - (list-generations pattern)))
> + (list-generations pattern #:list-installed-regex list-installed-regex)))
> ((switch-generation)
> (let ((pattern (match args
> ((pattern) pattern)
> @@ -748,7 +760,8 @@ (define (search . args)
>
> (define* (display-home-environment-generation
> number
> - #:optional (profile %guix-home))
> + #:optional (profile %guix-home)
> + #:key (list-installed-regex #f))
> "Display a summary of home-environment generation NUMBER in a
> human-readable format."
> (define (display-channel channel)
> @@ -782,9 +795,16 @@ (define-values (channels config-file)
> (format #t (G_ " configuration file: ~a~%")
> (if (supports-hyperlinks?)
> (file-hyperlink config-file)
> - config-file))))))
> -
> -(define* (list-generations pattern #:optional (profile %guix-home))
> + config-file)))
> + (when list-installed-regex
> + (format #t (G_ " packages:\n"))
> + (pretty-print-table (list-installed
> + list-installed-regex
> + (list (string-append generation "/profile")))
> + #:left-pad 4)))))
> +
> +(define* (list-generations pattern #:optional (profile %guix-home)
> + #:key (list-installed-regex #f))
> "Display in a human-readable format all the home environment
> generations matching PATTERN, a string. When PATTERN is #f, display
> all the home environment generations."
> @@ -792,14 +812,18 @@ (define* (list-generations pattern #:optional (profile %guix-home))
> (raise (condition (&profile-not-found-error
> (profile profile)))))
> ((not pattern)
> - (for-each display-home-environment-generation (profile-generations profile)))
> + (for-each (cut display-home-environment-generation <>
> + #:list-installed-regex list-installed-regex)
> + (profile-generations profile)))
> ((matching-generations pattern profile)
> =>
> (lambda (numbers)
> (if (null-list? numbers)
> (exit 1)
> - (leave-on-EPIPE
> - (for-each display-home-environment-generation numbers)))))))
> + (leave-on-EPIPE (for-each
> + (cut display-home-environment-generation <>
> + #:list-installed-regex list-installed-regex)
> + numbers)))))))
>
>
> ;;;
> diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
> index 99a6cfaa29..af61b50222 100644
> --- a/guix/scripts/package.scm
> +++ b/guix/scripts/package.scm
> @@ -11,6 +11,7 @@
> ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
> ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
> ;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
> +;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -67,6 +68,7 @@ (define-module (guix scripts package)
> delete-generations
> delete-matching-generations
> guix-package
> + list-installed
>
> search-path-environment-variables
> manifest-entry-version-prefix
> @@ -773,6 +775,20 @@ (define absolute
>
> (add-indirect-root store absolute))
>
> +(define (list-installed regexp profiles)
> + (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> + (manifest (concatenate-manifests
> + (map profile-manifest profiles)))
> + (installed (manifest-entries manifest)))
> + (leave-on-EPIPE
> + (let ((rows (filter-map
> + (match-lambda
> + (($ <manifest-entry> name version output path _)
> + (and (regexp-exec regexp name)
> + (list name (or version "?") output path))))
> + installed)))
> + rows))))
> +
>
> ;;;
> ;;; Queries and actions.
> @@ -824,19 +840,8 @@ (define (diff-profiles profile numbers)
> #t)
>
> (('list-installed regexp)
> - (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> - (manifest (concatenate-manifests
> - (map profile-manifest profiles)))
> - (installed (manifest-entries manifest)))
> - (leave-on-EPIPE
> - (let ((rows (filter-map
> - (match-lambda
> - (($ <manifest-entry> name version output path _)
> - (and (regexp-exec regexp name)
> - (list name (or version "?") output path))))
> - installed)))
> - ;; Show most recently installed packages last.
> - (pretty-print-table (reverse rows)))))
> + ;; Show most recently installed packages last.
> + (pretty-print-table (reverse (list-installed regexp profiles)))
> #t)
>
> (('list-available regexp)
> diff --git a/guix/utils.scm b/guix/utils.scm
> index 745da98a79..8484442b29 100644
> --- a/guix/utils.scm
> +++ b/guix/utils.scm
> @@ -1124,7 +1124,7 @@ (define* (string-closest trial tests #:key (threshold 3))
> ;;; Prettified output.
> ;;;
>
> -(define* (pretty-print-table rows #:key (max-column-width 20))
> +(define* (pretty-print-table rows #:key (max-column-width 20) (left-pad 0))
> "Print ROWS in neat columns. All rows should be lists of strings and each
> row should have the same length. The columns are separated by a tab
> character, and aligned using spaces. The maximum width of each column is
> @@ -1143,7 +1143,7 @@ (define* (pretty-print-table rows #:key (max-column-width 20))
> (map (cut min <> max-column-width)
> column-widths)))
> (fmt (string-append (string-join column-formats "\t") "\t~a")))
> - (for-each (cut format #t "~?~%" fmt <>) rows)))
> + (for-each (cut format #t "~v_~?~%" left-pad fmt <>) rows)))
>
> ;;; Local Variables:
> ;;; eval: (put 'call-with-progress-reporter 'scheme-indent-function 1)

Applied locally, tested, LGTM.

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmLP4BMACgkQIgjSCVjB
3rAsZQ/8CZJpU7JY/lUlAynPFp6ZidiNyni5K6GWEC8YVfp2hZNJb5oFYQSnu4Qj
nj8hYzWXw3d6Deb31sEUCFeRTgZ1RprMOj86RT3AEWDvM806cO/Px5JG+wASF1zW
PhwmD7xZQbUKGSynUAfXipx8zencPzFdtw87lDBui+HyiCp+RzRiR7noefcj9SGQ
5Lw3VWyaRYY4/+145ufFTybBbD+sAKQU2hjnYV1RaiiNl4/2CFn0htTVmKzPPGLZ
Dp7vnfE3vpFIjOZCMKOYDjoooHAQi+nEs4qw3MKpH314L1I+7wwPjw1hqD9idKj8
qQpHPGynGW3i2NTUZUAiEP/ArpSjl8OWnGUa/cPPVrCFo3fWGfAcRiDzHxdr/bhh
f6pjIAhHjf/lCOlMtbWhaLIXK43EO/4AQ2CMkTk0Us3ShSQOXrVyKJ6Yiqc4gwKr
yb1kq0THecBtFl7chPnxu957EtNygT1m9inHwL93ofM2XPonZPfJZRk96GjDrQez
RuwLgqgqdZRDRcl0ABDAuOpC9dxD3VNQKPJ4sa6ILnp9XrTfD2q/4twhNLz+6gpU
ZMj6BGCsgEyMpzaFk3ic5Tc3xbEDOFyFkMfriQe1voKG+QeQM3bMEDljsSxnVQxF
rIGkieE84xe3xD1jYK6WTpnet/cHlyqr948bhT1EozCEt2Z8vNI=
=P/kd
-----END PGP SIGNATURE-----

L
L
Ludovic Courtès wrote on 18 Jul 2022 15:21
Re: bug#56428: [PATCH] home: Add -I, --list-installed option.
(name . Antero Mejr)(address . antero@mailbox.org)
8735eyzhds.fsf_-_@gnu.org
Hi,

Antero Mejr <antero@mailbox.org> skribis:

Toggle quote (6 lines)
> * guix/scripts/package.scm (list-installed): New procedure.
> * guix/scripts/home.scm: Use it.
> * guix/scripts/utils.scm (pretty-print-table): New argument "left-pad".
> * doc/guix.texi (Invoking Guix Home): Add information and example for
> --list-installed flag.

I tweaked the wording in the manual, added a docstring to
‘list-installed’ (info "(guix) Formatting Code"), adjusted that of
‘pretty-print-table’, tweaked the commit log to list all the changes,
and committed.

Thanks!

Ludo’.
Closed
A
A
Andrew Tropin wrote on 5 Aug 2022 08:12
Re: [bug#56428] [PATCH] home: Add -I, --list-installed option.
87fsibb4nd.fsf@trop.in
On 2022-07-06 19:13, Antero Mejr via Guix-patches via wrote:

Toggle quote (101 lines)
> * guix/scripts/package.scm (list-installed): New procedure.
> * guix/scripts/home.scm: Use it.
> ---
> guix/scripts/home.scm | 13 +++++++++++++
> guix/scripts/package.scm | 30 +++++++++++++++++-------------
> 2 files changed, 30 insertions(+), 13 deletions(-)
>
> diff --git a/guix/scripts/home.scm b/guix/scripts/home.scm
> index 0f5c3388a1..7a5078fe3b 100644
> --- a/guix/scripts/home.scm
> +++ b/guix/scripts/home.scm
> @@ -4,6 +4,7 @@
> ;;; Copyright © 2021 Pierre Langlois <pierre.langlois@gmx.com>
> ;;; Copyright © 2021 Oleg Pykhalov <go.wigust@gmail.com>
> ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
> +;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -143,6 +144,10 @@ (define (show-help)
> use BACKEND for 'extension-graph' and 'shepherd-graph'"))
> (newline)
> (display (G_ "
> + -I, --list-installed[=REGEXP]
> + list installed packages matching REGEXP"))
> + (newline)
> + (display (G_ "
> -h, --help display this help and exit"))
> (display (G_ "
> -V, --version display version information and exit"))
> @@ -183,6 +188,14 @@ (define %options
> (option '("graph-backend") #t #f
> (lambda (opt name arg result)
> (alist-cons 'graph-backend arg result)))
> + (option '(#\I "list-installed") #f #t
> + (lambda (opt name arg result)
> + (pretty-print-table
> + (reverse
> + (list-installed (or arg "")
> + (list
> + (string-append %guix-home "/profile")))))
> + (exit 0)))
>
> ;; Container options.
> (option '(#\N "network") #f #f
> diff --git a/guix/scripts/package.scm b/guix/scripts/package.scm
> index 99a6cfaa29..144d18a626 100644
> --- a/guix/scripts/package.scm
> +++ b/guix/scripts/package.scm
> @@ -11,6 +11,7 @@
> ;;; Copyright © 2020 Simon Tournier <zimon.toutoune@gmail.com>
> ;;; Copyright © 2018 Steve Sprang <scs@stevesprang.com>
> ;;; Copyright © 2022 Josselin Poiret <dev@jpoiret.xyz>
> +;;; Copyright © 2022 Antero Mejr <antero@mailbox.org>
> ;;;
> ;;; This file is part of GNU Guix.
> ;;;
> @@ -773,6 +774,21 @@ (define absolute
>
> (add-indirect-root store absolute))
>
> +(define-public (list-installed regexp profiles)
> + (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> + (manifest (concatenate-manifests
> + (map profile-manifest profiles)))
> + (installed (manifest-entries manifest)))
> + (leave-on-EPIPE
> + (let ((rows (filter-map
> + (match-lambda
> + (($ <manifest-entry> name version output path _)
> + (and (regexp-exec regexp name)
> + (list name (or version "?") output path))))
> + installed)))
> + ;; Show most recently installed packages last.
> + (reverse rows)))))
> +
>
> ;;;
> ;;; Queries and actions.
> @@ -824,19 +840,7 @@ (define (diff-profiles profile numbers)
> #t)
>
> (('list-installed regexp)
> - (let* ((regexp (and regexp (make-regexp* regexp regexp/icase)))
> - (manifest (concatenate-manifests
> - (map profile-manifest profiles)))
> - (installed (manifest-entries manifest)))
> - (leave-on-EPIPE
> - (let ((rows (filter-map
> - (match-lambda
> - (($ <manifest-entry> name version output path _)
> - (and (regexp-exec regexp name)
> - (list name (or version "?") output path))))
> - installed)))
> - ;; Show most recently installed packages last.
> - (pretty-print-table (reverse rows)))))
> + (pretty-print-table (list-installed regexp profiles))
> #t)
>
> (('list-available regexp)

-I --list-installed works great, thank you. Just a thought for future:
Maybe it would be useful to have another option to list all the packages
in profile, including propagated.

--
Best regards,
Andrew Tropin
-----BEGIN PGP SIGNATURE-----

iQIzBAEBCgAdFiEEKEGaxlA4dEDH6S/6IgjSCVjB3rAFAmLstLYACgkQIgjSCVjB
3rBnGw/6AyqaI/udt2cu9CYmo0f1WMs4RF0e1tGY/t1OnP0fIE2x9vP+b+7c/OHv
Nt+bCAWJw4DSoPXNYdezxYUFaCfbx8i4/cOt0e2s607Q4FcpZ4Y3zbUIhjURfUsV
6iYrnj0HeycGxrZHu5v9qwKfCubRJsCaCumYkSzhmfYY237Igx+OlHFXTSitu4/Z
zhnsqSNJERG5tCXJtB2N98iRPhJOm94g58xyNI4LGwUtvKJv15bGpU+MZitEQ7z+
5EaXLeTco6/CVfcUvBQ3+nCbNi9AlirjT7gLFyjjYrDgClBzUsNq9FEYQUnE+LlD
Xm4cz3budmoFZZVEKzYCSl1k1Tn5XFtgdR2RUghHBWi6sXQJecDUifOm1JM0Z6yo
zg+0zhtC9K97vpV+g04BkTcAxAIfzDTGgVrgi+YPEaUUu+sPL+fUaZ0IH9PSUNH0
DE81cwhSIM0UZ8Mn5yK+6S5BDiXBRpuUs0SVGMVqmnTORZqYpvDCfOB7QhXEwOEu
mKD08W0dsp3HupnlnO27+hpBlvIJ8zSytxgZhQh0UOdfLvzoy4jdFjcsF5LvWUzi
5kiEA42OGxWZFfYwiaydFdnLhdADktw6mnJcUD1WtbAKxXM1bvQSJrw3Wc+t46qe
I47qnRYIRkKO7yy+pgt7JoCeCntTyPYlVsG8rIcGVMqUuej1pIc=
=mGZe
-----END PGP SIGNATURE-----

A
A
Antero Mejr wrote on 7 Aug 2022 01:02
(name . Andrew Tropin)(address . andrew@trop.in)
87o7wwhpw3.fsf@mailbox.org
Andrew Tropin <andrew@trop.in> writes:

Toggle quote (4 lines)
> -I --list-installed works great, thank you. Just a thought for future:
> Maybe it would be useful to have another option to list all the packages
> in profile, including propagated.

Not sure I fully understand.
For example, if a profile's package "foo" has input "bar" and
propagated-input "baz":
- would you want both "bar" and "baz" listed?
- would you want to know the relationships between the packages?

Could this could be done with 'guix graph' by adding an ascii backend,
like this:

guix graph --backend=ascii -t references $(readlink -f \
~/.guix-home/profile)

to get this:

+------------+-------+-----------------+------+
| package |parent |type |etc...|
+------------+-------+-----------------+------+
| foo |profile|parent | |
+------------+-------+-----------------+------+
| bar |foo |input | |
+------------+-------+-----------------+------+
| baz |foo |propagated-input | |
+------------+-------+-----------------+------+

or this:

foo
??? bar (input)
??? baz (propagated-input)

Maybe a 'guix sbom' subcommand, for "Software Bill of Materials", would
be better for displaying lists like this. Having an SBOM exporter would
make Guix great for regulated applications like medical device software.
?