all messages for Guix-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Herman Rimm via Guix-patches via <guix-patches@gnu.org>
To: 75010@debbugs.gnu.org
Subject: [bug#75010] [PATCH 2/7] gnu: machine: ssh: Refactor roll-back-managed-host.
Date: Sat, 21 Dec 2024 18:04:06 +0100	[thread overview]
Message-ID: <cbe72256fc842a207540d3a0d3ca28ef549ed885.1734798943.git.herman@rimm.ee> (raw)
In-Reply-To: <cover.1734798943.git.herman@rimm.ee>

* gnu/machine/ssh.scm (roll-back-managed-host): Use let* and mbegin.

Change-Id: Ic3d5039ecf01e1e965dce8a696e7dbd625d2b3c5
---
 gnu/machine/ssh.scm | 53 ++++++++++++++++++++++-----------------------
 1 file changed, 26 insertions(+), 27 deletions(-)

diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm
index 3e10d984e7..24c36a1936 100644
--- a/gnu/machine/ssh.scm
+++ b/gnu/machine/ssh.scm
@@ -2,6 +2,8 @@
 ;;; Copyright © 2019 Jakob L. Kreuze <zerodaysfordays@sdf.org>
 ;;; Copyright © 2020-2023 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2024 Ricardo <rekado@elephly.net>
+;;; Copyright © 2024 Felix Lechner <felix.lechner@lease-up.com>
+;;; Copyright © 2024 Herman Rimm <herman@rimm.ee>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -589,33 +591,30 @@ (define (roll-back-managed-host machine)
   (define roll-back-failure
     (condition (&message (message (G_ "could not roll-back machine")))))
 
-  (mlet* %store-monad ((boot-parameters (machine-boot-parameters machine))
-                       (_ -> (if (< (length boot-parameters) 2)
-                                 (raise roll-back-failure)))
-                       (entries -> (map boot-parameters->menu-entry
-                                        (list (second boot-parameters))))
-                       (locale -> (boot-parameters-locale
-                                   (second boot-parameters)))
-                       (crypto-dev -> (boot-parameters-store-crypto-devices
-                                       (second boot-parameters)))
-                       (store-dir -> (boot-parameters-store-directory-prefix
-                                      (second boot-parameters)))
-                       (old-entries -> (map boot-parameters->menu-entry
-                                            (drop boot-parameters 2)))
-                       (bootloader -> (operating-system-bootloader
-                                       (machine-operating-system machine)))
-                       (bootcfg (lower-object
-                                 ((bootloader-configuration-file-generator
-                                   (bootloader-configuration-bootloader
-                                    bootloader))
-                                  bootloader entries
-                                  #:locale locale
-                                  #:store-crypto-devices crypto-dev
-                                  #: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))))
+  (mmatch %store-monad (machine-boot-parameters machine)
+    ((_ params rest ...)
+     (let* ((entries (list (boot-parameters->menu-entry params)))
+            (locale (boot-parameters-locale params))
+            (crypto-dev (boot-parameters-store-crypto-devices params))
+            (store-dir (boot-parameters-store-directory-prefix params))
+            (old-entries (map boot-parameters->menu-entry rest))
+            (bootloader (operating-system-bootloader
+                          (machine-operating-system machine)))
+            (generate-bootloader-configuration-file
+             (bootloader-configuration-file-generator
+               (bootloader-configuration-bootloader bootloader))))
+       (mbegin %store-monad
+         (lower-object (generate-bootloader-configuration-file
+                         bootloader entries
+                         #:locale locale
+                         #:store-crypto-devices crypto-dev
+                         #:store-directory-prefix store-dir
+                         #:old-entries old-entries)))
+       (mlet %store-monad
+           ((remote-result (machine-remote-eval machine remote-exp)))
+         (when (eqv? 'error remote-result)
+           (raise roll-back-failure)))))
+    (_ (raise roll-back-failure))))
 
 \f
 ;;;
-- 
2.45.2





  parent reply	other threads:[~2024-12-21 18:14 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <cover.1734798943.git.herman@rimm.ee>
2024-12-21 17:04 ` [bug#75010] [PATCH 1/7] monads: Add 'mmatch' Herman Rimm via Guix-patches via
2024-12-21 17:04 ` Herman Rimm via Guix-patches via [this message]
2024-12-21 17:04 ` [bug#75010] [PATCH 3/7] gnu: machine: ssh: Return monadic value from roll-back-managed-host Herman Rimm via Guix-patches via
2024-12-21 17:04 ` [bug#75010] [PATCH 4/7] Rename two remote variables confusingly named 'generations' Herman Rimm via Guix-patches via
2024-12-21 17:04 ` [bug#75010] [PATCH 5/7] gnu: machine: Remove &deploy-error Herman Rimm via Guix-patches via
2024-12-21 17:04 ` [bug#75010] [PATCH 6/7] gnu: machine: ssh: Roll-back on failure Herman Rimm via Guix-patches via
2024-12-21 17:04 ` [bug#75010] [PATCH 7/7] WIP: gnu: tests: Add module for guix deploy tests Herman Rimm via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=cbe72256fc842a207540d3a0d3ca28ef549ed885.1734798943.git.herman@rimm.ee \
    --to=guix-patches@gnu.org \
    --cc=75010@debbugs.gnu.org \
    --cc=herman@rimm.ee \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/guix.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.