From patchwork Sun Aug 4 03:55:21 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lilah Tascheter X-Patchwork-Id: 66653 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 4F8E427BBEA; Sun, 4 Aug 2024 04:57:20 +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=-4.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, 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 3530727BBE2 for ; Sun, 4 Aug 2024 04:57:19 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1saSMP-0007Kt-Nm; Sat, 03 Aug 2024 23:56:45 -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 1saSMO-0007KE-RB for guix-patches@gnu.org; Sat, 03 Aug 2024 23:56:44 -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 1saSMN-00048K-Rj; Sat, 03 Aug 2024 23:56:43 -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:References:In-Reply-To:Date:From:To:Subject; bh=84/2yjYQnU7+z8GmMgD4MuSxb3CRyFMyRCZ/dLM81BQ=; b=litMLwfl/yEtACoeX8aAAGOFYBGciNQ9v7+F8MNZR9ROBeNbSGx4dubZgIhkWAiYrWSxIBd9hJ9ZOWiUQ4rlseS8WIVDTc11Tkn5RR9uL6c5anK3kJDckLjZG7NFmxSMyDUBquvaHjOQEhfCxA2cXdw0J1sCipGNFQZQkbONxkV84v2i6UsiJoGbH0MkYb7EMdS99j1UiltmrzuAyuBDPE2UsqapdccTCJZlKaDLF2S+aQkK18WS+s7o2oP0KFNA1DQfm2l/lAnp+gQ+mjDxxSLVHEZOG/Ou4bm1cxzeWcbC30fY0d1ndvgFbywCS3goEwfXe4X8aB41XgA02bF4Eg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1saSMg-0001IH-9w; Sat, 03 Aug 2024 23:57:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72457] [PATCH 01/15] guix: scripts: Rewrite reinstall-bootloader to use provenance data. Resent-From: Lilah Tascheter Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Sun, 04 Aug 2024 03:57:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72457 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 72457@debbugs.gnu.org Cc: Lilah Tascheter , Christopher Baines , Josselin Poiret , Ludovic Court??s , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Ludovic Court??s , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 72457-submit@debbugs.gnu.org id=B72457.17227438144905 (code B ref 72457); Sun, 04 Aug 2024 03:57:02 +0000 Received: (at 72457) by debbugs.gnu.org; 4 Aug 2024 03:56:54 +0000 Received: from localhost ([127.0.0.1]:55106 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saSMX-0001H1-Gc for submit@debbugs.gnu.org; Sat, 03 Aug 2024 23:56:54 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:60926) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saSMV-0001GX-Bb for 72457@debbugs.gnu.org; Sat, 03 Aug 2024 23:56:52 -0400 Authentication-Results: purelymail.com; auth=pass DKIM-Signature: a=rsa-sha256; b=Q8/hBi+X9b1mh3atFnYFhY4TY/nasxzINrJA+5l6/208t0/qAiK1aRrv+9SAHcwH3msoBZTCqm6DCif6/0CrLhA16F3rfRvD25Mjpgy2Tz/gfZnRWi4FaTeH/Frx6bSFBGGCDoCLNF73yCb8Kc+EfMH5DLunyvRmNBLQaTD9AebMbKd2TO8PpE6M+hQ5D2AKqWmNpV68lPqM2okyV1qiKutWs+yfywLxPvx+wlbKcsDFLyBMexBL4d4ZtbMSCRB1PyKaZ/Yr8An2Rv/Ygm+FEkmfUsL3yZzKoWUtHu644IUoEIe9ZPdMQvj1p9hFafTTA0592TFO1FmlTPvb1sZAFA==; s=purelymail2; d=lunabee.space; v=1; bh=NGAX//6gbaSkVGZaNWtJqH+fpDh0lE7iNJYijsJRixk=; h=Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=gacLeI6sYK+QAzBQFQZRqL7yQF1ooml/P6LAqIiY+hEiP+8V+zl+Y5rfvcoKPyVRZzGxM7LMhy2uapxLpH9tPVVXFgtUT0Koo9YUCBOFcZKSSNbgoke9DlmFPI/wi/bcPsCv6nI0wxf/vlKiRx4xyLnhGQNN88ZDYj6sJT2sBHAahxq8kcjZkJNZiXFTUrLRDmmJB/41JaMQ80JdbX+gtlYBQ4HKRXzzE/WZv+a/UeOBk+sw0oRpRWJKYNBUVtGFQxVch7qpORK6qYmKJl39x7tWZv09wxhVsgT1peAyf0KimI/sx9Rq0p39gDEba1ivzCjRmndUig30fMmw88Vfpg==; s=purelymail2; d=purelymail.com; v=1; bh=NGAX//6gbaSkVGZaNWtJqH+fpDh0lE7iNJYijsJRixk=; h=Feedback-ID:Received:From:To:Subject:Date; Feedback-ID: 8937:2070:null:purelymail X-Pm-Original-To: 72457@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id 1753051598; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 04 Aug 2024 03:56:19 +0000 (UTC) Date: Sat, 3 Aug 2024 22:55:21 -0500 Message-ID: <6d8a2015a9e54642e3ecf0f7d1d95300496cbbde.1722741997.git.lilah@lunabee.space> In-Reply-To: References: MIME-Version: 1.0 X-MIME-Autoconverted: from 8bit to quoted-printable by Purelymail 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: , X-Patchwork-Original-From: Lilah Tascheter via Guix-patches From: Lilah Tascheter Reply-To: Lilah Tascheter 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 The current implementation is broken anyway. Multiple bootloaders share a name (including both versions of extlinux) and bootloader-configuration data is significant to bootloader installation. It shouldn't be just faked. Rely on the provenance service instead, which while not always present, should be for the vast majority of systems. * guix/scripts/system.scm (reinstall-bootloader): Rename to... (install-bootloader-from-provenance): ...this, and rewrite to extract bootloader-configuration data from system provenance. (switch-to-system-generation, process-command): Use install-bootloader-from-provenance. Change-Id: I5713a43ad4f9f32a129d980db06d70de16b03f27 --- guix/scripts/system.scm | 75 ++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 50 deletions(-) diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 0f7d864e06..bb7b5d37bf 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,60 +378,33 @@ (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." +(define (install-bootloader-from-provenance store number) + "Re-install an old bootloader using provenance data for system profile +generation NUMBER with store 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)))) - (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))) - (mbegin %store-monad - (built-derivations drvs) - ;; Only install bootloader configuration file. - (install-bootloader local-eval bootloader-config bootcfg - #:run-installer? #f)))))) + (os (receive (_ os) (system-provenance generation) + (and=> os read-operating-system))) + (bootloader-config (operating-system-bootloader os)) + (bootloader (bootloader-configuration-bootloader bootloader-config)) + (numbers (delv number (reverse (generation-numbers %system-profile)))) + (old (profile->boot-alternatives %system-profile numbers))) + (if os + (run-with-store store + (mlet* %store-monad + ((bootcfg (lower-object (operating-system-bootcfg os old))) + (drvs -> (list bootcfg))) + (mbegin %store-monad + (built-derivations drvs) + ;; Only install bootloader configuration file. + (install-bootloader local-eval bootloader-config bootcfg + #:run-installer? #f)))) + (leave (G_ "cannot rollback to provenanceless generation '~a'~%") + number)))) ;;; @@ -1416,7 +1390,8 @@ (define (process-command command args opts) (x (leave (G_ "wrong number of arguments~%")))))) (with-store* store (delete-matching-generations store %system-profile pattern) - (reinstall-bootloader store (generation-number %system-profile))))) + (install-bootloader-from-provenance store + (generation-number %system-profile))))) ((switch-generation) (let ((pattern (match args ((pattern) pattern)