From patchwork Thu Sep 12 16:58:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Herman Rimm X-Patchwork-Id: 67889 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 8482627BBE2; Thu, 12 Sep 2024 18:00:30 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_VALIDITY_CERTIFIED, RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE,SPF_HELO_PASS, URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 5AABA27BBE9 for ; Thu, 12 Sep 2024 18:00:28 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sonAj-0005nk-NN; Thu, 12 Sep 2024 12:59:57 -0400 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 1sonAh-0005nG-HO for guix-patches@gnu.org; Thu, 12 Sep 2024 12:59:55 -0400 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 1sonAh-00015J-7e for guix-patches@gnu.org; Thu, 12 Sep 2024 12:59:55 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:Subject; bh=sluPL4qYkW0nibp9M23T3xRn75nJO7uDxuP5HkkFUXM=; b=jmmw9o7ViEReu/yURmRJXv3lnLfnt4b5Q1k4rKCk+W7izzQeUF4rF4H5xJGHirM4MomhXvSJJvppbOrST227/CtrotA0av4m1k7AmJunotKT99Bk5yHk+pUPz2YZ+WucaPaoZBiExVClYvMpBJGb6joBEeVWNbOK9MA52ZiZlZ56pDSsb9t68P596+hAIYBv81r+L881rNaxZObRf4IuUGl9GvETV9nXcLhKswbwDkUu00FoUHeoSUOkhfzTlSU3jkiGGgymRDiPJ+FdSRqA99FJsjtMpASZVSRSHK93zaT4UmwQYxAmIied4/GnEuw1r3fub6FjtwgVtAf1Xk55bw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sonAo-0004zG-4O for guix-patches@gnu.org; Thu, 12 Sep 2024 13:00:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73202] [PATCH] guix: scripts: Rewrite reinstall-bootloader to use provenance data. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 12 Sep 2024 17:00:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 73202 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73202@debbugs.gnu.org Cc: Lilah Tascheter X-Debbugs-Original-To: guix-patches@gnu.org Received: via spool by submit@debbugs.gnu.org id=B.172616037519089 (code B ref -1); Thu, 12 Sep 2024 17:00:02 +0000 Received: (at submit) by debbugs.gnu.org; 12 Sep 2024 16:59:35 +0000 Received: from localhost ([127.0.0.1]:41768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sonAN-0004xo-34 for submit@debbugs.gnu.org; Thu, 12 Sep 2024 12:59:35 -0400 Received: from lists.gnu.org ([209.51.188.17]:40292) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sonAK-0004xe-Pg for submit@debbugs.gnu.org; Thu, 12 Sep 2024 12:59:33 -0400 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 1sonAC-0004dl-Ao for guix-patches@gnu.org; Thu, 12 Sep 2024 12:59:24 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117] helo=email.rimm.ee) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_CHACHA20_POLY1305:256) (Exim 4.90_1) (envelope-from ) id 1sonA6-00012N-06 for guix-patches@gnu.org; Thu, 12 Sep 2024 12:59:21 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1726160350; 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; bh=btJc+SU6FN0iMlsaQoLpdEQ1FwpzFtHgI5jaCelZEjY=; b=lbrtjeULBwQXoe6UkSeKOl9B4aAtGLzVXSG91aTlTifX9UyfxMifItv3sRBpCJEU4g7V9c kD9od0A0scjUQYEyJlUf6fi2ukj5GwE+/pfyonh9u9aifPc9OvCymU0xL30NOfCZZaAAXA 5Xp97qYEohkxlcZtpk1FCNkixhdbnhQNwFcjtmpvOgOQ7R0q3zaBtg97p9pryqvnV9h841 eAqz1WD9OMNntCVHjb+KGt2OSF0GwB2E/GfOSkAOBS4hqinoGa1gP5I2Ivj9RFJAGF9vte aUpb6CfUltpinCu7T508CgnaBhEk4WJjWoye/AqF2U/deYRkZQ3t/i/NHFjQ7g== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 9baf5441 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Thu, 12 Sep 2024 16:59:09 +0000 (UTC) Date: Thu, 12 Sep 2024 18:58:17 +0200 Message-ID: <20240912165818.21580-1-herman@rimm.ee> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Received-SPF: pass client-ip=81.205.150.117; envelope-from=herman@rimm.ee; helo=email.rimm.ee X-Spam_score_int: 16 X-Spam_score: 1.6 X-Spam_bar: + X-Spam_report: (1.6 / 5.0 requ) BAYES_00=-1.9, DKIM_INVALID=0.1, DKIM_SIGNED=0.1, RCVD_IN_PBL=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, TVD_RCVD_IP=0.001 autolearn=no autolearn_force=no X-Spam_action: no action 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: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches X-Patchwork-Original-From: Herman Rimm via Guix-patches via From: Herman Rimm Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches From: Lilah Tascheter Looking up bootloaders by name is broken because (extlinux) bootloaders share a name. Also, bootloader-configuration data is significant to bootloader installation, so it shouldn't just use the default values. Installation can rely on the provenance service instead, which should be present for the vast majority of systems. * guix/scripts/system.scm (install-bootloader-from-os, install-bootloader-from-provenance): Add procedures. (reinstall-bootloader): Remove procedure. (switch-to-system-generation, process-command): Use install-bootloader-from-provenance. Change-Id: I5713a43ad4f9f32a129d980db06d70de16b03f27 --- Hello, This requires patches from #69343. #72457 is big and I thought it would be nice to separately review whatever possible, hence the new issue. This is [PATCH v5 01/15] from issue #72457, but with a modified commit description and the addition of an install-bootloader-from-os procedure, to reduce nesting and only define local variables when relevant. The (gnu tests reconfigure) tests all pass, though I myself cannot roll-back or switch-generations for unrelated reasons. So please let me know if this patch creates any trouble with the aformentioned and if you have ideas for additional (gnu tests reconfigure) tests. Thanks, Herman gnu/bootloader.scm | 2 ++ guix/scripts/system.scm | 72 +++++++++++++++-------------------------- 2 files changed, 28 insertions(+), 46 deletions(-) diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index f32e90e79d..61311b32cb 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -7,6 +7,8 @@ ;;; Copyright © 2022 Josselin Poiret ;;; Copyright © 2022 Reza Alizadeh Majd ;;; Copyright © 2024 Tomas Volf <~@wolfsden.cz> +;;; Copyright © 2024 Lilah Tascheter +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 0f7d864e06..d14dfd8d81 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -88,6 +88,7 @@ (define-module (guix scripts system) #:use-module (srfi srfi-37) #:use-module (ice-9 format) #:use-module (ice-9 match) + #:use-module (ice-9 receive) #:use-module (rnrs bytevectors) #:export (guix-system read-operating-system @@ -377,61 +378,39 @@ (define (switch-to-system-generation store spec) (activate (string-append generation "/activate"))) (if number (begin - (reinstall-bootloader store number) + (install-bootloader-from-provenance store number) (switch-to-generation* %system-profile number) (unless-file-not-found (primitive-load activate))) (leave (G_ "cannot switch to system generation '~a'~%") spec)))) -(define* (system-bootloader-name #:optional (system %system-profile)) - "Return the bootloader name stored in SYSTEM's \"parameters\" file." - (let ((params (unless-file-not-found - (read-boot-parameters-file system)))) - (boot-parameters-bootloader-name params))) - -(define (reinstall-bootloader store number) - "Re-install bootloader for existing system profile generation NUMBER. -STORE is an open connection to the store." - (let* ((generation (generation-file-name %system-profile number)) - ;; Detect the bootloader used in %system-profile. - (bootloader (lookup-bootloader-by-name (system-bootloader-name))) - - ;; Use the detected bootloader with default configuration. - ;; It will be enough to allow the system to boot. - (bootloader-config (bootloader-configuration - (bootloader bootloader))) - - ;; Make the specified system generation the default entry. - (chosen-alternative (generation->boot-alternative - %system-profile number)) - (params (boot-alternative-parameters chosen-alternative)) - (locale (boot-parameters-locale params)) - (store-crypto-devices (boot-parameters-store-crypto-devices params)) - (store-directory-prefix - (boot-parameters-store-directory-prefix params)) - (old-generations - (delv number (reverse (generation-numbers %system-profile)))) - (previous-boot-alternatives (profile->boot-alternatives - %system-profile old-generations)) - (entries (list (boot-parameters->menu-entry params))) - (old-entries (map boot-parameters->menu-entry - (map boot-alternative-parameters - previous-boot-alternatives)))) +(define (install-bootloader-from-os store number os) + "Re-install an old bootloader defined in record OS, +for system profile generation NUMBER, with store STORE." + (let* ((os (read-operating-system os)) + (bootloader-config (operating-system-bootloader os)) + (numbers (generation-numbers %system-profile)) + (numbers (delv number (reverse numbers))) + (old (profile->boot-alternatives %system-profile numbers)) + (bootcfg (operating-system-bootcfg os old))) (run-with-store store - (mlet* %store-monad - ((bootcfg (lower-object - ((bootloader-configuration-file-generator bootloader) - bootloader-config entries - #:locale locale - #:store-crypto-devices store-crypto-devices - #:store-directory-prefix store-directory-prefix - #:old-entries old-entries))) - (drvs -> (list bootcfg))) + (mlet* %store-monad ((bootcfg (lower-object bootcfg)) + (drvs -> (list bootcfg))) (mbegin %store-monad (built-derivations drvs) ;; Only install bootloader configuration file. (install-bootloader local-eval bootloader-config bootcfg #:run-installer? #f)))))) +(define (install-bootloader-from-provenance store number) + "Re-install an old bootloader using provenance data for system profile +generation NUMBER with store STORE." + (receive (_ os) + (system-provenance (generation-file-name %system-profile number)) + (if os + (install-bootloader-from-os store number os) + (leave (G_ "cannot rollback to generation '~a': no provenance~%") + number)))) + ;;; ;;; Graphs. @@ -1413,10 +1392,11 @@ (define-syntax-rule (with-store* store exp ...) (let ((pattern (match args (() #f) ((pattern) pattern) - (x (leave (G_ "wrong number of arguments~%")))))) + (_ (leave (G_ "wrong number of arguments~%"))))) + (number (generation-number %system-profile))) (with-store* store (delete-matching-generations store %system-profile pattern) - (reinstall-bootloader store (generation-number %system-profile))))) + (install-bootloader-from-provenance store number)))) ((switch-generation) (let ((pattern (match args ((pattern) pattern)