| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 |
|
| 20 | (define-module (gnu bootloader extlinux)
|
| 21 | #:use-module (gnu bootloader)
|
| 22 | #:use-module (gnu system)
|
| 23 | #:use-module (gnu build bootloader)
|
| 24 | #:use-module (gnu packages bootloaders)
|
| 25 | #:use-module (guix gexp)
|
| 26 | #:use-module (guix monads)
|
| 27 | #:use-module (guix records)
|
| 28 | #:use-module (guix utils)
|
| 29 | #:export (extlinux-bootloader
|
| 30 | extlinux-bootloader-gpt))
|
| 31 |
|
| 32 | (define* (extlinux-configuration-file config entries
|
| 33 | #:key
|
| 34 | (system (%current-system))
|
| 35 | (old-entries '()))
|
| 36 | "Return the U-Boot configuration file corresponding to CONFIG, a
|
| 37 | <u-boot-configuration> object, and where the store is available at STORE-FS, a
|
| 38 | <file-system> object. OLD-ENTRIES is taken to be a list of menu entries
|
| 39 | corresponding to old generations of the system."
|
| 40 |
|
| 41 | (define all-entries
|
| 42 | (append entries (bootloader-configuration-menu-entries config)))
|
| 43 |
|
| 44 | (define (menu-entry->gexp entry)
|
| 45 | (let ((label (menu-entry-label entry))
|
| 46 | (kernel (menu-entry-linux entry))
|
| 47 | (kernel-arguments (menu-entry-linux-arguments entry))
|
| 48 | (initrd (menu-entry-initrd entry)))
|
| 49 | #~(format port "LABEL ~a
|
| 50 | MENU LABEL ~a
|
| 51 | KERNEL ~a
|
| 52 | FDTDIR ~a/lib/dtbs
|
| 53 | INITRD ~a
|
| 54 | APPEND ~a
|
| 55 | ~%"
|
| 56 | #$label #$label
|
| 57 | #$kernel (dirname #$kernel) #$initrd
|
| 58 | (string-join (list #$@kernel-arguments)))))
|
| 59 |
|
| 60 | (define builder
|
| 61 | #~(call-with-output-file #$output
|
| 62 | (lambda (port)
|
| 63 | (let ((timeout #$(bootloader-configuration-timeout config)))
|
| 64 | (format port "# This file was generated from your GuixSD configuration. Any changes
|
| 65 | # will be lost upon reconfiguration.
|
| 66 | UI menu.c32
|
| 67 | MENU TITLE GuixSD Boot Options
|
| 68 | PROMPT ~a
|
| 69 | TIMEOUT ~a~%"
|
| 70 | (if (> timeout 0) 1 0)
|
| 71 | |
| 72 | (* 10 timeout))
|
| 73 | #$@(map menu-entry->gexp all-entries)
|
| 74 |
|
| 75 | #$@(if (pair? old-entries)
|
| 76 | #~((format port "~%")
|
| 77 | #$@(map menu-entry->gexp old-entries)
|
| 78 | (format port "~%"))
|
| 79 | #~())))))
|
| 80 |
|
| 81 | (gexp->derivation "extlinux.conf" builder))
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
|
| 86 | |
| 87 | |
| 88 | |
| 89 |
|
| 90 | (define (install-extlinux mbr)
|
| 91 | #~(lambda (bootloader device mount-point)
|
| 92 | (let ((extlinux (string-append bootloader "/sbin/extlinux"))
|
| 93 | (install-dir (string-append mount-point "/boot/extlinux"))
|
| 94 | (syslinux-dir (string-append bootloader "/share/syslinux")))
|
| 95 | (for-each (lambda (file)
|
| 96 | (install-file file install-dir))
|
| 97 | (find-files syslinux-dir "\\.c32$"))
|
| 98 | (unless
|
| 99 | (and (zero? (system* extlinux "--install" install-dir))
|
| 100 | (write-file-on-device
|
| 101 | (string-append syslinux-dir "/" #$mbr) 440 device 0))
|
| 102 | (error "failed to install SYSLINUX")))))
|
| 103 |
|
| 104 | (define install-extlinux-mbr
|
| 105 | (install-extlinux "mbr.bin"))
|
| 106 |
|
| 107 | (define install-extlinux-gpt
|
| 108 | (install-extlinux "gptmbr.bin"))
|
| 109 |
|
| 110 |
|
| 111 |
|
| 112 | |
| 113 | |
| 114 | |
| 115 |
|
| 116 | (define extlinux-bootloader
|
| 117 | (bootloader
|
| 118 | (name 'extlinux)
|
| 119 | (package syslinux)
|
| 120 | (installer install-extlinux-mbr)
|
| 121 | (configuration-file "/boot/extlinux/extlinux.conf")
|
| 122 | (configuration-file-generator extlinux-configuration-file)))
|
| 123 |
|
| 124 | (define extlinux-bootloader-gpt
|
| 125 | (bootloader
|
| 126 | (inherit extlinux-bootloader)
|
| 127 | (installer install-extlinux-gpt)))
|