From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id +ILpMUBR7WaPaAAA62LTzQ:P1 (envelope-from ) for ; Fri, 20 Sep 2024 10:41:04 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id +ILpMUBR7WaPaAAA62LTzQ (envelope-from ) for ; Fri, 20 Sep 2024 12:41:04 +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=B5yCD6lS; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=NN1T3WpW; dmarc=pass (policy=none) header.from=gnu.org; 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" ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1726828864; 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=ahYOiYejvGUtNAnSjkb6HMGrj1pd/GqjJ61kZBWbi9A=; b=C2ecOXsTY8nQhJesNJ9tZQzxf4tkSUG0jHDEPL0eRBc+HpvK77xXsIMtENxTCB+QF6swU2 pgqdaozAt2eg6zUWILTc1YIvzHK5H5b09G9rLpxjWfAnEV3VzA5M57DLeVVBDhrLwVo4PT wL6CzXYNE1gZQHy3JPz5ogpzK2pqztiHHWQYz/qr8aIBXg1In4in4jphiwtky+Serx9bKh UpXmhRK5zADZ+WU6Sm5mXr0GRFHmBLF1o0sYZnEL7KTaivDq82jtIAqN6hSUYXHzPAeaJ/ HMFZ32G1u8+Jfp/dj1RUVOlPNw0uy8Ku9ZbCSW5uFD0FpgF+c5YqV9bzmRFYtA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1726828864; a=rsa-sha256; cv=none; b=CxqmVH++ILABcOhHcn/q53izsQD9+FCsjv9czfAdK4WRm5KW6ZBxSeOWI3XmZV9oDETxgT o3g2DWVwe2cIOo8JSb3AnCCJyQqy+9F58EXGnq3b6CE0E0EdZxmGdBRaP18UjmIb0tIhtv +0pcdZCl+kzb/0uLd6pTFExJtJm4qVjI3Iw3w+fcq7jvsr2DsLMBJM6z1D4gBd0BnaYmF0 /lYfH9nDkNhaG4o9vYcvMV/Fl6RKoqobFn+VA7RY6fA64CQk/TdgFAi6hLY9I7JAL6yZi7 d5G0SsuRb66CZnAUgjfvSkdj/anBfCM6MJ4kJ51GyjKightnGSRLyhHKqRTEMg== 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=B5yCD6lS; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=NN1T3WpW; dmarc=pass (policy=none) header.from=gnu.org; 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" 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 9C3C1E0F7 for ; Fri, 20 Sep 2024 12:41:04 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1srb3d-0005AI-0l; Fri, 20 Sep 2024 06:40:13 -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 1srb3G-0004y3-FQ for guix-patches@gnu.org; Fri, 20 Sep 2024 06:39:51 -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 1srb3G-0006UX-6q for guix-patches@gnu.org; Fri, 20 Sep 2024 06:39:50 -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=IwjQq7hXMawzHIjFS9OpHeTFeaptK6HMgCh8qwZAyV8=; b=B5yCD6lS5H2ErdfSK/NdzUXnyxxr+R2CBOwXAzI/omWR3rVsiP2ihZ1RGTYdme0XroWdPU8o1IAG7JwaOuqG7xejAwEagKm0nVilXw3UUoCQlZVGbXXKuUtAxe3hX/0I0+CXdAocgn3hp8bSfJNJwZdYfanx+MBmiQtyUMbcrq5TvYGOCJcgfkA2NdUZd7/GUzxRaMOMIttk+RGE5I4NN3LNkz847BjQoGJthyALtrB3nQQUi88LFoUJ+xnKr3ZikR/JpLcm4uxkPhUR3sHlmYGy41KA/yt1ov1BzxSTTh2uk/6rcRWlgLEbg4wjNoinLUWwa4S5hsd6Hyea3KgcXg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1srb3Y-0001QR-RC for guix-patches@gnu.org; Fri, 20 Sep 2024 06:40:08 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73202] [PATCH v2 11/15] gnu: build: bootloader: Add efi-bootnums procedure. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 20 Sep 2024 10:40:08 +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 Received: via spool by 73202-submit@debbugs.gnu.org id=B73202.17268287835315 (code B ref 73202); Fri, 20 Sep 2024 10:40:08 +0000 Received: (at 73202) by debbugs.gnu.org; 20 Sep 2024 10:39:43 +0000 Received: from localhost ([127.0.0.1]:34173 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srb39-0001NZ-5H for submit@debbugs.gnu.org; Fri, 20 Sep 2024 06:39:43 -0400 Received: from 81-205-150-117.fixed.kpn.net ([81.205.150.117]:54361 helo=email.rimm.ee) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1srb2x-0001KU-17 for 73202@debbugs.gnu.org; Fri, 20 Sep 2024 06:39:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1726828738; 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=ahYOiYejvGUtNAnSjkb6HMGrj1pd/GqjJ61kZBWbi9A=; b=NN1T3WpWUf4k+3qfAJvOXlmfYSiFpoe7GSIvY9RlxO8BBFd2ckPMUoeqsP56Dx+2dOeCfU hoEVdMJGOjwEk05eq8NZEAnQrLl2mjc+QXpIO6pN3PEfbPyOrhzB/LbbRj+F5FtH3lseAY FOvj8ciPpbpTS9Vo7FH+VeZnI4drzm7XdkJo7DNGK4V+AyyVCtyYvfo4hSSFrAgR7smfqo FJiTN3R1pjuaNrzf+7EEu2yYtdsDYA3vWksO7U4vttpLGnx+qmZ56qo0w06/YYovHTcnOM xkwT/JgCf3PV9bsUrsjV1vnI7UrYnJZyGCT0VmHAdEYwt4PLjLKg9IUROP4SJQ== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id d76c76f8 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Fri, 20 Sep 2024 10:38:58 +0000 (UTC) Date: Fri, 20 Sep 2024 12:37:56 +0200 Message-ID: <5bb21b9075822392a90e3e5aeb4e5daa2fcfff82.1726827025.git.herman@rimm.ee> X-Mailer: git-send-email 2.45.2 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: , 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-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -4.91 X-Spam-Score: -4.91 X-Migadu-Scanner: mx13.migadu.com X-Migadu-Queue-Id: 9C3C1E0F7 X-TUID: N75PBeDY0jtf From: Lilah Tascheter * gnu/build/bootloader.scm (atomic-copy, efi-bootnums): Add procedures. (in-temporary-directory): Add macro. Change-Id: I3654d160f7306bb45a78b82ea6b249ff4281f739 --- gnu/build/bootloader.scm | 48 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/gnu/build/bootloader.scm b/gnu/build/bootloader.scm index af6063a884..3934e03aee 100644 --- a/gnu/build/bootloader.scm +++ b/gnu/build/bootloader.scm @@ -3,6 +3,7 @@ ;;; Copyright © 2019 Ludovic Courtès ;;; Copyright © 2022 Denis 'GNUtoo' Carikli ;;; Copyright © 2022 Timothy Sample +;;; Copyright © 2024 Lilah Tascheter ;;; ;;; This file is part of GNU Guix. ;;; @@ -20,13 +21,25 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu build bootloader) + #:autoload (guix build syscalls) (free-disk-space) #:use-module (guix build utils) #:use-module (guix utils) #:use-module (ice-9 binary-ports) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (ice-9 format) + #:use-module (ice-9 match) + #:use-module (ice-9 popen) + #:use-module (ice-9 receive) + #:use-module (ice-9 regex) #:use-module (rnrs io ports) #:use-module (rnrs io simple) - #:export (write-file-on-device + #:use-module (srfi srfi-1) + #:use-module (srfi srfi-26) + #:use-module (srfi srfi-35) + #:export (atomic-copy + in-temporary-directory + write-file-on-device install-efi-loader)) @@ -34,6 +47,21 @@ (define-module (gnu build bootloader) ;;; Writing utils. ;;; +(define (atomic-copy from to) + (let ((pivot (string-append to ".new"))) + (copy-file from pivot) + (rename-file pivot to))) + +(define-syntax-rule (in-temporary-directory blocks ...) + "Run BLOCKS while chdir'd into a temporary directory." + ;; Under POSIX.1-2008, mkdtemp must make the dir with 700 perms. + (let* ((tmp (or (getenv "TMPDIR") "/tmp")) + (dir (mkdtemp (string-append tmp "/guix-bootloader.XXXXXX"))) + (cwd (getcwd))) + (dynamic-wind (lambda () (chdir dir)) + (lambda () blocks ...) + (lambda () (chdir cwd) (delete-file-recursively dir))))) + (define (write-file-on-device file size device offset) "Write SIZE bytes from FILE to DEVICE starting at OFFSET." (call-with-input-file file @@ -56,6 +84,24 @@ (define (write-file-on-device file size device offset) ;;; EFI bootloader. ;;; +;; XXX: Parsing efibootmgr output may be kinda jank. A better way may exist. +(define (efi-bootnums efibootmgr) + "Returns '(path . bootnum) pairs for each EFI boot entry. bootnum is +a string, and path is backslash-deliminated and relative to the ESP." + (let* ((pipe (open-pipe* OPEN_READ efibootmgr)) + (text (get-string-all pipe)) + (status (status:exit-val (close-pipe pipe))) + (bootnum-pattern + "^Boot([0-9a-fA-F]+).*[^A-Za-z]File\\(([^)]+)\\)$")) + (unless (zero? status) + (raise-exception + (formatted-message (G_ "efibootmgr exited with error code ~a") status))) + (fold-matches (make-regexp bootnum-pattern regexp/newline) text '() + (lambda (match acc) + (let* ((path (match:substring match 2)) + (bootnum (match:substring match 1))) + (cons (cons path bootnum) acc)))))) + (define* (install-efi grub grub-config esp #:key targets) "Write a self-contained GRUB EFI loader to the mounted ESP using GRUB-CONFIG. -- 2.45.2