From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id COjxJ511fGd1RQEA62LTzQ:P1 (envelope-from ) for ; Tue, 07 Jan 2025 00:30:21 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:58f0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id COjxJ511fGd1RQEA62LTzQ (envelope-from ) for ; Tue, 07 Jan 2025 01:30:21 +0100 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=o30i+q8M; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b=LJPrLMME; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=systemreboot.net (policy=none) ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1736209821; h=from:from:sender:sender: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=LitUQhQBPxqsOjhPgEiWuvKtbleA5haieRyDQkfxRvs=; b=S93rrCllFxHsjhPrOLNYgHxJ9g7s5yS1iYIM0HoMlohHArKhz7pCVq9wVXuMwYbKf6tRZ+ wP5cUS/t2pYdzRPtgaXY91a3UdmmyV1iLHbwj8VkFS8SB4ObmkRSPqbPXrZjWvFWGWDEmv TjI0pAe4z/Hw2R7EUdUNNrLRUACpFvmu1kCTlvlM4uoLI7FcJWvPLfRB0k6XANbrKPU+vE iu+gLYAaeS0B+to/uONpSAYBGBqyxer4cb+YIro93vJGKbMzgl3sjwvGJ5Lvi5IkbarMFx ZLFXqMCvuJFChKzT9RsPQUlLoBxUHvxstkor0NHYSiZam7sLeJrSRt7U/7k1lQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=o30i+q8M; dkim=fail ("headers rsa verify failed") header.d=systemreboot.net header.s=default header.b=LJPrLMME; 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"; dmarc=fail reason="SPF not aligned (relaxed)" header.from=systemreboot.net (policy=none) ARC-Seal: i=1; s=key1; d=yhetil.org; t=1736209821; a=rsa-sha256; cv=none; b=OxGRGYq2Fr12yQQXc7JhapM8ga2Rv7MOnm7Nijmqq2V1NpoJElmeWCnEyukeN6gDwEEnUw 8W6SRckr2OB6cxXR9N2mnhuPbPlexugY9Cyuj9ZaBU5mv0w2oMVjs/JXftLu6jQhI2CQJH koF6f28+W8VWBMaIJ7EhBSiHIQi2RHJtHVyPMjQN5xwftAI6i4cdznIKMJ8EjZmfYF/l8D jxybN9+pQUqJfNZ3qpZ++Yz6SlRgFd7fwHLQa655+s0dxPFHHhwx2mqR0WT/7rJcrwu4ab lW+6UETKpRdXMdkvMI10+0AciL1IhL5brMkETsmhMR3avEEKJrkQWTYnp/e0Wg== 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 056318E240 for ; Tue, 07 Jan 2025 01:30:20 +0100 (CET) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tUxU2-0002PA-42; Mon, 06 Jan 2025 19:30:10 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tUxU0-0002OV-AO for guix-patches@gnu.org; Mon, 06 Jan 2025 19:30:08 -0500 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tUxTy-00056b-Dv; Mon, 06 Jan 2025 19:30:06 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=SNm2sZ2qIGjuzk1vbimER/IVv5o9pFgJIM3SNvl/Mes=; b=o30i+q8MRv60fifnQfFflF0z+BiAcm5Ufg5vLNmi6fe6602bpS2hWvaNMiZrnTAWXzln4FDXMcg6MeCngskpb6tQc2p/Y7KA92Y9Dg268iSqR38DnPeTTdWckRUwYKDIRF1qvONZiEkcTNhK13po2eXisZVKrpLDdnkKSUFdaz0/rllUpVUyADGzK26qz/gSynJuVDR1Fo1/chz8YW6co1/2h8k7hbxaUhw6FJM+2p70ddCtTkvQBJMnotVaWa4Q+fdGMGPaRWGQcnL9iCDIWURGJWUv1MhUPFaPLvg6Gx6XHCesgMs/gYvfW6hEauyPN8KRRXSnS7s2baBRtXNJ3g==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tUxTu-00043w-OW; Mon, 06 Jan 2025 19:30:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75414] [PATCH 2/2] deploy: Add roll-back action. Resent-From: Arun Isaac Original-Sender: "Debbugs-submit" Resent-CC: arunisaac@systemreboot.net, guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, maxim.cournoyer@gmail.com, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Tue, 07 Jan 2025 00:30:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75414 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75414@debbugs.gnu.org Cc: Arun Isaac , Arun Isaac , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Arun Isaac , Christopher Baines , Josselin Poiret , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Maxim Cournoyer , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 75414-submit@debbugs.gnu.org id=B75414.173620974415514 (code B ref 75414); Tue, 07 Jan 2025 00:30:02 +0000 Received: (at 75414) by debbugs.gnu.org; 7 Jan 2025 00:29:04 +0000 Received: from localhost ([127.0.0.1]:41048 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tUxSy-000429-5p for submit@debbugs.gnu.org; Mon, 06 Jan 2025 19:29:04 -0500 Received: from mugam.systemreboot.net ([139.59.75.54]:50610) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tUxSu-00040q-PC for 75414@debbugs.gnu.org; Mon, 06 Jan 2025 19:29:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=systemreboot.net; s=default; t=1736209734; 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: in-reply-to:in-reply-to:references:references; bh=LitUQhQBPxqsOjhPgEiWuvKtbleA5haieRyDQkfxRvs=; b=LJPrLMMEZOok0tLT8WXy+YOsey1Q6a4rVLtw2ElPiXhP+lm+gBRFItRkaToPztkPO2OpLJ MJ1wCGmZAstP8aTcG1U0z+nK2Z73OxpkDxqQyVh+HK5SBRT9cYHHV6OT9jP9LlWoG2me9O sUWYE4o3cfash9LUY5IgimrC6vBIkEDSkdKW9ETW+VHhHIMtkYNmvP7uNhTABFnKuA4249 kak2bVdJ+L1L+cqWWBIEvLchWQP2nOuJrYkBFor5cVG3CGOKlcMwoPPhFAote++ZX2RdC1 YeXcK6N0StOsrWCTd+TJD1EWgMDzvGe3owt4cfGyZKAsUlkTC3HPhUt2ZmXg5w== Received: from localhost.localdomain ( [192.168.2.1]) by mugam.systemreboot.net (OpenSMTPD) with ESMTPSA id 9a4feff6 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 7 Jan 2025 00:28:53 +0000 (UTC) From: Arun Isaac Date: Tue, 7 Jan 2025 00:28:31 +0000 Message-ID: <48a1e0e70b6e9aef50c847e5882fd996c0a5476d.1736208948.git.arunisaac@systemreboot.net> X-Mailer: git-send-email 2.47.1 In-Reply-To: References: MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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-bounces+larch=yhetil.org@gnu.org X-Migadu-Flow: FLOW_IN X-Migadu-Country: US X-Migadu-Scanner: mx11.migadu.com X-Migadu-Spam-Score: 8.01 X-Migadu-Spam: Yes X-Migadu-Queue-Id: 056318E240 X-Spam: Yes X-Spam-Score: 8.01 X-TUID: U//P0E1XxP9I * 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 ;;; Copyright © 2020-2022 Ludovic Courtès ;;; Copyright © 2024 Richard Sent +;;; Copyright © 2025 Arun Isaac ;;; ;;; 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