From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id SHp4C4H8zWJrUgEAbAwnHQ (envelope-from ) for ; Wed, 13 Jul 2022 00:58:09 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id iHBqC4H8zWLchwAA9RJhRA (envelope-from ) for ; Wed, 13 Jul 2022 00:58:09 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 7315F279E9 for ; Wed, 13 Jul 2022 00:58:08 +0200 (CEST) Received: from localhost ([::1]:52372 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oBOpT-0004vI-9y for larch@yhetil.org; Tue, 12 Jul 2022 18:58:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:52724) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oBOic-0003ch-VQ for guix-patches@gnu.org; Tue, 12 Jul 2022 18:51:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:49956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oBOic-00076l-Ll for guix-patches@gnu.org; Tue, 12 Jul 2022 18:51:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oBOic-0003Um-EL for guix-patches@gnu.org; Tue, 12 Jul 2022 18:51:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#56428] [PATCH v3] home: Add -I, --list-installed option. References: <20220706191311.14662-1-antero@mailbox.org> In-Reply-To: <20220706191311.14662-1-antero@mailbox.org> Resent-From: Antero Mejr Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 12 Jul 2022 22:51:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 56428 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 56428@debbugs.gnu.org Cc: andrew@trop.in Received: via spool by 56428-submit@debbugs.gnu.org id=B56428.165766622813389 (code B ref 56428); Tue, 12 Jul 2022 22:51:02 +0000 Received: (at 56428) by debbugs.gnu.org; 12 Jul 2022 22:50:28 +0000 Received: from localhost ([127.0.0.1]:43853 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBOi0-0003Tl-Dk for submit@debbugs.gnu.org; Tue, 12 Jul 2022 18:50:28 -0400 Received: from mout-p-102.mailbox.org ([80.241.56.152]:38800) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oBOhw-0003TK-Sw for 56428@debbugs.gnu.org; Tue, 12 Jul 2022 18:50:23 -0400 Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-102.mailbox.org (Postfix) with ESMTPS id 4LjGDN4tQgz9sSh; Wed, 13 Jul 2022 00:50:12 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=mailbox.org; s=mail20150812; t=1657666212; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=Epvhqh2AIMGuqhSBxYWYeMTNMkdDM9DyJfCZ9xV88cY=; b=l8q4XY2SheaBesB4aqw6AwYLP032jFwenIc4svovWC/h39GgIn59g/Jr8WOQn4kGJPcqiV ObHyr5kdvTz6Dinm8g1li6WqTvgeiTlo4Uq7O/BwKC1X24lNuel2Bqjm/858I8n32ze8l9 DAzOsrtVMID20JFncaAQT4JG7VfSUVkRVFfP+YSAiWOE/tA1Rn+DxhOMlcB2VLqqSUwoxW 2ikpZbXgEljJ0fMniZIhK4rxuB/hsbZJjUf/uQ+gIeDKlQ258gEMup3O5AMbB01yq08WaT 2Me11huNOlcziWYgjnWlWuFZbQpI9u+w9Mwcx5KiiAS5dFJd3+Tk3dkXckbqZQ== Date: Tue, 12 Jul 2022 22:50:07 +0000 Message-Id: <20220712225007.23875-1-antero@mailbox.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-MBO-RS-META: spfd9huqj7s453r1ndnmsca75mzdgwxe X-MBO-RS-ID: c845409391d707b8a37 X-Rspamd-Queue-Id: 4LjGDN4tQgz9sSh X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" Reply-to: Antero Mejr X-ACL-Warn: , Antero Mejr via Guix-patches From: Antero Mejr via Guix-patches via X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1657666688; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=Epvhqh2AIMGuqhSBxYWYeMTNMkdDM9DyJfCZ9xV88cY=; b=DooL+jtzWwbzdl5VHfBFUdQ2RzCZnCyh3GJAHEXjoqOWqqB6Q8tYlWOahSnw5SvjPGVtgu r7ROMIz/1vQPj/NhtnGsgVgNkb0JJJK2eXj2YGSkKNshb8/Z/hVI/MHMVSLmEednuzCh4b 0svy+FlMyih6vS+BKPDTEz9mY1j8fRPZmwzvbT9LmvSsF2nriy40ytZsvaWna1byfTBRlY /hK2nXyh2ctEn3IZFcSBlvU+bluyTrRQ0J/ICr2KvpbMQrVjggUGH27InSl1KTHhm1UbzD e3m4pZUfsMjl0HaTm+CeUj0k/QEUEUdc8Q4AJKRu/jvx8/Qjhf0E8K5y/bXfbQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1657666688; a=rsa-sha256; cv=none; b=Hp9W2EduyCZSWPMggvvD+t3BfQwgvHnJNvqQoRtuplyh9g/r20YlFnmZv21GKjWvloWZhH GiNYak8IdQD7iV6gCLUhf4HNnb55EBv4frb17s3bExE2xDDUPYStLpWeQrsxVxz/lEYb8E co9YZfbNRgfMa0jWrdymG/Pn2bKl9k6E7Or9wD+R/c78wGxrG3nHh3ptd/Og80M66OfoVW iYjx03/fMqLtyoyMunDTlK+kiREIqq3Smim5L/TuurnXx3flYunrHD0ye6xIvDt9jvfuUF PWyhQIIvUYJ/cpolUr33JU96zoISOiYO0ROZ8UVV7koj6ciXznuvBVBeYBcDsA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mailbox.org header.s=mail20150812 header.b=l8q4XY2S; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -3.65 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=mailbox.org header.s=mail20150812 header.b=l8q4XY2S; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 7315F279E9 X-Spam-Score: -3.65 X-Migadu-Scanner: scn0.migadu.com X-TUID: 8Uo28vUuylEL * 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 ;;; Copyright © 2021 Oleg Pykhalov ;;; Copyright © 2022 Ludovic Courtès +;;; Copyright © 2022 Antero Mejr ;;; ;;; 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 ;;; Copyright © 2018 Steve Sprang ;;; Copyright © 2022 Josselin Poiret +;;; Copyright © 2022 Antero Mejr ;;; ;;; 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 + (($ 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 - (($ 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