From patchwork Sun Aug 4 03:55:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Lilah Tascheter X-Patchwork-Id: 66664 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 2D40027BBE2; Sun, 4 Aug 2024 04:58:35 +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=ham 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 0876527BBEC for ; Sun, 4 Aug 2024 04:58:31 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1saSNO-0007lN-A0; Sat, 03 Aug 2024 23:57:46 -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 1saSNL-0007jE-Ss for guix-patches@gnu.org; Sat, 03 Aug 2024 23:57:43 -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 1saSNL-0004HC-IM for guix-patches@gnu.org; Sat, 03 Aug 2024 23:57: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=8fQVRIcug+29QpjYqGnKWuC0Fa26hbculojoB2ZEVOA=; b=vDbXsi3jgwQVbFsNvSUTml8YwTOSeoY0AoiQZocG/Y+AK7OZe6Y/e+7ExnSAmvjRNoyC1xSjP2iZKd1tBNl8LidjNgzfA99YNtBS/+dUgGTBFm3GUMiVj2p4ee+KX9Nl7hzXkc0DtBjViv4+4oHQB4r86Lqm8/SMf2MiykZg7XFvcFSs2B1HSjidN6DVj2As+hqDSpM9JT0ZnmqALIa8ah4uuyMml+opWKaN/nD0NTbEMr0MdSCHf8Sqd8MDwwuA5absTD+N3zynesWXfirVuAE0TaMeHsccRv9FJDv67legfICiYMXgydiMKaq03yIR1UV580e0BBLm6BOGAVdwPg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1saSNg-0001Ol-0t; Sat, 03 Aug 2024 23:58:04 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72457] [PATCH 11/15] gnu: bootloaders: Add uki-efi-bootloader. Resent-From: Lilah Tascheter Original-Sender: "Debbugs-submit" Resent-CC: lilah@lunabee.space, guix-patches@gnu.org Resent-Date: Sun, 04 Aug 2024 03:58:03 +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 , Lilah Tascheter X-Debbugs-Original-Xcc: Lilah Tascheter Received: via spool by 72457-submit@debbugs.gnu.org id=B72457.17227438355166 (code B ref 72457); Sun, 04 Aug 2024 03:58:03 +0000 Received: (at 72457) by debbugs.gnu.org; 4 Aug 2024 03:57:15 +0000 Received: from localhost ([127.0.0.1]:55181 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saSMs-0001LA-Db for submit@debbugs.gnu.org; Sat, 03 Aug 2024 23:57:14 -0400 Received: from sendmail.purelymail.com ([34.202.193.197]:58156) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1saSMq-0001K3-RS for 72457@debbugs.gnu.org; Sat, 03 Aug 2024 23:57:13 -0400 Authentication-Results: purelymail.com; auth=pass DKIM-Signature: a=rsa-sha256; b=OjInYgaBs1QrEDHsDgmzlSj5o0yueH8D51GvpoY/rc7dE0Khe5j/zELJ6xTbVnSzM7EcoiDTapbsG8H6e+2A4m5hWOo91CYIsFZOTb3w+B9gOKri3QgoS5pne5aV/dUDIAyL0W9i65l0K9Wgw6Z3JsALGk3gmgHImmASzbk36rf4eYoLnKmDDnUCHllP4PZGFLxoxXD88FU/tLDpWJcrLnfwTr5rwLB+I5pL9qQmzhZtidLM4ttTjckcU3pX/TG1u61HpObVpiKoVFTcEzycZG+0lZ1F+wlYyheGfN4a8I+kRrf8Uas0ysF7hviTuKfHY2KDo6Lcn0wtlaHZlrt7Ig==; s=purelymail2; d=lunabee.space; v=1; bh=0BTbtbb1WMn2ImvtBkUNApOZg7gkwwhbtKapC5Ogvig=; h=Received:From:To:Subject:Date; DKIM-Signature: a=rsa-sha256; b=Yv8FPOcxoAt+sgf8wgO5jXs02ouBKMAz7CA0tpxso4taSVvteFpmzSMpmpxDt2aDhVa2mid9O5YI5iGaopxqDuY+NnhTr4qLRZ5fBd+LMbToeq8jjlo/gxUoUMw/bgEfkpCjARE9Gim2eFGkc+cidFvSEbWbYViBk1zOJKpVKH1gd4Zi93+c3vjfxTPqmluFd6nqLh0aLCB9/xSWb/tWohKv3GG624uxk2uvJFf1+QbyFUh+nNoypmJ2HYwFhG9HPH7SJO4rrc6ivrvpCzkNDpQYUVP3lZxlXZKe9nfAMI6kUhnLuTLtkkXR4m1lguTX0rL+EQuHMwpRDZh2UQ7qKQ==; s=purelymail2; d=purelymail.com; v=1; bh=0BTbtbb1WMn2ImvtBkUNApOZg7gkwwhbtKapC5Ogvig=; 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:26 +0000 (UTC) Date: Sat, 3 Aug 2024 22:55:31 -0500 Message-ID: <788156df85ec2c2f955465deaf9557d7a2e774c0.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 * gnu/bootloader.scm (): New keypair field. * gnu/bootloader/uki.scm: New file. * gnu/local.mk (GNU_SYSTEM_MODULES): Add bootloader/uki.scm. Change-Id: I2097da9f3dd35137b3419f6d0545de26d53cb6da --- gnu/bootloader.scm | 3 ++ gnu/bootloader/uki.scm | 96 ++++++++++++++++++++++++++++++++++++++++++ gnu/local.mk | 1 + 3 files changed, 100 insertions(+) create mode 100644 gnu/bootloader/uki.scm diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm index 27b0c51342..a2a70d362f 100644 --- a/gnu/bootloader.scm +++ b/gnu/bootloader.scm @@ -100,6 +100,7 @@ (define-module (gnu bootloader) bootloader-configuration-default-entry bootloader-configuration-efi-removable? bootloader-configuration-32bit? + bootloader-configuration-keypair bootloader-configuration-timeout bootloader-configuration-keyboard-layout bootloader-configuration-theme @@ -523,6 +524,8 @@ (define-record-type* (default #f)) ;bool (32bit? bootloader-configuration-32bit? (default #f)) ;bool + (keypair bootloader-configuration-keypair + (default #f)) ;(cert . priv) pair (timeout bootloader-configuration-timeout (default 5)) ;seconds as integer (keyboard-layout bootloader-configuration-keyboard-layout diff --git a/gnu/bootloader/uki.scm b/gnu/bootloader/uki.scm new file mode 100644 index 0000000000..4871dbe037 --- /dev/null +++ b/gnu/bootloader/uki.scm @@ -0,0 +1,96 @@ +;;; 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 (gnu system boot) + #:use-module (guix gexp) + #:use-module (guix diagnostics) + #:use-module (guix i18n) + #:use-module (guix records) + #:export (uki-efi-bootloader)) + +;; TODO: support 32bit/mixed-mode UEFI. +;; https://github.com/systemd/systemd/issues/17056 may be relevant +(define bootcfg->menu-entry->builder + (match-record-lambda (32bit? theme keypair) + (match-record-lambda + (label linux linux-arguments initrd chain-loader) + ;; support chainloader in order to allow arbitrary signed EFI binaries + (cond + ((and chain-loader keypair) + #~(lambda (dest) + (invoke/quiet #+(sbsigntools "/bin/sbsign") + "--cert" #$(car keypair) "--key" #$(cdr keypair) + "--output" dest #$chain-loader) + (invoke/quiet #+(sbsigntools "/bin/sbverify") + "--cert" #$(car keypair) dest))) + (chain-loader #~(lambda (dest) (copy-file #$chain-loader dest))) + (linux + (let* ((arch (efi-arch #:32? 32bit?)) + (stub (file-append systemd-stub + "/libexec/linux" arch ".efi.stub"))) + #~(lambda (dest) + (invoke/quiet #+(file-append ukify "/bin/ukify") + "build" "--output" dest + "--linux" #$linux "--initrd" #$initrd + "--cmdline" (string-join (list #$@linux-arguments)) + "--os-release" #$label "--stub" #$stub "--efi-arch" #$arch + #$@(if theme #~("--splash" #$theme) '()) + #$@(if keypair #~("--secureboot-certificate" #$(car keypair) + "--secureboot-private-key" #$(cdr keypair)) + '()))))) + (else (leave (G_ "uki-efi-bootloader doesn't support multiboot"))))))) + +;; we cannot use guix's build system to make UKI images for two reasons: +;; 1. signing is necessarily non-reproducable, especially since keys should not +;; be in the store, or else risk being publically accessible. +;; 2. menu-entries may reference files which do not exist in the store. +(define* (install-uki #:key bootloader-config + current-boot-alternative + old-boot-alternatives + #:allow-other-keys) + (define* (menu-entry->plan entry num #:optional (prefix "menu-entry")) + #~(cons* #$((bootcfg->menu-entry->builder bootloader-config) entry) + #$(string-append prefix "-" (number->string num) ".efi") + #$(menu-entry-label entry))) + + (define (boot-alternative->plan alt) + (menu-entry->plan (boot-alternative->menu-entry alt) + (boot-alternative-generation alt) + "generation")) + + (install-efi bootloader-config + (let ((entries (bootloader-configuration-menu-entries bootloader-config))) + #~(list #$(boot-alternative->plan current-boot-alternative) + #$@(map menu-entry->plan entries (iota (length entries))) + #$@(map boot-alternative->plan old-boot-alternatives))))) + + + +(define uki-efi-bootloader + (bootloader + (name 'uki-efi) + (default-targets (list (bootloader-target + (type 'vendir) + (offset 'esp) + (path "EFI/Guix")))) + (installer install-uki))) diff --git a/gnu/local.mk b/gnu/local.mk index 8375e13709..32ed753ee2 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -93,6 +93,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 \