From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id +MFrJY0z9WZ3sAAAqHPOHw:P1 (envelope-from ) for ; Thu, 26 Sep 2024 10:12:29 +0000 Received: from aspmx1.migadu.com ([2001:41d0:403:4876::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0.migadu.com with LMTPS id +MFrJY0z9WZ3sAAAqHPOHw (envelope-from ) for ; Thu, 26 Sep 2024 12:12:29 +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=kMS6vfzq; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=kU3dDqEf; 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=1727345549; 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=Eov+h5K+GPsfvDVbXfIykuIMCzcnCpdcAvIYlYucKPKVcjSlcJnG8r/ZCbaWPjihqwCFmG Oay6EQsW03xl8MlC+zxxFX5t/FZd/fXdZLewIJ5VWuKoM43FYNfdD9fAK2BrgaRhI5TcDp UyuedKWHdR2b7Pq7izlllP2vCp+4WbiJQnq9NpkovItmoO89xO8Pe9wdzqDWeCchS4P5yn PuPPqUvvFCuDIs+ecprbHZdV4W0MIQN/k+tElpAfL7Zc0AVc/0WLTCfqeN5YRg+qdSXaAB it7jl4Ee2sUYuyyC677CfVVLQaS2hqajtbrZ2dVS709LP1wDIVRPagIDW6fsNA== 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=kMS6vfzq; dkim=fail ("headers rsa verify failed") header.d=rimm.ee header.s=herman header.b=kU3dDqEf; 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-Seal: i=1; s=key1; d=yhetil.org; t=1727345549; a=rsa-sha256; cv=none; b=BIggAGCQtST0yfKa36jiVDmLO571egnqq2IyeLADKz4hS/mSr6P4Llx1W9UBgr191bAwlq JEqsFB+I67EkjZXhB2iuRvbKNSPiv6AnwTUL0ShsLh31/ok53csCHj8WmuE7OPAERk68// 9Rv8YYu9aOEOCIqpygGtjb84vF54NnZiKkJxTyjAl7uMabvQLU8OcCnX668GGM9Ow6yZPu 63a+uy6vFBIuFLKdnR4NfOmg59/Zxwq+FyulkRbbsjBrCfp+EiZXEjPKjDjX5aD5USWGK/ 3KAgp8mHEONHu6ulxJWFEBnkYp9L22h82DmgqlKSJIQkO+ElRNtRHEzDu+L8UQ== 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 365F97AA49 for ; Thu, 26 Sep 2024 12:12:29 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1stlTL-000308-Vb; Thu, 26 Sep 2024 06:11:44 -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-0002yO-P1 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 1stlTI-0007QU-EY for guix-patches@gnu.org; Thu, 26 Sep 2024 06:11:40 -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=kMS6vfzqE06vuF2H3OWJ/+oRMP5C2fJV6bFidsXEeJIQZnge3mPZ4R7tjzXI7Kfga7J7I+DGlmPUm03pFoCcf/aHK7ecxqxdLcOY4Zn2K8GnMjc9Nes+fRMF+23d9wy7B7dzoHgZovuPd4vHo7kQ5xOxkvVMo1ISmDm4pUdEIbj3y7hgP0Wr7j1rgw6RNRpcwQh6UQzFmO6VH/VTBEVWRa+W4H9J21Syl5xHGNCslHnb0+tccuqkXGeX45WW3I6od1CuNZoYfAW+I/IM7qGOAskVWFZn5xVtBaTjZAGz3XPhfNfPedbbV/vCf36btfgHI0eIYEEpOiepS5wfe6cFDw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1stlTj-0003VQ-D0 for guix-patches@gnu.org; Thu, 26 Sep 2024 06:12:07 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#73202] [PATCH v3 11/14] gnu: build: bootloader: Add efi-bootnums procedure. Resent-From: Herman Rimm Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 26 Sep 2024 10:12:07 +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.172734550713325 (code B ref 73202); Thu, 26 Sep 2024 10:12:07 +0000 Received: (at 73202) by debbugs.gnu.org; 26 Sep 2024 10:11:47 +0000 Received: from localhost ([127.0.0.1]:55504 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1stlTO-0003Sl-Ic for submit@debbugs.gnu.org; Thu, 26 Sep 2024 06:11:47 -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 1stlT1-0003PA-UU for 73202@debbugs.gnu.org; Thu, 26 Sep 2024 06:11:25 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rimm.ee; s=herman; t=1727345442; 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=kU3dDqEfP9KtYV9MUCOVtlUrxaVlbzJapexMpfSVIGQ0VhImnM4V7amipd9ZyXbz7wKk5B Y9xZWmgLx53/R5xplTki+yq0Gtp4xd056SnNydyML//gj/Ys7n5I+Et1fPShUuk8rASITK GxXSjOhA/mXCCXAOR+nthleF82d1QSd6vc0PweF9OIHnvmggTKtV4hLnAFupN73vMK5kMN 55tqzboXThqYyYtpKSE4pf/SU4qXRKHnmYFiE36QBkcO4rA7cxZXwJsmpdlFvuwPeL7JYE 1jymYI4l/Y8TmV9/cT1tEJ0f//8pXYtEvxkPSdsiajPg/S+EJIUUnXNttYw7wA== Received: by 81-205-150-117.fixed.kpn.net (OpenSMTPD) with ESMTPSA id fa5314c6 (TLSv1.3:TLS_CHACHA20_POLY1305_SHA256:256:NO); Thu, 26 Sep 2024 10:10:42 +0000 (UTC) Date: Thu, 26 Sep 2024 12:09:08 +0200 Message-ID: <3063da96c7b9dc3db63dbc96d2238f6ed742b857.1727345067.git.herman@rimm.ee> 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-Spam-Score: -4.91 X-Spam-Score: -4.91 X-Migadu-Queue-Id: 365F97AA49 X-Migadu-Scanner: mx10.migadu.com X-TUID: qICQHNlhFSKY 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