From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id WBK1K6kz9WZUBAAAe85BDQ:P1 (envelope-from ) for ; Thu, 26 Sep 2024 10:12:57 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e224::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2.migadu.com with LMTPS id WBK1K6kz9WZUBAAAe85BDQ (envelope-from ) for ; Thu, 26 Sep 2024 12:12:57 +0200 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="cN/M54jm"; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=KhpQrnMl; 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=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1727345577; h=from:from:sender:sender:reply-to: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=TIV9r0fR/7ADV2dR0dxOhiTkX2HwIVGBAggUOpD02gY=; b=oQ34MafY0b1K0Wa4XOhIopIzBS/cDC6KSHr6H8zBT2FToHlvrxNOuFF3QsJGIuopQaMUiJ ONzuMimY593heZDNiE4IYT5sdEa910PPaWqYM68l82x/WYXLEa7eLejK3fvlYBIxQg7YOc yJ1u1O9Sm2JttJiHo9vXuRwOMBsWA9abCV2o5tQhySg9SCJNjOLV48Aw9uOaj8kmzUsdd/ PHvt2dR/NudGRhjiLBttQDo0mzHRCXpHt4X3qr2cYw3bvPA3fm2HrsHmulBpPa2rteJLl/ EdayIPe33TbsBewJayRH2cHxm6GNFDnmMnU++akVFzhUmDnrfTT19MtHlkhy0Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1727345577; a=rsa-sha256; cv=none; b=X8sMbbli65B3vCgfwtDu9CitvhOxhTlg12pWj1G4NSkPIXQTU9HRwiS0y/h/Ve9hrNnxo8 Wvrg+B9Df/HbAgwOsPIXMrk0fpyT0SGaK3dmEt5BiXgTFXRt3O5D+GxZzU6WJdk/j1s0oG +vTZHEgg37mSoquRQ2rw6eV+BdhCIaUb9cA5jhzcaRsVr5g6QnuG2eqiEXu4cP4r6xgEd9 RnyuBO7kJKEScVBFLeBoTtEjPTuA4/niasBrwKUs2xlxWKgqP9sFVg8MZMHiApVh2fLKRK dPLZQdXGsDHqvgz0+3TIq3r7Qn/rpO2HcLxM57e26dPSPCYGt7m7Zf3dbjn7UA== 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="cN/M54jm"; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=KhpQrnMl; 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=pass (policy=none) header.from=gnu.org 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 4B936817BA for ; Thu, 26 Sep 2024 12:12:57 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1stlTK-0002zY-E6; Thu, 26 Sep 2024 06:11:42 -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 1stlTI-0002xi-98 for guix-patches@gnu.org; Thu, 26 Sep 2024 06:11:40 -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 1stlTH-0007Py-V6; Thu, 26 Sep 2024 06:11:39 -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=v7VVD5foO2RJuxpQG7l1R01iBFyTtg7SBPGm/0Lk4fo=; b=cN/M54jmm2OHZtFdhnGHdDwDKyObA6bOfgXv10ggYTO+TM7ESqo9jdgBVp3MCe1Gswl+T2Ixbl1k2jWjPB0cd7nwNN6jSeT7iYJ/BpNmKJ9R0GI6OdsqSGFzE4t/vksMf6mB53nlqzq8FllCthba4UADtvYNP//ljPtThIRIH1hFFQLctMtWNIecy8mjtdPL+0O2MbH0dc9Jik9tBbTRJdR6xTGrTCi1WGMf92z7pttdIEZmMZQh+N2Gb45yGJYz7P0q6y65q0kjOGH2CkA3G/T9KK9pLcNWc/5XpQV89ey3uVKEXylSFrZivIP6FNdGDDUOBmHgoQweKNMJipGrQA==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1stlTg-0003UI-9H; Thu, 26 Sep 2024 06:12:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73202] [PATCH v3 05/14] guix: scripts: Rewrite reinstall-bootloader to use provenance data. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix@cbaines.net, dev@jpoiret.xyz, lilah@lunabee.space, ludo@gnu.org, othacehe@gnu.org, zimon.toutoune@gmail.com, me@tobias.gr, guix-patches@gnu.org Resent-Date: Thu, 26 Sep 2024 10:12:04 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 73202 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 73202@debbugs.gnu.org Cc: Lilah Tascheter , Christopher Baines , Josselin Poiret , Lilah Tascheter , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice X-Debbugs-Original-Xcc: Christopher Baines , Josselin Poiret , Lilah Tascheter , Ludovic =?UTF-8?Q?Court=C3=A8s?= , Mathieu Othacehe , Simon Tournier , Tobias Geerinckx-Rice Received: via spool by 73202-submit@debbugs.gnu.org id=B73202.172734548713252 (code B ref 73202); Thu, 26 Sep 2024 10:12:04 +0000 Received: (at 73202) by debbugs.gnu.org; 26 Sep 2024 10:11:27 +0000 Received: from localhost ([127.0.0.1]:55489 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stlT4-0003RL-37 for submit@debbugs.gnu.org; Thu, 26 Sep 2024 06:11:27 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:39475 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stlSx-0003PA-Bw for 73202@debbugs.gnu.org; Thu, 26 Sep 2024 06:11:20 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1727345438; 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=TIV9r0fR/7ADV2dR0dxOhiTkX2HwIVGBAggUOpD02gY=; b=KhpQrnMlDW+ZfZcC2yXGB2DerVGgdFHFKscIlveBRNe//Ce47XdFbPiyocZwScjw6aNCUy yRWUBMouxPEZurAh8M43a831M6+8nIVZ/2bI/2fygEZQsQKOyYy9g0DRyI8WxmGtff8iJv uVJlh967E0CZ/pzzDqpO83sB1J4ltIthLqiuoa8ZkGRv1s08zoBfGoUNix4IjKX7uuPirt bUZ3IdyljNwimoOHbG0hTk+pKQor0tLRUd+u5/PP4uyXdkEigFql76KVgCgh20XukXOcPF yb4eQS9Xu/PkzEys1zKYhshyv9I9xizZPL1dDQxnb+E1BoTiKkmwTpLdFXs9oQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id 30ea07c1 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Thu, 26 Sep 2024 10:10:38 +0000 (UTC) Date: Thu, 26 Sep 2024 12:09:02 +0200 Message-ID: X-Mailer: git-send-email 2.45.2 In-Reply-To: <74c789e74594d538308d33633ed8540283dcde49.1727345067.git.herman@rimm.ee> References: <74c789e74594d538308d33633ed8540283dcde49.1727345067.git.herman@rimm.ee> 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: , Reply-to: Herman Rimm X-ACL-Warn: , Herman Rimm via Guix-patches From: Herman Rimm via Guix-patches via 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: mx12.migadu.com X-Migadu-Spam-Score: -5.52 X-Migadu-Queue-Id: 4B936817BA X-Spam-Score: -5.52 X-TUID: SUciPGyNows/ 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. * gnu/bootloader.scm (%bootloaders): Delete variable. (lookup-bootloader-by-name, bootloader-modules): Delete procedures. * 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 --- gnu/bootloader.scm | 26 --------------- guix/scripts/system.scm | 73 ++++++++++++++++------------------------- 2 files changed, 28 insertions(+), 71 deletions(-) diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index 865521e6e5..3ea50a4004 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -26,7 +26,6 @@ (define-module (gnu bootloader) #:use-module (gnu system file-systems) #:use-module (gnu system uuid) - #:use-module (guix discovery) #:use-module (guix gexp) #:use-module (guix profiles) #:use-module (guix records) @@ -79,8 +78,6 @@ (define-module (gnu bootloader) bootloader-configuration-device-tree-support? bootloader-configuration-extra-initrd - %bootloaders - lookup-bootloader-by-name efi-bootloader-chain)) @@ -287,29 +284,6 @@ (define (bootloader-configuration-targets config) ;;; Bootloaders. ;;; -(define (bootloader-modules) - "Return the list of bootloader modules." - (all-modules (map (lambda (entry) - `(,entry . "gnu/bootloader")) - %load-path) - #:warn warn-about-load-error)) - -(define %bootloaders - ;; The list of publically-known bootloaders. - (delay (fold-module-public-variables (lambda (obj result) - (if (bootloader? obj) - (cons obj result) - result)) - '() - (bootloader-modules)))) - -(define (lookup-bootloader-by-name name) - "Return the bootloader called NAME." - (or (find (lambda (bootloader) - (eq? name (bootloader-name bootloader))) - (force %bootloaders)) - (leave (G_ "~a: no such bootloader~%") name))) - (define (efi-bootloader-profile packages files hooks) "Creates a profile from the lists of PACKAGES and FILES from the store. This profile is meant to be used by the bootloader-installer. diff --git a/guix/scripts/system.scm b/guix/scripts/system.scm index 881f2de104..6b6bb46975 100644 --- a/guix/scripts/system.scm +++ b/guix/scripts/system.scm @@ -11,6 +11,8 @@ ;;; Copyright © 2021 Brice Waegeneire ;;; Copyright © 2021 Simon Tournier ;;; Copyright © 2022 Tobias Geerinckx-Rice +;;; Copyright © 2024 Lilah Tascheter +;;; Copyright © 2024 Herman Rimm ;;; ;;; This file is part of GNU Guix. ;;; @@ -88,6 +90,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 @@ -375,60 +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-alternative->menu-entry - 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. @@ -1387,10 +1369,11 @@ (define (process-command command args opts) (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) -- 2.45.2