GNU bug report logs - #75414
[PATCH 0/2] Add roll-back action to guix deploy

Previous Next

Package: guix-patches;

Reported by: Arun Isaac <arunisaac <at> systemreboot.net>

Date: Tue, 7 Jan 2025 00:19:02 UTC

Severity: normal

Tags: patch

Done: Arun Isaac <arunisaac <at> systemreboot.net>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 75414 in the body.
You can then email your comments to 75414 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Tue, 07 Jan 2025 00:19:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Arun Isaac <arunisaac <at> systemreboot.net>:
New bug report received and forwarded. Copy sent to guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org. (Tue, 07 Jan 2025 00:19:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: guix-patches <at> gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [PATCH 0/2] Add roll-back action to guix deploy
Date: Tue,  7 Jan 2025 00:18:08 +0000
Hi,

I implement a roll-back action for guix deploy. This is convenient to roll
back all machines in a `guix deploy' configuration.

By the by, PATCH 1 fixes a bug necessary to make this work.

Regards,
Arun

Arun Isaac (2):
  machine: ssh: Return monadic value from roll-back-managed-host.
  deploy: Add roll-back action.

 doc/guix.texi           |  7 ++++
 gnu/machine/ssh.scm     |  6 ++-
 guix/scripts/deploy.scm | 90 +++++++++++++++++++++++++++++++++--------
 3 files changed, 84 insertions(+), 19 deletions(-)


base-commit: 67a535351f8678969e412e8dba9197a883b524d0
-- 
2.47.1





Information forwarded to arunisaac <at> systemreboot.net, guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Tue, 07 Jan 2025 00:29:02 GMT) Full text and rfc822 format available.

Message #8 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 75414 <at> debbugs.gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [PATCH 1/2] machine: ssh: Return monadic value from
 roll-back-managed-host.
Date: Tue,  7 Jan 2025 00:28:30 +0000
Previously, <unspecified> would be returned. That was a bug. Monadic
procedures must always return monadic values.

* gnu/machine/ssh.scm (roll-back-managed-host): Return monadic value.

Change-Id: I3db2879dbfbcab5e9d251fa5ed02c8653adbeafb
---
 gnu/machine/ssh.scm | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm
index bc4289ef7d..73d5dc513e 100644
--- a/gnu/machine/ssh.scm
+++ b/gnu/machine/ssh.scm
@@ -2,6 +2,7 @@
 ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays <at> sdf.org>
 ;;; Copyright © 2020-2024 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2024 Ricardo <rekado <at> elephly.net>
+;;; Copyright © 2025 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -621,8 +622,9 @@ (define (roll-back-managed-host machine)
                                   #:store-directory-prefix store-dir
                                   #:old-entries old-entries)))
                        (remote-result (machine-remote-eval machine remote-exp)))
-    (when (eqv? 'error remote-result)
-      (raise roll-back-failure))))
+    (if (eqv? 'error remote-result)
+        (raise roll-back-failure)
+        (return remote-result))))
 
 
 ;;;
-- 
2.47.1





Information forwarded to arunisaac <at> systemreboot.net, guix <at> cbaines.net, dev <at> jpoiret.xyz, ludo <at> gnu.org, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Tue, 07 Jan 2025 00:30:02 GMT) Full text and rfc822 format available.

Message #11 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 75414 <at> debbugs.gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [PATCH 2/2] deploy: Add roll-back action.
Date: Tue,  7 Jan 2025 00:28:31 +0000
* guix/scripts/deploy.scm (guix-deploy): Add the roll-back action.
(show-what-to-deploy): Optionally support the roll-back action.
(roll-back-machine*): New function.
(show-help): Document the roll-back action.
* doc/guix.texi (Invoking guix deploy): Document the roll-back action.

Change-Id: Ic5084f287aefb2d1d28380ca4ba1c6971cb913e7
---
 doc/guix.texi           |  7 ++++
 guix/scripts/deploy.scm | 90 +++++++++++++++++++++++++++++++++--------
 2 files changed, 80 insertions(+), 17 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index b2bcab8791..c08c2c70ef 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -44354,6 +44354,13 @@ Invoking guix deploy
 The @command{guix deploy -x} command returns zero if and only if the
 command succeeded on all the machines.
 
+You may also wish to roll back configurations on machines to a previous
+generation.  You can do that using
+
+@example
+guix deploy roll-back @var{file}
+@end example
+
 @c FIXME/TODO: Separate the API doc from the CLI doc.
 
 Below are the data types you need to know about when writing a
diff --git a/guix/scripts/deploy.scm b/guix/scripts/deploy.scm
index 941ee199f0..3f1b8b27a7 100644
--- a/guix/scripts/deploy.scm
+++ b/guix/scripts/deploy.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays <at> sdf.org>
 ;;; Copyright © 2020-2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2024 Richard Sent <richard <at> freakingpenguin.com>
+;;; Copyright © 2025 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -50,8 +51,13 @@ (define-module (guix scripts deploy)
 
 
 (define (show-help)
-  (display (G_ "Usage: guix deploy [OPTION] FILE...
-Perform the deployment specified by FILE.\n"))
+  (display (G_ "Usage: guix deploy [OPTION] [ACTION] FILE...
+Perform the deployment specified by FILE.
+Optionally, perform ACTION.\n\n"))
+  (display (G_ "The valid values for ACTION are:\n"))
+  (newline)
+  (display (G_ "\
+   roll-back        switch to the previous operating system configuration\n"))
   (show-build-options-help)
   (newline)
   (display (G_ "
@@ -118,20 +124,32 @@ (define (load-source-file file)
                                            environment-modules))))
     (load* file module)))
 
-(define* (show-what-to-deploy machines #:key (dry-run? #f))
-  "Show the list of machines to deploy, MACHINES."
+(define* (show-what-to-deploy machines #:key (dry-run? #f) (roll-back? #f))
+  "Show the list of machines in MACHINES to deploy or roll back."
   (let ((count (length machines)))
     (if dry-run?
-        (format (current-error-port)
-                (N_ "The following ~d machine would be deployed:~%"
-                    "The following ~d machines would be deployed:~%"
+        (if roll-back?
+            (format (current-error-port)
+                (N_ "The following ~d machine would be rolled back:~%"
+                    "The following ~d machines would be rolled back:~%"
                     count)
                 count)
-        (format (current-error-port)
-                (N_ "The following ~d machine will be deployed:~%"
-                    "The following ~d machines will be deployed:~%"
+            (format (current-error-port)
+                    (N_ "The following ~d machine would be deployed:~%"
+                        "The following ~d machines would be deployed:~%"
+                        count)
+                    count))
+        (if roll-back?
+            (format (current-error-port)
+                    (N_ "The following ~d machine will be rolled back:~%"
+                        "The following ~d machines will be rolled back:~%"
+                        count)
                     count)
-                count))
+            (format (current-error-port)
+                    (N_ "The following ~d machine will be deployed:~%"
+                        "The following ~d machines will be deployed:~%"
+                        count)
+                    count)))
     (display (indented-string
               (fill-paragraph (string-join (map machine-display-name machines)
                                            ", ")
@@ -175,6 +193,35 @@ (define (deploy-machine* store machine)
     (info (G_ "successfully deployed ~a~%")
           (machine-display-name machine))))
 
+(define (roll-back-machine* store machine)
+  "Roll back MACHINE, taking care of error handling."
+  (info (G_ "rolling back ~a...~%")
+        (machine-display-name machine))
+
+  (guard* (c
+           ;; On Guile 3.0, exceptions such as 'unbound-variable' are compound
+           ;; and include a '&message'.  However, that message only contains
+           ;; the format string.  Thus, special-case it here to avoid
+           ;; displaying a bare format string.
+           (((exception-predicate &exception-with-kind-and-args) c)
+            (raise c))
+
+           ((message-condition? c)
+            (leave (G_ "failed to roll back ~a: ~a~%")
+                   (machine-display-name machine)
+                   (condition-message c)))
+           ((formatted-message? c)
+            (leave (G_ "failed to roll back ~a: ~a~%")
+                   (machine-display-name machine)
+                   (apply format #f
+                          (gettext (formatted-message-string c)
+                                   %gettext-domain)
+                          (formatted-message-arguments c)))))
+      (run-with-store store (roll-back-machine machine)))
+
+  (info (G_ "successfully rolled back ~a~%")
+        (machine-display-name machine)))
+
 (define (invoke-command store machine command)
   "Invoke COMMAND, a list of strings, on MACHINE.  Display its output (if any)
 and its error code if it's non-zero.  Return true if COMMAND succeeded, false
@@ -291,9 +338,18 @@ (define-command (guix-deploy . args)
                             machines)))
                     (_
                      (leave (G_ "'-x' specified but no command given~%"))))
-                  (begin
-                    (show-what-to-deploy machines #:dry-run? dry-run?)
-                    (unless dry-run?
-                      (map/accumulate-builds store
-                                             (cut deploy-machine* store <>)
-                                             machines)))))))))))
+                  (match args
+                    (("roll-back" _ ...)
+                     (show-what-to-deploy machines
+                                          #:dry-run? dry-run?
+                                          #:roll-back? #t)
+                     (unless dry-run?
+                       (map/accumulate-builds store
+                                              (cut roll-back-machine* store <>)
+                                              machines)))
+                    (_
+                     (show-what-to-deploy machines #:dry-run? dry-run?)
+                     (unless dry-run?
+                       (map/accumulate-builds store
+                                              (cut deploy-machine* store <>)
+                                              machines))))))))))))
-- 
2.47.1





Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Sun, 19 Jan 2025 22:01:01 GMT) Full text and rfc822 format available.

Message #14 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Arun Isaac <arunisaac <at> systemreboot.net>
Cc: 75414 <at> debbugs.gnu.org
Subject: Re: [bug#75414] [PATCH 1/2] machine: ssh: Return monadic value from
 roll-back-managed-host.
Date: Sun, 19 Jan 2025 23:00:06 +0100
Howdy Arun,

Arun Isaac <arunisaac <at> systemreboot.net> skribis:

> Previously, <unspecified> would be returned. That was a bug. Monadic
> procedures must always return monadic values.
>
> * gnu/machine/ssh.scm (roll-back-managed-host): Return monadic value.
>
> Change-Id: I3db2879dbfbcab5e9d251fa5ed02c8653adbeafb

LGTM!




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Sun, 19 Jan 2025 22:08:02 GMT) Full text and rfc822 format available.

Message #17 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Arun Isaac <arunisaac <at> systemreboot.net>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>,
 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Tobias Geerinckx-Rice <me <at> tobias.gr>, 75414 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Sun, 19 Jan 2025 23:07:02 +0100
Arun Isaac <arunisaac <at> systemreboot.net> skribis:

> * guix/scripts/deploy.scm (guix-deploy): Add the roll-back action.
> (show-what-to-deploy): Optionally support the roll-back action.
> (roll-back-machine*): New function.
> (show-help): Document the roll-back action.
> * doc/guix.texi (Invoking guix deploy): Document the roll-back action.
>
> Change-Id: Ic5084f287aefb2d1d28380ca4ba1c6971cb913e7

[...]

> +You may also wish to roll back configurations on machines to a previous
> +generation.  You can do that using
                                     ^
I would add a colon.

>  (define (show-help)
> -  (display (G_ "Usage: guix deploy [OPTION] FILE...
> -Perform the deployment specified by FILE.\n"))
> +  (display (G_ "Usage: guix deploy [OPTION] [ACTION] FILE...

Hmm I would rather have ‘guix deploy --roll-back’, although that’d be
different from ‘guix system’, primarily because I don’t see what other
actions we could have, and in particular how we’d name the default
action (‘guix deploy deploy’? ‘guix deploy really’? ‘guix deploy
please’?).

Tough issue!

But note that if we make it a ‘--roll-back’ option, we can easily change
our mind later and make it an action, whereas the converse would be more
difficult.

Apart from that it looks great to me.

Thank you!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Fri, 24 Jan 2025 15:47:01 GMT) Full text and rfc822 format available.

Message #20 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Evgeny Pisemsky <mail <at> pisemsky.site>
To: 75414 <at> debbugs.gnu.org
Cc: ludo <at> gnu.org, arunisaac <at> systemreboot.net
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Fri, 24 Jan 2025 18:45:40 +0300
> Hmm I would rather have ‘guix deploy --roll-back’, although that’d be
> different from ‘guix system’, primarily because I don’t see what other
> actions we could have, and in particular how we’d name the default
> action (‘guix deploy deploy’? ‘guix deploy really’? ‘guix deploy
> please’?).

The default action is =system reconfigure= on remote machine(s).

This patch implements =system roll-back= on remote machine(s)

I really miss =system delete-generations= on remote machine(s), which
understands =build-locally?= and does not trigger a lot of downloads
just to update grub, which happens when I run it directly on machine.

So one can see the tendency here - reimplementing system actions for
deploy. Since machine definition includes system definition, how bad
is the idea to just make deploy a feature of specific system actions?
Even in the manual they follow each other in the same system section.

On the other hand, it is clear that all system commands work with a
single operating system, and adding deploy may be conceptually wrong.

But if it is not, I think about an UI analogous to guix container:

#+begin_example
guix system reconfigure --machine servers.scm
guix machine exec servers.scm -- herd restart something
#+end_example

The first command actually works with systems on remote machine(s).
The second one is specific to machine(s), without affecting systems.

To me this is more flexible than one command that does everything. I
can imagine a situation when I just need to run some command on all
machines without reconfiguring them, which is currently impossible.

Of course, this is not an objection to the patch, just a brain dump.




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Fri, 24 Jan 2025 23:14:02 GMT) Full text and rfc822 format available.

Message #23 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Ludovic Courtès <ludo <at> gnu.org>
To: Evgeny Pisemsky <mail <at> pisemsky.site>
Cc: arunisaac <at> systemreboot.net, 75414 <at> debbugs.gnu.org
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Sat, 25 Jan 2025 00:13:34 +0100
Hi,

Evgeny Pisemsky <mail <at> pisemsky.site> skribis:

>> Hmm I would rather have ‘guix deploy --roll-back’, although that’d be
>> different from ‘guix system’, primarily because I don’t see what other
>> actions we could have, and in particular how we’d name the default
>> action (‘guix deploy deploy’? ‘guix deploy really’? ‘guix deploy
>> please’?).
>
> The default action is =system reconfigure= on remote machine(s).
>
> This patch implements =system roll-back= on remote machine(s)
>
> I really miss =system delete-generations= on remote machine(s), which
> understands =build-locally?= and does not trigger a lot of downloads
> just to update grub, which happens when I run it directly on machine.

Yes, I understand.  My question is more about how we’d name that default
action.

And also noting that this is a broader change than just adding support
for roll-back.

> #+begin_example
> guix system reconfigure --machine servers.scm
> guix machine exec servers.scm -- herd restart something
> #+end_example

‘guix machine’ might actually be a better name than ‘guix deploy’.

> To me this is more flexible than one command that does everything. I
> can imagine a situation when I just need to run some command on all
> machines without reconfiguring them, which is currently impossible.

It’s possible:

  guix deploy machines.scm -x -- herd restart something

But yes, it could very well be called ‘guix machine exec …’.

Anyway, we’re going beyond what this patch series intended to address!

Ludo’.




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Fri, 31 Jan 2025 19:02:01 GMT) Full text and rfc822 format available.

Message #26 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Evgeny Pisemsky <mail <at> pisemsky.site>
To: Ludovic Courtès <ludo <at> gnu.org>
Cc: arunisaac <at> systemreboot.net, 75414 <at> debbugs.gnu.org
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Fri, 31 Jan 2025 22:01:00 +0300
Ludovic Courtès <ludo <at> gnu.org> writes:

>> To me this is more flexible than one command that does everything. I
>> can imagine a situation when I just need to run some command on all
>> machines without reconfiguring them, which is currently impossible.
>
> It’s possible:
>
>   guix deploy machines.scm -x -- herd restart something

This is funny and sad at the same time, because I thought that this
option works like some kind of post-deploy hook, not separate action.

The reasons are how documentation puts it and how those commands look:
the verb "deploy" just make one think it always deploys. Confusing UI.

If my opinion matters, for the current =guix deploy= interface keep
adding actions as options, explicitly stating them as separate actions
in documentation. If/when the decision to introduce =guix machine= UI
will be made, it would be better to implement actual actions there -
like in the transition from =guix environment= to =guix shell=.




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Sat, 01 Feb 2025 22:35:02 GMT) Full text and rfc822 format available.

Message #29 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: Evgeny Pisemsky <mail <at> pisemsky.site>, Ludovic Courtès
 <ludo <at> gnu.org>
Cc: 75414 <at> debbugs.gnu.org
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Sat, 01 Feb 2025 22:33:53 +0000
Hi all,

Thanks everyone for the feedback!

> If my opinion matters, for the current =guix deploy= interface keep
> adding actions as options, explicitly stating them as separate actions
> in documentation. If/when the decision to introduce =guix machine= UI
> will be made, it would be better to implement actual actions there -
> like in the transition from =guix environment= to =guix shell=.

I'm at FOSDEM now, and will be on vacation next week. I'll work on this
and send a new patch series when I'm back home.

Regards,
Arun




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Wed, 19 Feb 2025 00:06:02 GMT) Full text and rfc822 format available.

Message #32 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: Evgeny Pisemsky <mail <at> pisemsky.site>, Ludovic Courtès
 <ludo <at> gnu.org>
Cc: 75414 <at> debbugs.gnu.org
Subject: Re: [bug#75414] [PATCH 2/2] deploy: Add roll-back action.
Date: Wed, 19 Feb 2025 00:04:51 +0000
Thanks for the feedback, and sorry about the long delay. This is on my
radar. I will get to this soon, perhaps by next week.




Information forwarded to arunisaac <at> systemreboot.net, ludo <at> gnu.org, mail <at> pisemsky.site, guix <at> cbaines.net, dev <at> jpoiret.xyz, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Thu, 27 Feb 2025 22:57:02 GMT) Full text and rfc822 format available.

Message #35 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 75414 <at> debbugs.gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [PATCH v2 0/1] deploy: Add --roll-back option
Date: Thu, 27 Feb 2025 22:55:49 +0000
Hi,

I pushed the first patch in this patchset since it was approved. Here is the
v2 of the second patch.

Regards,
Arun

Arun Isaac (1):
  deploy: Add --roll-back option.

 doc/guix.texi           |  8 +++++
 guix/scripts/deploy.scm | 75 +++++++++++++++++++++++++++++++++++------
 2 files changed, 72 insertions(+), 11 deletions(-)


base-commit: 55a5181e745131e5369beaf59d4d406da92b5617
-- 
2.48.1





Information forwarded to arunisaac <at> systemreboot.net, ludo <at> gnu.org, mail <at> pisemsky.site, guix <at> cbaines.net, dev <at> jpoiret.xyz, othacehe <at> gnu.org, maxim.cournoyer <at> gmail.com, zimon.toutoune <at> gmail.com, me <at> tobias.gr, guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Thu, 27 Feb 2025 22:57:03 GMT) Full text and rfc822 format available.

Message #38 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 75414 <at> debbugs.gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>
Subject: [PATCH v2 1/1] deploy: Add --roll-back option.
Date: Thu, 27 Feb 2025 22:55:50 +0000
* guix/scripts/deploy.scm (guix-deploy): Add the --roll-back option.
(show-what-to-deploy): Add #:roll-back? argument.
(roll-back-machine*): New function.
(show-help): Document the --roll-back option.
* doc/guix.texi (Invoking guix deploy): Document the --roll-back option.

Change-Id: Ic5084f287aefb2d1d28380ca4ba1c6971cb913e7
---
 doc/guix.texi           |  8 +++++
 guix/scripts/deploy.scm | 75 +++++++++++++++++++++++++++++++++++------
 2 files changed, 72 insertions(+), 11 deletions(-)

diff --git a/doc/guix.texi b/doc/guix.texi
index a036c85c31a..64746c7f925 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -45232,6 +45232,14 @@ Invoking guix deploy
 The @command{guix deploy -x} command returns zero if and only if the
 command succeeded on all the machines.
 
+You may also wish to roll back configurations on machines to a previous
+generation.  You can do that using the @option{--roll-back} or
+@option{-r} option like so:
+
+@example
+guix deploy --roll-back @var{file}
+@end example
+
 @c FIXME/TODO: Separate the API doc from the CLI doc.
 
 Below are the data types you need to know about when writing a
diff --git a/guix/scripts/deploy.scm b/guix/scripts/deploy.scm
index 941ee199f01..e2ef0006e06 100644
--- a/guix/scripts/deploy.scm
+++ b/guix/scripts/deploy.scm
@@ -3,6 +3,7 @@
 ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays <at> sdf.org>
 ;;; Copyright © 2020-2022 Ludovic Courtès <ludo <at> gnu.org>
 ;;; Copyright © 2024 Richard Sent <richard <at> freakingpenguin.com>
+;;; Copyright © 2025 Arun Isaac <arunisaac <at> systemreboot.net>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -63,6 +64,8 @@ (define (show-help)
   -e, --expression=EXPR  deploy the list of machines EXPR evaluates to"))
   (newline)
   (display (G_ "
+  -r, --roll-back        switch to the previous operating system configuration"))
+  (display (G_ "
   -x, --execute          execute the following command on all the machines"))
   (newline)
   (display (G_ "
@@ -84,6 +87,9 @@ (define %options
          (option '(#\n "dry-run") #f #f
                  (lambda (opt name arg result)
                    (alist-cons 'dry-run? #t result)))
+         (option '(#\r "roll-back") #f #f
+                 (lambda (opt name arg result)
+                   (alist-cons 'roll-back? #t result)))
          (option '(#\x "execute") #f #f
                  (lambda (opt name arg result)
                    (alist-cons 'execute-command? #t result)))
@@ -118,20 +124,32 @@ (define (load-source-file file)
                                            environment-modules))))
     (load* file module)))
 
-(define* (show-what-to-deploy machines #:key (dry-run? #f))
-  "Show the list of machines to deploy, MACHINES."
+(define* (show-what-to-deploy machines #:key (dry-run? #f) (roll-back? #f))
+  "Show the list of machines in MACHINES to deploy or roll back."
   (let ((count (length machines)))
     (if dry-run?
-        (format (current-error-port)
-                (N_ "The following ~d machine would be deployed:~%"
-                    "The following ~d machines would be deployed:~%"
+        (if roll-back?
+            (format (current-error-port)
+                (N_ "The following ~d machine would be rolled back:~%"
+                    "The following ~d machines would be rolled back:~%"
                     count)
                 count)
-        (format (current-error-port)
-                (N_ "The following ~d machine will be deployed:~%"
-                    "The following ~d machines will be deployed:~%"
+            (format (current-error-port)
+                    (N_ "The following ~d machine would be deployed:~%"
+                        "The following ~d machines would be deployed:~%"
+                        count)
+                    count))
+        (if roll-back?
+            (format (current-error-port)
+                    (N_ "The following ~d machine will be rolled back:~%"
+                        "The following ~d machines will be rolled back:~%"
+                        count)
                     count)
-                count))
+            (format (current-error-port)
+                    (N_ "The following ~d machine will be deployed:~%"
+                        "The following ~d machines will be deployed:~%"
+                        count)
+                    count)))
     (display (indented-string
               (fill-paragraph (string-join (map machine-display-name machines)
                                            ", ")
@@ -175,6 +193,35 @@ (define (deploy-machine* store machine)
     (info (G_ "successfully deployed ~a~%")
           (machine-display-name machine))))
 
+(define (roll-back-machine* store machine)
+  "Roll back MACHINE, taking care of error handling."
+  (info (G_ "rolling back ~a...~%")
+        (machine-display-name machine))
+
+  (guard* (c
+           ;; On Guile 3.0, exceptions such as 'unbound-variable' are compound
+           ;; and include a '&message'.  However, that message only contains
+           ;; the format string.  Thus, special-case it here to avoid
+           ;; displaying a bare format string.
+           (((exception-predicate &exception-with-kind-and-args) c)
+            (raise c))
+
+           ((message-condition? c)
+            (leave (G_ "failed to roll back ~a: ~a~%")
+                   (machine-display-name machine)
+                   (condition-message c)))
+           ((formatted-message? c)
+            (leave (G_ "failed to roll back ~a: ~a~%")
+                   (machine-display-name machine)
+                   (apply format #f
+                          (gettext (formatted-message-string c)
+                                   %gettext-domain)
+                          (formatted-message-arguments c)))))
+      (run-with-store store (roll-back-machine machine)))
+
+  (info (G_ "successfully rolled back ~a~%")
+        (machine-display-name machine)))
+
 (define (invoke-command store machine command)
   "Invoke COMMAND, a list of strings, on MACHINE.  Display its output (if any)
 and its error code if it's non-zero.  Return true if COMMAND succeeded, false
@@ -258,6 +305,7 @@ (define-command (guix-deploy . args)
            (machines (or (and file (load-source-file file))
                          (and expression (read/eval expression))))
            (dry-run? (assoc-ref opts 'dry-run?))
+           (roll-back? (assq-ref opts 'roll-back?))
            (execute-command? (assoc-ref opts 'execute-command?)))
       (when (and file expression)
         (leave (G_ "both '--expression' and a deployment file were provided~%")))
@@ -292,8 +340,13 @@ (define-command (guix-deploy . args)
                     (_
                      (leave (G_ "'-x' specified but no command given~%"))))
                   (begin
-                    (show-what-to-deploy machines #:dry-run? dry-run?)
+                    (show-what-to-deploy machines
+                                         #:dry-run? dry-run?
+                                         #:roll-back? roll-back?)
                     (unless dry-run?
                       (map/accumulate-builds store
-                                             (cut deploy-machine* store <>)
+                                             (cut (if roll-back?
+                                                      roll-back-machine*
+                                                      deploy-machine*)
+                                                  store <>)
                                              machines)))))))))))
-- 
2.48.1





Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Fri, 28 Feb 2025 00:43:02 GMT) Full text and rfc822 format available.

Message #41 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
To: Arun Isaac <arunisaac <at> systemreboot.net>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>, Tobias Geerinckx-Rice <me <at> tobias.gr>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Ludovic Courtès <ludo <at> gnu.org>,
 Evgeny Pisemsky <mail <at> pisemsky.site>, 75414 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#75414] [PATCH v2 1/1] deploy: Add --roll-back option.
Date: Fri, 28 Feb 2025 09:41:57 +0900
Hi Arun,

Arun Isaac <arunisaac <at> systemreboot.net> writes:

> * guix/scripts/deploy.scm (guix-deploy): Add the --roll-back option.
> (show-what-to-deploy): Add #:roll-back? argument.
> (roll-back-machine*): New function.
> (show-help): Document the --roll-back option.
> * doc/guix.texi (Invoking guix deploy): Document the --roll-back option.
>
> Change-Id: Ic5084f287aefb2d1d28380ca4ba1c6971cb913e7

The change LGTM, but I was just thinking that --roll-back, which doesn't
actually 'deploy' anything (it rathers does something more akind to
'guix deploy -x -- sudo guix system roll-back', right ?), was a bit odd
to have under 'guix deploy'.  Probably not important enough to block
this contribution.  I'd say, go ahead!

Reviewed-by: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>

--
Thanks,
Maxim




Information forwarded to guix-patches <at> gnu.org:
bug#75414; Package guix-patches. (Fri, 28 Feb 2025 01:24:02 GMT) Full text and rfc822 format available.

Message #44 received at 75414 <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Cc: Josselin Poiret <dev <at> jpoiret.xyz>, Tobias Geerinckx-Rice <me <at> tobias.gr>,
 Simon Tournier <zimon.toutoune <at> gmail.com>, Mathieu Othacehe <othacehe <at> gnu.org>,
 Ludovic Courtès <ludo <at> gnu.org>,
 Evgeny Pisemsky <mail <at> pisemsky.site>, 75414 <at> debbugs.gnu.org,
 Christopher Baines <guix <at> cbaines.net>
Subject: Re: [bug#75414] [PATCH v2 1/1] deploy: Add --roll-back option.
Date: Fri, 28 Feb 2025 01:23:32 +0000
Hi Maxim,

Thanks for the review!

> The change LGTM, but I was just thinking that --roll-back, which doesn't
> actually 'deploy' anything (it rathers does something more akind to
> 'guix deploy -x -- sudo guix system roll-back', right ?), was a bit odd
> to have under 'guix deploy'.  Probably not important enough to block
> this contribution.  I'd say, go ahead!

That's true. It's not the best user experience. The idea was that we'd
revisit that decision later. See earlier discussion on this issue.

Regards,
Arun




Reply sent to Arun Isaac <arunisaac <at> systemreboot.net>:
You have taken responsibility. (Sat, 01 Mar 2025 00:38:02 GMT) Full text and rfc822 format available.

Notification sent to Arun Isaac <arunisaac <at> systemreboot.net>:
bug acknowledged by developer. (Sat, 01 Mar 2025 00:38:03 GMT) Full text and rfc822 format available.

Message #49 received at 75414-done <at> debbugs.gnu.org (full text, mbox):

From: Arun Isaac <arunisaac <at> systemreboot.net>
To: 75414-done <at> debbugs.gnu.org
Cc: Arun Isaac <arunisaac <at> systemreboot.net>,
 Evgeny Pisemsky <mail <at> pisemsky.site>,
 Ludovic Courtès <ludo <at> gnu.org>,
 Maxim Cournoyer <maxim.cournoyer <at> gmail.com>
Subject: Re: [PATCH 0/2] Add roll-back action to guix deploy
Date: Sat, 01 Mar 2025 00:36:33 +0000
Pushed, thanks!




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Sat, 29 Mar 2025 11:24:15 GMT) Full text and rfc822 format available.

This bug report was last modified 99 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.