Subject: [PATCH] refresh: Add '--installed' option.

From: Xinglu Chen <[email-masked]>
Date: Mon, 15 Mar 2021 16:45:54 +0100

This lets the user to only check for updates for packages installed in the
current profile.

If the user is using the imperative way to install packages, or uses
multiple manifests, this is a quick way to check for updates for the
installed packages.

* guix/scripts/refresh.scm (%options): Add '--installed' option.
* guix.texi (Invoking guix refresh): Document it.
---
 doc/guix.texi            |  5 +++++
 guix/scripts/refresh.scm | 14 +++++++++++++-
 2 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index 3e7ffc81bc..c778a877d8 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -11657,6 +11657,11 @@
 Select all the packages from the manifest in @var{file}.  This is useful to
 check if any packages of the user manifest can be updated.
 
+@item --installed
+@itemx -i
+Select all the packages installed in the current profile.  This is
+useful to check if any of the packages the user is using can be updated.
+
 @item --type=@var{updater}
 @itemx -t @var{updater}
 Select only packages handled by @var{updater} (may be a comma-separated
diff --git a/guix/scripts/refresh.scm b/guix/scripts/refresh.scm
index fb6c52a567..c1c672dc0b 100644
--- a/guix/scripts/refresh.scm
+++ b/guix/scripts/refresh.scm
@@ -86,6 +86,9 @@
         (option '(#\m "manifest") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'manifest arg result)))
+        (option '(#\i "installed") #f #f
+                (lambda (opt name arg result)
+                  (alist-cons 'installed #t result)))
         (option '(#\e "expression") #t #f
                 (lambda (opt name arg result)
                   (alist-cons 'expression arg result)))
@@ -156,6 +159,9 @@ specified with `--select'.\n"))
   (display (G_ "
   -m, --manifest=FILE    select all the packages from the manifest in FILE"))
   (display (G_ "
+  -i  --installed        select all the packages installed in the current
+                         profile"))
+  (display (G_ "
   -t, --type=UPDATER,... restrict to updates from the specified updaters
                          (e.g., 'gnu')"))
   (display (G_ "
@@ -253,7 +259,13 @@ update would trigger a complete rebuild."
 
   (define packages
     (match (assoc-ref opts 'manifest)
-      (#f args-packages)
+      (#f (if (assoc-ref opts 'installed)
+              ;; All packages installed in current profile
+              (manifest->packages
+               (match (manifest->code (profile-manifest %current-profile))
+                 (('begin expr) (eval expr
+                                      (make-user-module '((gnu packages)))))))
+              args-packages))
       ((? string? file) (packages-from-manifest file))))
 
   (if (assoc-ref opts 'recursive?)

base-commit: 266d55dc3080475544bf45e72359c9b9bbcecd53
-- 
2.30.2