unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
blob fddf038b8eefb6e66c029ec04616a826d1abf531 7933 bytes (raw)
name: gnu/system/bootloader.scm 	 # note: path name is non-authoritative(*)

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
 
;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2017 David Craven <david@craven.ch>
;;;
;;; 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 <http://www.gnu.org/licenses/>.

(define-module (gnu system bootloader)
  #:use-module (gnu system)
  #:use-module (gnu system grub)
  #:use-module (guix gexp)
  #:use-module (guix packages)
  #:use-module (guix records)
  #:use-module (ice-9 match)
  #:export (bootloader-configuration
            bootloader-configuration?
            bootloader-configuration-bootloader
            bootloader-configuration-device
            bootloader-configuration-menu-entries
            bootloader-configuration-default-entry
            bootloader-configuration-timeout
            bootloader-configuration-file-generator
            bootloader-configuration-file-name
            bootloader-configuration-installer
            bootloader-configuration-additional-configuration

            extlinux-configuration
            grub-configuration
            grub-efi-configuration
            syslinux-configuration

            install-grub
            install-syslinux))

;;; Commentary:
;;;
;;; Generic configuration for bootloaders.
;;;
;;; Code:

(define-record-type* <bootloader-configuration>
  bootloader-configuration make-bootloader-configuration
  bootloader-configuration?
  (bootloader                      bootloader-configuration-bootloader     ; package
                                   (default #f))
  (device                          bootloader-configuration-device         ; string
                                   (default #f))
  (menu-entries                    bootloader-configuration-menu-entries   ; list of <boot-parameters>
                                   (default '()))
  (default-entry                   bootloader-configuration-default-entry  ; integer
                                   (default 0))
  (timeout                         bootloader-configuration-timeout        ; integer
                                   (default 5))
  (configuration-file-name         bootloader-configuration-file-name
                                   (default #f))
  (configuration-file-generator    bootloader-configuration-file-generator ; procedure
                                   (default #f))
  (installer                       bootloader-configuration-installer ; procedure
                                   (default #f))
  (additional-configuration        bootloader-configuration-additional-configuration ; record
                                   (default #f)))

\f

;;;
;;; Extlinux configuration file.
;;;

(define* (extlinux-configuration-file config entries
                                      #:key
                                      (system (%current-system))
                                      (old-entries '()))
  "Return the U-Boot configuration file corresponding to CONFIG, a
<u-boot-configuration> object, and where the store is available at STORE-FS, a
<file-system> object.  OLD-ENTRIES is taken to be a list of menu entries
corresponding to old generations of the system."

  (define all-entries
    (append entries (bootloader-configuration-menu-entries config)))

  (define (boot-parameters->gexp params)
    (let ((label (boot-parameters-label params))
          (kernel (boot-parameters-kernel params))
          (kernel-arguments (boot-parameters-kernel-arguments params))
          (initrd (boot-parameters-initrd params)))
      #~(format port "LABEL ~a
  MENU LABEL ~a
  KERNEL ~a
  FDTDIR ~a/lib/dtbs
  INITRD ~a
  APPEND ~a
~%"
                #$label #$label
                #$kernel #$kernel #$initrd
                (string-join (list #$@kernel-arguments)))))

  (define builder
    #~(call-with-output-file #$output
        (lambda (port)
          (let ((timeout #$(bootloader-configuration-timeout config)))
            (format port "
UI menu.c32
PROMPT ~a
TIMEOUT ~a~%"
                    (if (> timeout 0) 1 0)
                    ;; timeout is expressed in 1/10s of seconds.
                    (* 10 timeout))
            #$@(map boot-parameters->gexp all-entries)

            #$@(if (pair? old-entries)
                   #~((format port "~%")
                      #$@(map boot-parameters->gexp old-entries)
                      (format port "~%"))
                   #~())))))

  (gexp->derivation "extlinux.conf" builder))


\f

;;;
;;; Bootloader configurations.
;;;

(define* (extlinux-configuration #:optional (config (bootloader-configuration)))
  (bootloader-configuration
   (inherit config)
   (configuration-file-name "/boot/extlinux/extlinux.conf")
   (configuration-file-generator extlinux-configuration-file)))

(define* (grub-configuration #:optional (config (bootloader-configuration)))
  (bootloader-configuration
   (inherit config)
   (bootloader (@ (gnu packages bootloaders) grub))
   (configuration-file-name "/boot/grub/grub.cfg")
   (configuration-file-generator grub-configuration-file)
   (installer install-grub)
   (additional-configuration
    (let ((additional-config (bootloader-configuration-additional-configuration config)))
      (if additional-config additional-config %default-theme)))))

(define* (grub-efi-configuration #:optional (config (bootloader-configuration)))
  (bootloader-configuration
   (inherit (grub-configuration config))
   (bootloader (@ (gnu packages bootloaders) grub-efi))))

(define* (syslinux-configuration #:optional (config (bootloader-configuration)))
  (bootloader-configuration
   (inherit (extlinux-configuration config))
   (bootloader (@ (gnu packages bootloaders) syslinux))
   (installer install-syslinux)))

\f

;;;
;;; Bootloader install procedures.
;;;

(define dd
  #~(lambda (bs count if of)
      (zero? (system* "dd"
                      (string-append "bs=" (number->string bs))
                      (string-append "count=" (number->string count))
                      (string-append "if=" if)
                      (string-append "of=" of)))))

(define install-grub
  #~(lambda (bootloader device mount-point)
      ;; Install GRUB on DEVICE which is mounted at MOUNT-POINT.
      (let ((grub (string-append bootloader "/sbin/grub-install"))
            (install-dir (string-append mount-point "/boot")))
        ;; Tell 'grub-install' that there might be a LUKS-encrypted /boot or
        ;; root partition.
        (setenv "GRUB_ENABLE_CRYPTODISK" "y")

        (unless (zero? (system* grub "--no-floppy"
                                "--boot-directory" install-dir
                                device))
          (error "failed to install GRUB")))))

(define install-syslinux
  #~(lambda (bootloader device mount-point)
      (let ((extlinux (string-append bootloader "/sbin/extlinux"))
            (install-dir (string-append mount-point "/boot/extlinux"))
            (syslinux-dir (string-append bootloader "/share/syslinux")))
        (mkdir-p install-dir)
        (for-each (lambda (file)
                    (copy-file file
                               (string-append install-dir "/" (basename file))))
                  (find-files syslinux-dir "\\.c32$"))

        (unless (and (zero? (system* extlinux "--install" install-dir))
                     (#$dd 440 1 (string-append syslinux-dir "/mbr.bin") device))
          (error "failed to install SYSLINUX")))))

;;; bootloader.scm ends here

debug log:

solving fddf038b8 ...
found fddf038b8 in https://yhetil.org/guix-patches/20170506154154.17836-3-m.othacehe@gmail.com/ ||
	https://yhetil.org/guix-patches/20170417090148.13791-5-m.othacehe@gmail.com/
found ea067bf73 in https://yhetil.org/guix-patches/20170506154154.17836-2-m.othacehe@gmail.com/ ||
	https://yhetil.org/guix-patches/20170417090148.13791-3-m.othacehe@gmail.com/

applying [1/2] https://yhetil.org/guix-patches/20170506154154.17836-2-m.othacehe@gmail.com/
diff --git a/gnu/system/bootloader.scm b/gnu/system/bootloader.scm
new file mode 100644
index 000000000..ea067bf73

Checking patch gnu/system/bootloader.scm...
Applied patch gnu/system/bootloader.scm cleanly.

skipping https://yhetil.org/guix-patches/20170417090148.13791-3-m.othacehe@gmail.com/ for ea067bf73
index at:
100644 ea067bf735c4af30114cfe415ae4c29e1b3e791f	gnu/system/bootloader.scm

applying [2/2] https://yhetil.org/guix-patches/20170506154154.17836-3-m.othacehe@gmail.com/
diff --git a/gnu/system/bootloader.scm b/gnu/system/bootloader.scm
index ea067bf73..fddf038b8 100644

Checking patch gnu/system/bootloader.scm...
Applied patch gnu/system/bootloader.scm cleanly.

skipping https://yhetil.org/guix-patches/20170417090148.13791-5-m.othacehe@gmail.com/ for fddf038b8
index at:
100644 fddf038b8eefb6e66c029ec04616a826d1abf531	gnu/system/bootloader.scm

(*) Git path names are given by the tree(s) the blob belongs to.
    Blobs themselves have no identifier aside from the hash of its contents.^

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).