From patchwork Sun Jan 28 09:51:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lilah Tascheter X-Patchwork-Id: 59508 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 AEB3527BBEA; Sun, 28 Jan 2024 10:04:22 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED, URIBL_SBL_A autolearn=no 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 9535E27BBE2 for ; Sun, 28 Jan 2024 10:04:21 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rU219-0007q3-Fh; Sun, 28 Jan 2024 05:03:59 -0500 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 1rU215-0007oe-Qg for guix-patches@gnu.org; Sun, 28 Jan 2024 05:03:56 -0500 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 1rU215-0006mh-JA for guix-patches@gnu.org; Sun, 28 Jan 2024 05:03:55 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rU21C-00040O-1s; Sun, 28 Jan 2024 05:04:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68524] [PATCH v2 1/2] gnu: bootloaders: Add uki packages. Resent-From: Lilah Tascheter Original-Sender: "Debbugs-submit" Resent-CC: efraim@flashner.co.il, vagrant@debian.org, guix-patches@gnu.org Resent-Date: Sun, 28 Jan 2024 10:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68524 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68524@debbugs.gnu.org Cc: vagrant@debian.org, Lilah Tascheter , herman@rimm.ee, efraim@flashner.co.il, Efraim Flashner , Vagrant Cascadian X-Debbugs-Original-Xcc: Efraim Flashner , Vagrant Cascadian Received: via spool by 68524-submit@debbugs.gnu.org id=B68524.170643621215311 (code B ref 68524); Sun, 28 Jan 2024 10:04:02 +0000 Received: (at 68524) by debbugs.gnu.org; 28 Jan 2024 10:03:32 +0000 Received: from localhost ([127.0.0.1]:56626 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU20h-0003yq-T1 for submit@debbugs.gnu.org; Sun, 28 Jan 2024 05:03:32 -0500 Received: from sendmail.purelymail.com ([34.202.193.197]:50706) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU20f-0003yO-SO for 68524@debbugs.gnu.org; Sun, 28 Jan 2024 05:03:30 -0500 Authentication-Results: purelymail.com; auth=pass DKIM-Signature: a=rsa-sha256; b=U673TrUCTFscakmyI8GUi6M1eWjyPIKffhlWHqWEPenliP1FXr9T2CW+sMzObgwBDLqpK3uNLJdYq1c/kYUfiVQLpSCjVnXWP1rBWjZ0zfnXaqQzRROLnswvswa49ul6ZPge6DRuzTUoFsocB/bxA2wcR420DBzxbr5smgXfHtyOIaGfDhspohS0l5dNQhgGnGM1kVdpQUig1LzXVgW59EhD2dyBPBsBG0ym2CbDzZ1a7yyBZTsern81bk6KCXs8pVy6CUItybvoqgHyvJ9gtiXL8CNzlu0Sk0VOnGxljBMEc1UHl1eJvbZDbpAGZ1zkruV5s1HEPXylfxMycK4POw==; s=purelymail2; d=lunabee.space; v=1; bh=/0e0X1bfriDa7mztPzwNLhVYDcs7uvRT3P83zy8NFF8=; h=Received:From:To:Subject; DKIM-Signature: a=rsa-sha256; b=uEknK+JL2gwPRkc4ZR3wQ/sP0MDEvbtXr6fvI0fXG4Yi34pjtsFNeiSYRazOSYcNzMJWr2d+QoWZdT9cjY5emniOmVZ2khRQqLaoiGoz/lvuqjPRjhK+jtluwDN3hfuRi+iPBs56jQPxUveNZCtUpY9FSHwJ5ux9oBveK+nxz9xdDXrIXTAQquMZEZLdN6XbtJJ9oWukVyCiDZXnUXG5CQ0iZ/hKr5ZIryPw6d6LjBi5uXhlpe5WNGjq3wUMRL2oXwbHpIzYHBzNx+kRLCBhYGkYjaaoG0dm6iWyw3rsO97FfuCrlo/1svH0N9lKpXM7BJ9ECa4KmqxTfv4jkYMKag==; s=purelymail2; d=purelymail.com; v=1; bh=/0e0X1bfriDa7mztPzwNLhVYDcs7uvRT3P83zy8NFF8=; h=Feedback-ID:Received:From:To:Subject; Feedback-ID: 8937:2070:null:purelymail X-Pm-Original-To: 68524@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1308848491; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 28 Jan 2024 10:03:12 +0000 (UTC) Date: Sun, 28 Jan 2024 03:51:40 -0600 Message-ID: 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 * gnu/packages/bootloaders.scm (systemd-stub-name): New procedure. (systemd-version,systemd-source,systemd-stub,ukify): New variables. Change-Id: I67776ec35d165afebc2eb4b11bea0459259e4bd8 --- gnu/packages/bootloaders.scm | 95 ++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm index 986f0ac035..b0d4979f44 100644 --- a/gnu/packages/bootloaders.scm +++ b/gnu/packages/bootloaders.scm @@ -19,6 +19,7 @@ ;;; Copyright © 2021 Stefan ;;; Copyright © 2022, 2023 Maxim Cournoyer ;;; Copyright © 2023 Herman Rimm +;;; Copyright © 2024 Lilah Tascheter ;;; ;;; This file is part of GNU Guix. ;;; @@ -46,11 +47,13 @@ (define-module (gnu packages bootloaders) #:use-module (gnu packages compression) #:use-module (gnu packages cross-base) #:use-module (gnu packages disk) + #:use-module (gnu packages efi) #:use-module (gnu packages firmware) #:use-module (gnu packages flex) #:use-module (gnu packages fontutils) #:use-module (gnu packages gcc) #:use-module (gnu packages gettext) + #:use-module (gnu packages gperf) #:use-module (gnu packages linux) #:use-module (gnu packages man) #:use-module (gnu packages mtools) @@ -71,11 +74,13 @@ (define-module (gnu packages bootloaders) #:use-module (gnu packages valgrind) #:use-module (gnu packages virtualization) #:use-module (gnu packages xorg) + #:use-module (gnu packages python-crypto) #:use-module (gnu packages python-web) #:use-module (gnu packages python-xyz) #:use-module (guix build-system gnu) #:use-module (guix build-system meson) #:use-module (guix build-system pyproject) + #:use-module (guix build-system python) #:use-module (guix build-system trivial) #:use-module (guix download) #:use-module (guix gexp) @@ -632,6 +637,96 @@ (define-public syslinux ;; Also contains: license:expat license:isc license:zlib))))) +(define systemd-version "255") +(define systemd-source + (origin + (method git-fetch) + (uri (git-reference + (url "https://github.com/systemd/systemd") + (commit (string-append "v" systemd-version)))) + (file-name (git-file-name "systemd" systemd-version)) + (sha256 + (base32 + "1qdyw9g3jgvsbc1aryr11gpc3075w5pg00mqv4pyf3hwixxkwaq6")))) + +(define-public (systemd-stub-name) + (let ((arch (cond ((target-x86-32?) "ia32") + ((target-x86-64?) "x64") + ((target-arm32?) "arm") + ((target-aarch64?) "aa64") + ((target-riscv64?) "riscv64")))) + (string-append "linux" arch ".efi.stub"))) + +(define-public systemd-stub + (package + (name "systemd-stub") + (version systemd-version) + (source systemd-source) + (build-system meson-build-system) + (arguments + (list + #:configure-flags + `(list "-Defi=true" "-Dsbat-distro=guix" + "-Dsbat-distro-generation=1" ; package revision! + "-Dsbat-distro-summary=Guix System" + "-Dsbat-distro-url=https://guix.gnu.org" + ,(string-append "-Dsbat-distro-pkgname=" name) + ,(string-append "-Dsbat-distro-version=" version)) + #:phases + #~(let ((stub #$(string-append "src/boot/efi/" (systemd-stub-name)))) + (modify-phases %standard-phases + (replace 'build + (lambda* (#:key parallel-build? #:allow-other-keys) + (invoke "ninja" stub + "-j" (if parallel-build? + (number->string (parallel-job-count)) "1")))) + (replace 'install + (lambda _ + (install-file stub (string-append #$output "/libexec")))) + (delete 'check))))) + (inputs (list libcap python-pyelftools `(,util-linux "lib"))) + (native-inputs (list gperf pkg-config python-3 python-jinja2)) + (home-page "https://systemd.io") + (synopsis "Unified kernel image UEFI stub") + (description "Simple UEFi boot stub that loads a conjoined kernel image and +supporting data to their proper locations, before chainloading to the kernel. +Supports measured and/or verified boot environments.") + (license license:lgpl2.1+))) + +(define-public ukify + (package + (name "ukify") + (version systemd-version) + (source systemd-source) + (build-system python-build-system) + (arguments + (list #:phases + #~(modify-phases %standard-phases + (replace 'build + (lambda _ + (substitute* "src/ukify/ukify.py" ; added in python 3.11 + (("datetime\\.UTC") "datetime.timezone.utc")))) + (delete 'check) + (replace 'install + (lambda* (#:key inputs #:allow-other-keys) + (let* ((bin (string-append #$output "/bin")) + (file (string-append bin "/ukify")) + (binutils (assoc-ref inputs "binutils")) + (sbsign (assoc-ref inputs "sbsigntools"))) + (mkdir-p bin) + (copy-file "src/ukify/ukify.py" file) + (wrap-program file + `("PATH" ":" prefix + (,(string-append binutils "/bin") + ,(string-append sbsign "/bin")))))))))) + (inputs (list binutils python-cryptography python-pefile sbsigntools)) + (home-page "https://systemd.io") + (synopsis "Unified kernel image UEFI tool") + (description "@command{ukify} joins together a UKI stub, linux kernel, initrd, +kernel arguments, and optional secure boot signatures into a single, UEFI-bootable +image.") + (license license:lgpl2.1+))) + (define-public dtc (package (name "dtc") From patchwork Sun Jan 28 09:51:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lilah Tascheter X-Patchwork-Id: 59507 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 A3E1027BBE2; Sun, 28 Jan 2024 10:04:14 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,FROM_SUSPICIOUS_NTLD,MAILING_LIST_MULTI,PDS_OTHER_BAD_TLD, RCVD_IN_MSPIKE_H5,RCVD_IN_MSPIKE_WL,SPF_HELO_PASS,URIBL_BLOCKED autolearn=no 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 EBA6427BBE9 for ; Sun, 28 Jan 2024 10:04:12 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rU218-0007p9-CE; Sun, 28 Jan 2024 05:03:59 -0500 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 1rU215-0007oV-5o for guix-patches@gnu.org; Sun, 28 Jan 2024 05:03:56 -0500 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 1rU214-0006mc-Tc for guix-patches@gnu.org; Sun, 28 Jan 2024 05:03:54 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1rU21C-00040U-Ff for guix-patches@gnu.org; Sun, 28 Jan 2024 05:04:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#68524] [PATCH v2 2/2] gnu: bootloaders: Add uefi-uki-bootloader. Resent-From: Lilah Tascheter Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 28 Jan 2024 10:04:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 68524 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 68524@debbugs.gnu.org Cc: vagrant@debian.org, Lilah Tascheter , herman@rimm.ee, efraim@flashner.co.il Received: via spool by 68524-submit@debbugs.gnu.org id=B68524.170643621815338 (code B ref 68524); Sun, 28 Jan 2024 10:04:02 +0000 Received: (at 68524) by debbugs.gnu.org; 28 Jan 2024 10:03:38 +0000 Received: from localhost ([127.0.0.1]:56628 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU20n-0003zJ-KI for submit@debbugs.gnu.org; Sun, 28 Jan 2024 05:03:38 -0500 Received: from sendmail.purelymail.com ([34.202.193.197]:38470) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1rU20f-0003yP-TG for 68524@debbugs.gnu.org; Sun, 28 Jan 2024 05:03:33 -0500 Authentication-Results: purelymail.com; auth=pass DKIM-Signature: a=rsa-sha256; b=kUhKC5Nf+fJ6l/lOCHlQqpDckhrg+zkmeLugvtEZg3z4EcXPbSKKQD1qbAiKZQEN36CmA91VA/i+q3/eB6L52x/fqdgV31bCAq8JOcMhoMq5bgNVHXgmahsUGYbqQCRswo7hR3tGqFrMQcJYPYvjYU+ln7Q3pPvQ/JnS2wHqr4ts8HfSUMC9UF4Cy6V464PQBkzqu/YMZ9I5y08cFjxwlBNUXdFB6S5we7JxdAqDJtxqdmcn4H3mbqofXj5261Yz/9w9GF+q+TqlIkp1WvSySe9Lr7tOjTtpOnJEdobdIIIDAjHGpzIr/yRa+qovTxa9OX61CqB3W9m1X4ZNbFGCrQ==; s=purelymail2; d=lunabee.space; v=1; bh=us+EFDXms9fDRtQBeGDoDSsswTmzdHRQy5lzdw8+3gY=; h=Received:From:To:Subject; DKIM-Signature: a=rsa-sha256; b=EGDXT+2aVT7KPMrNo+7HP+Wjppoit2QVachhvPmjPQAXOgTmCvNjD+sUyTvCTeriHQ2MQCBEM+9aGPQA/BUE1XvQnrYyIvfca15o1iutcOZa1Wcv8TDX2RvPb1gXHB+5Y9qqOT3w2rJ9S80oTXi1bZnbC4z3cHAl1Nf5dJ2lRwL/fYzYxJN0cpdNpmPU3ZwuYGvqG7FPRjebgA+rDlFmI+U8rlLWs4X3r8NPUicRvRWY2vlD4+F+14fj8i9aKn5tdtmSMIF/NDS4DcQeZAjZB5PFrCIXVeNpUvcpwnp1geP50o01NGytpcfPVjltqYcYVgrJ3gFuX6KR7fVTVB9wjw==; s=purelymail2; d=purelymail.com; v=1; bh=us+EFDXms9fDRtQBeGDoDSsswTmzdHRQy5lzdw8+3gY=; h=Feedback-ID:Received:From:To:Subject; Feedback-ID: 8937:2070:null:purelymail X-Pm-Original-To: 68524@debbugs.gnu.org Received: by smtp.purelymail.com (Purelymail SMTP) with ESMTPSA id -1308848491; (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384); Sun, 28 Jan 2024 10:03:15 +0000 (UTC) Date: Sun, 28 Jan 2024 03:51:41 -0600 Message-ID: <22f2967a552454baade056c60a37c02e36a048a5.1706435500.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 * doc/guix.texi (Bootloader Configuration)[bootloader,targets]: Document uefi-uki-bootloader and uefi-uki-signed-bootloader. (Keyboard Layout, Networking, and Partitioning)[Disk Partitioning]: Note use of uefi-uki-bootloader and uefi-uki-signed-bootloader. * gnu/bootloader/uki.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add bootloader/uki.scm. Change-Id: I2097da9f3dd35137b3419f6d0545de26d53cb6da --- doc/guix.texi | 45 ++++++++++---- gnu/bootloader/uki.scm | 129 +++++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 163 insertions(+), 12 deletions(-) create mode 100644 gnu/bootloader/uki.scm diff --git a/doc/guix.texi b/doc/guix.texi index c458befb76..30fd5d022b 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -2723,12 +2723,13 @@ Keyboard Layout and Networking and Partitioning for @command{cryptsetup luksFormat}. You can check which key derivation function is being used by a device by running @command{cryptsetup luksDump @var{device}}, and looking for the PBKDF field of your -keyslots. +keyslots. UEFI stub bootloaders, such as @code{uefi-uki-bootloader}, can +however use the default, more secure key derivation function. @end quotation -Assuming you want to store the root partition on @file{/dev/sda2}, the -command sequence to format it as a LUKS2 partition would be along these -lines: +Assuming you want to store the root partition on @file{/dev/sda2} and use GRUB +as your bootloader, the command sequence to format it as a LUKS2 partition would +be along these lines: @example cryptsetup luksFormat --type luks2 --pbkdf pbkdf2 /dev/sda2 @@ -41136,8 +41137,9 @@ Bootloader Configuration The bootloader to use, as a @code{bootloader} object. For now @code{grub-bootloader}, @code{grub-efi-bootloader}, @code{grub-efi-removable-bootloader}, @code{grub-efi-netboot-bootloader}, -@code{grub-efi-netboot-removable-bootloader}, @code{extlinux-bootloader} -and @code{u-boot-bootloader} are supported. +@code{grub-efi-netboot-removable-bootloader}, @code{extlinux-bootloader}, +@code{u-boot-bootloader}, @code{uefi-uki-bootloader}, and +@code{uefi-uki-signed-bootloader} are supported. @cindex ARM, bootloaders @cindex AArch64, bootloaders @@ -41244,6 +41246,25 @@ Bootloader Configuration unbootable. @end quotation +@vindex uefi-uki-bootloader +@code{uefi-uki-bootloader} boots a linux kernel directly through UEFI, without +an intermediary like GRUB. The main practical advantage of this is allowing +root/store encryption without an extra GRUB password entry and slow decryption +step. + +@vindex uefi-uki-signed-bootloader +@code{uefi-uki-signed-bootloader} is like @code{uefi-uki-bootloader}, except +that it is a procedure that returns a bootloader compatible with UEFI secure +boot. You must provide it with two paths: an out-of-store secure boot db +certificate (in PEM format), and out-of-store db key, in that order. + +@quotation Warning +When using @code{uefi-uki-bootloader} or @code{uefi-uki-signed-bootloader}, +@emph{do not} turn off your computer if a system reconfigure failed at +installing the bootloader. Until bootloader installation succeeds, your system +is in an unbootable state. +@end quotation + @item @code{targets} This is a list of strings denoting the targets onto which to install the bootloader. @@ -41252,12 +41273,12 @@ Bootloader Configuration For @code{grub-bootloader}, for example, they should be device names understood by the bootloader @command{installer} command, such as @code{/dev/sda} or @code{(hd0)} (@pxref{Invoking grub-install,,, grub, -GNU GRUB Manual}). For @code{grub-efi-bootloader} and -@code{grub-efi-removable-bootloader} they should be mount -points of the EFI file system, usually @file{/boot/efi}. For -@code{grub-efi-netboot-bootloader}, @code{targets} should be the mount -points corresponding to TFTP root directories served by your TFTP -server. +GNU GRUB Manual}). For @code{grub-efi-bootloader}, +@code{grub-efi-removable-bootloader}, @code{uefi-uki-bootloader}, and +@code{uefi-uki-signed-bootloader}, they should be mount points of the EFI file +system, usually @file{/boot/efi}. For @code{grub-efi-netboot-bootloader}, +@code{targets} should be the mount points corresponding to TFTP root directories +served by your TFTP server. @item @code{menu-entries} (default: @code{'()}) A possibly empty list of @code{menu-entry} objects (see below), denoting diff --git a/gnu/bootloader/uki.scm b/gnu/bootloader/uki.scm new file mode 100644 index 0000000000..0ef62295d6 --- /dev/null +++ b/gnu/bootloader/uki.scm @@ -0,0 +1,129 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2024 Lilah Tascheter +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu bootloader uki) + #:use-module (gnu bootloader) + #:use-module (gnu packages bootloaders) + #:use-module (gnu packages efi) + #:use-module (gnu packages linux) + #:use-module (guix gexp) + #:use-module (guix modules) + #:use-module (srfi srfi-1) + #:export (uefi-uki-bootloader uefi-uki-signed-bootloader)) + +;; config generator makes script creating uki images +;; install runs script +;; install device is path to uefi dir +(define vendor "Guix") +(define script-loc "/boot/install-uki.scm") + +(define* (uefi-uki-configuration-file #:optional cert privkey) + (lambda* (config entries #:key (old-entries '()) #:allow-other-keys) + + (define (menu-entry->args e) + (let* ((boot (bootloader-configuration-bootloader config)) + (stub (bootloader-package boot))) + #~(list "--os-release" #$(menu-entry-label e) + "--linux" #$(menu-entry-linux e) "--initrd" #$(menu-entry-initrd e) + "--cmdline" (string-join (list #$@(menu-entry-linux-arguments e))) + "--stub" #$(file-append stub "/libexec/" (systemd-stub-name)) + #$@(if cert #~("--secureboot-certificate" #$cert) #~()) + #$@(if privkey #~("--secureboot-private-key" #$privkey) #~())))) + + (define (enum-filenames . args) ; same args as iota + (map (lambda (n) (string-append (number->string n) ".efi")) + (apply iota (map length args)))) + + (program-file "install-uki" + (with-imported-modules (source-module-closure '((guix build syscalls) + (guix build utils))) + #~(let* ((target (cadr (command-line))) + (vendir (string-append target "/EFI/" #$vendor)) + (schema (string-append vendir "/boot.mgr")) + (findmnt #$(file-append util-linux "/bin/findmnt")) + (efibootmgr #$(file-append efibootmgr "/sbin/efibootmgr"))) + (use-modules (guix build syscalls) (guix build utils) + (ice-9 popen) (ice-9 textual-ports)) + + (define (out name) (string-append vendir "/" name)) + (define disk + (call-with-port + (open-pipe* OPEN_READ findmnt "-fnro" "SOURCE" "-T" target) + (lambda (port) (get-line port)))) ; only 1 line: the device + + ;; delete all boot entries and files we control + (when (file-exists? schema) + (call-with-input-file schema + (lambda (port) + (for-each (lambda (l) + (unless (string-null? l) + (system* efibootmgr "-B" "-L" l "-q"))) + (string-split (get-string-all port) #\lf))))) + (when (directory-exists? vendir) (delete-file-recursively vendir)) + (mkdir-p vendir) + + (define (install port boot? oos) + (lambda (args label name) + (let ((minbytes (* 2 (stat:size (stat #$script-loc))))) + (put-string port label) + (put-char port #\lf) + (force-output port) ; make sure space is alloc'd + (apply invoke #$(file-append ukify "/bin/ukify") + "build" "-o" (out name) args) + ;; make sure we have enough space for next install-uki.scm + (when (and oos (< (free-disk-space vendir) minbytes)) (oos)) + (invoke efibootmgr (if boot? "-c" "-C") "-L" label "-d" disk + "-l" (string-append "\\EFI\\" #$vendor "\\" name) "-q")))) + + (call-with-output-file schema + (lambda (port) ; prioritize latest UKIs in limited ESP space + (for-each (install port #t #f) + (list #$@(map-in-order menu-entry->args entries)) + (list #$@(map-in-order menu-entry-label entries)) + (list #$@(enum-filenames entries))) + (for-each ; old-entries can fail (out of space) we don't care + (lambda (args label name) + (define (cleanup . _) ; do exit early if out of space tho + (when (file-exists? (out name)) (delete-file (out name))) + (exit)) + (with-exception-handler cleanup + (lambda _ ((install port #f cleanup) args label name)))) + (list #$@(map-in-order menu-entry->args old-entries)) + (list #$@(map-in-order menu-entry-label old-entries)) + (list #$@(enum-filenames old-entries entries)))))))))) + +(define install-uefi-uki + #~(lambda (bootloader target mount-point) + (invoke (string-append mount-point #$script-loc) + (string-append mount-point target)))) + +(define* (make-uefi-uki-bootloader #:optional cert privkey) + (bootloader + (name 'uefi-uki) + (package systemd-stub) + (installer install-uefi-uki) + (disk-image-installer #f) + (configuration-file script-loc) + (configuration-file-generator (uefi-uki-configuration-file cert privkey)))) + +;; IMPORTANT NOTE: if bootloader install fails, do not turn off your computer! until +;; install succeeds, your system is unbootable. +(define uefi-uki-bootloader (make-uefi-uki-bootloader)) +;; use ukify genkey to generate cert and privkey. DO NOT include in store. +(define (uefi-uki-signed-bootloader cert privkey) + (make-uefi-uki-bootloader cert privkey)) diff --git a/gnu/local.mk b/gnu/local.mk index ab63bd5881..0a15251ddf 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -90,6 +90,7 @@ GNU_SYSTEM_MODULES = \ %D%/bootloader/extlinux.scm \ %D%/bootloader/u-boot.scm \ %D%/bootloader/depthcharge.scm \ + %D%/bootloader/uki.scm \ %D%/ci.scm \ %D%/compression.scm \ %D%/home.scm \