diff mbox series

[bug#47163] refresh: Add '--installed' option.

Message ID bbf925b124979bf1203f3619d06dc51948b0f81e.1615822877.git.public@yoctocell.xyz
State Accepted
Headers show
Series [bug#47163] refresh: Add '--installed' option. | expand

Checks

Context Check Description
cbaines/submitting builds success
cbaines/comparison success View comparision
cbaines/git branch success View Git branch
cbaines/applying patch success View Laminar job
cbaines/issue success View issue

Commit Message

Xinglu Chen March 15, 2021, 3:45 p.m. UTC
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(-)


base-commit: 266d55dc3080475544bf45e72359c9b9bbcecd53

Comments

Ludovic Courtès March 15, 2021, 8:38 p.m. UTC | #1
Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

> 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.

I sometimes run:

  guix refresh $(guix package -I | cut -f1)

I’m not sure an extra ‘guix refresh’ option is warranted.  WDYT?

Thanks,
Ludo’.
Xinglu Chen March 15, 2021, 9:14 p.m. UTC | #2
On Mon, Mar 15 2021, Ludovic Courtès wrote:

> Hi,
>
> Xinglu Chen <public@yoctocell.xyz> skribis:
>
>> 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.
>
> I sometimes run:
>
>   guix refresh $(guix package -I | cut -f1)
>
> I’m not sure an extra ‘guix refresh’ option is warranted.  WDYT?

That's cool, I think your solution would suffice.  Maybe we could add it
to the manual or cookbok?
Ludovic Courtès March 16, 2021, 9:08 a.m. UTC | #3
Hi,

Xinglu Chen <public@yoctocell.xyz> skribis:

> On Mon, Mar 15 2021, Ludovic Courtès wrote:
>
>> Hi,
>>
>> Xinglu Chen <public@yoctocell.xyz> skribis:
>>
>>> 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.
>>
>> I sometimes run:
>>
>>   guix refresh $(guix package -I | cut -f1)
>>
>> I’m not sure an extra ‘guix refresh’ option is warranted.  WDYT?
>
> That's cool, I think your solution would suffice.  Maybe we could add it
> to the manual or cookbok?

That’s a good idea.  Do you want to propose a short section on this?

You may also like the new ‘--with-latest’ package transformation
option.  :-)

Thanks,
Ludo’.
Léo Le Bouter March 16, 2021, 9:16 a.m. UTC | #4
On Tue, 2021-03-16 at 10:08 +0100, Ludovic Courtès wrote:
> Hi,
> 
> Xinglu Chen <public@yoctocell.xyz> skribis:
> 
> > On Mon, Mar 15 2021, Ludovic Courtès wrote:
> > 
> > > Hi,
> > > 
> > > Xinglu Chen <public@yoctocell.xyz> skribis:
> > > 
> > > > 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.
> > > 
> > > I sometimes run:
> > > 
> > >   guix refresh $(guix package -I | cut -f1)
> > > 
> > > I’m not sure an extra ‘guix refresh’ option is warranted.  WDYT?
> > 
> > That's cool, I think your solution would suffice.  Maybe we could
> > add it
> > to the manual or cookbok?
> 
> That’s a good idea.  Do you want to propose a short section on this?
> 
> You may also like the new ‘--with-latest’ package transformation
> option.  :-)
> 
> Thanks,
> Ludo’.

I would also really like such option for 'lint' and 'refresh' that can
take an operating-system definition so I can ensure a certain set of
packages are up to some standards and help me focus my efforts on my or
some fellow's configuration (especially w.r.t. security), rather than
randomly trying to maintain *everything* in the GNU Guix repo which is
quite exhausting and large work to take on. Starting from a place of
actual need for myself and some fellow's configurations looks like a
more achieveable goal mid-term.
Simon Tournier March 16, 2021, 12:58 p.m. UTC | #5
Hi Léo,

On Tue, 16 Mar 2021 at 10:18, Léo Le Bouter via Guix-patches via
<guix-patches@gnu.org> wrote:
> I would also really like such option for 'lint' and 'refresh' that can
> take an operating-system definition so I can ensure a certain set of
> packages are up to some standards and help me focus my efforts on my or
> some fellow's configuration (especially w.r.t. security), rather than
> randomly trying to maintain *everything* in the GNU Guix repo which is
> quite exhausting and large work to take on. Starting from a place of
> actual need for myself and some fellow's configurations looks like a
> more achieveable goal mid-term.

Adding the manifest option to "guix lint", is it not enough?  I do not
know how many packages you have in your operating-system definition
but from my understanding your user-wide packages should be in
manifest.scm files, and you could also maintain a manifest.scm file
for your packages system-wide.  Anyway.

Here an example with an hard-coded path, saved in /tmp/manifest-from-os.scm:

--8<---------------cut here---------------start------------->8---
(use-modules
 (gnu system)
 (guix profiles))

(define os
  (load "/home/simon/src/guix/guix/gnu/system/examples/bare-bones.tmpl"))

(define pkgs (operating-system-packages os))

(packages->manifest pkgs)
--8<---------------cut here---------------end--------------->8---

Then "guix refresh -m /tmp/manifest-from-os.scm" should do the job.
Well, it is an example, the point is simply to show that an option is
not necessary, IMHO.  However, a robust script could be in etc/ with
some other tools and with a line in the manual.  Maybe. :-)
It seems better to keep separated what operates on packages and what
operates on system.


Cheers,
simon
Léo Le Bouter March 16, 2021, 1:10 p.m. UTC | #6
On Tue, 2021-03-16 at 13:58 +0100, zimoun wrote:
> Adding the manifest option to "guix lint", is it not enough?  I do
> not
> know how many packages you have in your operating-system definition
> but from my understanding your user-wide packages should be in
> manifest.scm files, and you could also maintain a manifest.scm file
> for your packages system-wide.  Anyway.
> 
> Here an example with an hard-coded path, saved in /tmp/manifest-from-
> os.scm:
> 
> --8<---------------cut here---------------start------------->8---
> (use-modules
>  (gnu system)
>  (guix profiles))
> 
> (define os
>   (load "/home/simon/src/guix/guix/gnu/system/examples/bare-
> bones.tmpl"))
> 
> (define pkgs (operating-system-packages os))
> 
> (packages->manifest pkgs)
> --8<---------------cut here---------------end--------------->8---
> 
> Then "guix refresh -m /tmp/manifest-from-os.scm" should do the job.
> Well, it is an example, the point is simply to show that an option is
> not necessary, IMHO.  However, a robust script could be in etc/ with
> some other tools and with a line in the manual.  Maybe. :-)
> It seems better to keep separated what operates on packages and what
> operates on system.
> 
> 
> Cheers,
> simon

You are right that looks great!
Xinglu Chen March 16, 2021, 4:05 p.m. UTC | #7
On Tue, Mar 16 2021, Ludovic Courtès wrote:

>>> I sometimes run:
>>>
>>>   guix refresh $(guix package -I | cut -f1)
>>>
>>> I’m not sure an extra ‘guix refresh’ option is warranted.  WDYT?
>>
>> That's cool, I think your solution would suffice.  Maybe we could add it
>> to the manual or cookbok?
>
> That’s a good idea.  Do you want to propose a short section on this?

Sure, I will send a followup patch to this.
Xinglu Chen March 16, 2021, 4:44 p.m. UTC | #8
On Tue, Mar 16 2021, Ludovic Courtès wrote:

> You may also like the new ‘--with-latest’ package transformation
> option.  :-)

I really like package transformations but is there a way to use specify
them with Guile so I can use them with `guix home`[1] or in manifests?

Ccing guix-devel

[1]: https://yhetil.org/guix-devel/878s6u2pco.fsf@trop.in
Simon Tournier March 16, 2021, 5:23 p.m. UTC | #9
Hi,

On Tue, 16 Mar 2021 at 17:46, Xinglu Chen <public@yoctocell.xyz> wrote:
> On Tue, Mar 16 2021, Ludovic Courtès wrote:
>
> > You may also like the new ‘--with-latest’ package transformation
> > option.  :-)
>
> I really like package transformations but is there a way to use specify
> them with Guile so I can use them with `guix home`[1] or in manifests?

There is several ways to have package transformations at the manifest
level.  One is:

--8<---------------cut here---------------start------------->8---
(use-modules (guix transformations))

(define transform1
  (options->transformation
    '((with-c-toolchain . "hello=gcc-toolchain@8"))))

(packages->manifest
  (list (transform1 (specification->package "hello"))))
--8<---------------cut here---------------end--------------->8---


HTH,
simon
Xinglu Chen March 16, 2021, 6:35 p.m. UTC | #10
On Tue, Mar 16 2021, zimoun wrote:

>> I really like package transformations but is there a way to use specify
>> them with Guile so I can use them with `guix home`[1] or in manifests?
>
> There is several ways to have package transformations at the manifest
> level.  One is:
>
> --8<---------------cut here---------------start------------->8---
> (use-modules (guix transformations))
>
> (define transform1
>   (options->transformation
>     '((with-c-toolchain . "hello=gcc-toolchain@8"))))
>
> (packages->manifest
>   (list (transform1 (specification->package "hello"))))
> --8<---------------cut here---------------end--------------->8---

Cool, thanks for the help.
Ludovic Courtès March 17, 2021, 5:17 p.m. UTC | #11
Hi,

zimoun <zimon.toutoune@gmail.com> skribis:

> There is several ways to have package transformations at the manifest
> level.  One is:
>
> (use-modules (guix transformations))
>
> (define transform1
>   (options->transformation
>     '((with-c-toolchain . "hello=gcc-toolchain@8"))))
>
> (packages->manifest
>   (list (transform1 (specification->package "hello"))))

On this topic, do not miss this section of the fine manual:
<https://guix.gnu.org/manual/en/html_node/Defining-Package-Variants.html>.
:-)

Ludo’.
Xinglu Chen March 26, 2021, 5:18 p.m. UTC | #12
The v2 patch has been applied.  Closing.
diff mbox series

Patch

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?)