Commit | Line | Data |
---|---|---|
0ded70f3 LC |
1 | ;;; GNU Guix --- Functional package management for GNU |
2 | ;;; Copyright © 2013 Ludovic Courtès <ludo@gnu.org> | |
3 | ;;; | |
4 | ;;; This file is part of GNU Guix. | |
5 | ;;; | |
6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
7 | ;;; under the terms of the GNU General Public License as published by | |
8 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
9 | ;;; your option) any later version. | |
10 | ;;; | |
11 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | ;;; GNU General Public License for more details. | |
15 | ;;; | |
16 | ;;; You should have received a copy of the GNU General Public License | |
17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
18 | ||
19 | (define-module (gnu system grub) | |
20 | #:use-module (guix store) | |
21 | #:use-module (guix packages) | |
22 | #:use-module (guix derivations) | |
23 | #:use-module (guix records) | |
24 | #:use-module (ice-9 match) | |
25 | #:use-module (srfi srfi-1) | |
26 | #:export (menu-entry | |
27 | menu-entry? | |
28 | grub-configuration-file)) | |
29 | ||
30 | ;;; Commentary: | |
31 | ;;; | |
32 | ;;; Configuration of GNU GRUB. | |
33 | ;;; | |
34 | ;;; Code: | |
35 | ||
36 | (define-record-type* <menu-entry> | |
37 | menu-entry make-menu-entry | |
38 | menu-entry? | |
39 | (label menu-entry-label) | |
40 | (linux menu-entry-linux) | |
41 | (linux-arguments menu-entry-linux-arguments | |
42 | (default '())) | |
43 | (initrd menu-entry-initrd)) | |
44 | ||
45 | (define* (grub-configuration-file store entries | |
46 | #:key (default-entry 1) (timeout 5) | |
47 | (system (%current-system))) | |
48 | "Return the GRUB configuration file in STORE for ENTRIES, a list of | |
49 | <menu-entry> objects, defaulting to DEFAULT-ENTRY and with the given TIMEOUT." | |
50 | (define prologue | |
51 | (format #f " | |
52 | set default=~a | |
53 | set timeout=~a | |
54 | search.file ~a~%" | |
55 | default-entry timeout | |
56 | (any (match-lambda | |
57 | (($ <menu-entry> _ linux) | |
58 | (let* ((drv (package-derivation store linux system)) | |
59 | (out (derivation-path->output-path drv))) | |
60 | (string-append out "/bzImage")))) | |
61 | entries))) | |
62 | ||
63 | (define entry->text | |
64 | (match-lambda | |
65 | (($ <menu-entry> label linux arguments initrd) | |
66 | (let ((linux-drv (package-derivation store linux system)) | |
67 | (initrd-drv (package-derivation store initrd system))) | |
68 | ;; XXX: Assume that INITRD is a directory containing an 'initrd' file. | |
69 | (format #f "menuentry ~s { | |
70 | linux ~a/bzImage ~a | |
71 | initrd ~a/initrd | |
72 | }~%" | |
73 | label | |
74 | (derivation-path->output-path linux-drv) | |
75 | (string-join arguments) | |
76 | (derivation-path->output-path initrd-drv)))))) | |
77 | ||
78 | (add-text-to-store store "grub.cfg" | |
79 | (string-append prologue | |
80 | (string-concatenate | |
81 | (map entry->text entries))) | |
82 | '())) | |
83 | ||
84 | ;;; grub.scm ends here |