diff mbox series

[bug#72457,10/15] gnu: packages: Add systemd-stub.

Message ID 618b4d4f364fbc2450df50380cbf457c5ac1e3aa.1722741997.git.lilah@lunabee.space
State New
Headers show
Series Rewrite bootloader subsystem. | expand

Commit Message

Lilah Tascheter Aug. 4, 2024, 3:55 a.m. UTC
* gnu/bootloader.scm (%efi-supported-systems, lazy-efibootmgr): New variable.
  (install-efi): Use lazy-efibootmgr.
* gnu/packages/bootloaders.scm (systemd-stub): New variable.

Change-Id: I974bad9ff7a52f736286d05de53f7c5ccb60b9d6
---
 gnu/bootloader.scm           | 13 +++++++++--
 gnu/packages/bootloaders.scm | 43 ++++++++++++++++++++++++++++++++++++
 2 files changed, 54 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/gnu/bootloader.scm b/gnu/bootloader.scm
index 2bb13437dc..27b0c51342 100644
--- a/gnu/bootloader.scm
+++ b/gnu/bootloader.scm
@@ -28,7 +28,6 @@  (define-module (gnu bootloader)
   #:autoload   (gnu build file-systems)
                (read-partition-label read-partition-uuid
                 find-partition-by-label find-partition-by-uuid)
-  #:use-module (gnu packages linux)
   #:use-module (gnu system file-systems)
   #:use-module (gnu system uuid)
   #:autoload   (guix build syscalls)
@@ -114,6 +113,7 @@  (define-module (gnu bootloader)
             bootloader-configuration->gexp
             bootloader-configurations->gexp
 
+            %efi-supported-systems
             efi-arch
             install-efi))
 
@@ -633,6 +633,11 @@  (define (bootloader-configurations->gexp bootloader-configs . rest)
 ;;; EFI shit
 ;;;
 
+;; systems currently supported by efi-arch. should be used for packages relying
+;; on it.
+(define %efi-supported-systems
+  '("i686-linux" "x86_64-linux" "armhf-linux" "aarch64-linux" "riscv64-linux"))
+
 (define* (efi-arch #:key (target (or (%current-target-system) (%current-system)))
                          (32? #f))
   "Returns the UEFI architecture name for the current target, in lowercase."
@@ -644,6 +649,10 @@  (define* (efi-arch #:key (target (or (%current-target-system) (%current-system))
         (else (raise (formatted-message (G_ "no UEFI standard arch for ~a!")
                                         target)))))
 
+(define (lazy-efibootmgr)
+  "Lazy-loaded efibootmgr package, in order to prevent circular refs."
+  (module-ref (resolve-interface '(gnu packages linux)) 'efibootmgr))
+
 (define (install-efi bootloader-config plan)
   "Returns a gexp installing PLAN to the ESP, as denoted by the 'vendir target.
 PLAN is a gexp of a list of '(BUILDER DEST-BASENAME . LABEL) triples, that
@@ -666,5 +675,5 @@  (define (install-efi bootloader-config plan)
       ;; normal install when not doing a removable config
       (with-targets targets
         (('vendir => (vendir :path) (loader :devpath) (disk :device))
-         #~(install-efi #+(file-append efibootmgr "/sbin/efibootmgr")
+         #~(install-efi #+(file-append (lazy-efibootmgr) "/sbin/efibootmgr")
                         #$vendir #$loader #$disk #$plan))))))
diff --git a/gnu/packages/bootloaders.scm b/gnu/packages/bootloaders.scm
index 04bb1b06f0..2bc04059d2 100644
--- a/gnu/packages/bootloaders.scm
+++ b/gnu/packages/bootloaders.scm
@@ -38,6 +38,7 @@ 
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (gnu packages bootloaders)
+  #:use-module (gnu bootloader)
   #:use-module (gnu packages)
   #:use-module (gnu packages assembly)
   #:use-module (gnu packages base)
@@ -54,6 +55,7 @@  (define-module (gnu packages bootloaders)
   #: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 llvm)
   #:use-module (gnu packages man)
@@ -592,6 +594,47 @@  (define systemd-source
       (base32
         "1qdyw9g3jgvsbc1aryr11gpc3075w5pg00mqv4pyf3hwixxkwaq6"))))
 
+(define-public systemd-stub
+  (package
+    (name "systemd-stub")
+    (version systemd-version)
+    (source systemd-source)
+    (build-system meson-build-system)
+    (arguments
+      (list #:configure-flags
+            #~(list "-Dmode=release" "-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="
+                        (package-name this-package))
+                    #$(string-append "-Dsbat-distro-version="
+                        (package-version this-package)))
+            #:phases
+            ;; TODO: 32bit support
+            (let* ((stub (string-append
+                           "src/boot/efi/linux" (efi-arch) ".efi.stub")))
+              #~(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 _
+                      (let ((libexec (string-append #$output "/libexec")))
+                        (install-file #$stub libexec))))
+                  (delete 'check)))))
+    (supported-systems %efi-supported-systems)
+    (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")