(define-module (ryan-packages bootloaders) #:use-module ((guix licenses) #:prefix license:) #:use-module (guix gexp) #:use-module (guix packages) #:use-module (guix git-download) #:use-module (guix utils) #:use-module (gnu packages base) #:use-module (gnu packages efi) #:use-module (gnu packages gperf) #:use-module (gnu packages linux) #:use-module (gnu packages pkg-config) #:use-module (gnu packages python) #:use-module (gnu packages python-crypto) #:use-module (gnu packages python-xyz) #:use-module (guix build-system python) #:use-module (guix build-system meson)) (define systemd-version "256.1") (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 "0hjpwmap8vsf0dbpad9rzd2jh02mj0cw6w13ag3j2k61wj2nmlnc")))) (define-public (systemd-stub-name) (let ((arch (cond ((target-x86-32?) "ia32") ((target-arm32?) "arm") ((target-x86-64?) "x64") ((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" "-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"))) ; FIXME - there's a better way to do this (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 kernel image + supporting data to proper locations, then chainloads kernel.") (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" (("datetime\\.UTC") "datetime.timezone.utc")))) (delete 'check) ;; below is becaue of system-error "utime" "~A" ("No such file or directory") (delete 'ensure-no-mtimes-pre-1980) (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 "UKI UEFI Tool") (description "Joins a UKI stub, kernel, initrd, kernel args, and signatures into a single UEFI compatible image.") (license license:lgpl2.1+))) systemd-stub