Merge branch 'core-updates'
[jackhill/guix/guix.git] / gnu / system.scm
CommitLineData
033adfe7 1;;; GNU Guix --- Functional package management for GNU
6ce206cb 2;;; Copyright © 2013, 2014 Ludovic Courtès <ludo@gnu.org>
033adfe7
LC
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)
20 #:use-module (guix store)
21 #:use-module (guix monads)
02100028 22 #:use-module (guix gexp)
033adfe7
LC
23 #:use-module (guix records)
24 #:use-module (guix packages)
25 #:use-module (guix derivations)
29fce8b6 26 #:use-module (guix profiles)
033adfe7
LC
27 #:use-module (gnu packages base)
28 #:use-module (gnu packages bash)
bdb36958 29 #:use-module (gnu packages guile)
89a0d00a 30 #:use-module (gnu packages which)
9de46ffb 31 #:use-module (gnu packages admin)
8a07c289 32 #:use-module (gnu packages linux)
033adfe7 33 #:use-module (gnu packages package-management)
6f436c54
LC
34 #:use-module (gnu packages which)
35 #:use-module (gnu packages less)
36 #:use-module (gnu packages zile)
55e70e65
LC
37 #:use-module (gnu packages nano)
38 #:use-module (gnu packages lsof)
a68c6967
LC
39 #:use-module (gnu packages gawk)
40 #:use-module (gnu packages compression)
41 #:autoload (gnu packages cryptsetup) (cryptsetup)
db4fdc04
LC
42 #:use-module (gnu services)
43 #:use-module (gnu services dmd)
44 #:use-module (gnu services base)
033adfe7
LC
45 #:use-module (gnu system grub)
46 #:use-module (gnu system shadow)
47 #:use-module (gnu system linux)
735c6dd7 48 #:use-module (gnu system linux-initrd)
c5df1839 49 #:use-module (gnu system file-systems)
033adfe7
LC
50 #:use-module (ice-9 match)
51 #:use-module (srfi srfi-1)
52 #:use-module (srfi srfi-26)
53 #:export (operating-system
54 operating-system?
d5b429ab
LC
55
56 operating-system-bootloader
033adfe7 57 operating-system-services
217a5b85 58 operating-system-user-services
033adfe7 59 operating-system-packages
fd3bfc44 60 operating-system-host-name
c65e1834 61 operating-system-hosts-file
fd3bfc44
LC
62 operating-system-kernel
63 operating-system-initrd
64 operating-system-users
65 operating-system-groups
548d4c13 66 operating-system-issue
fd3bfc44
LC
67 operating-system-packages
68 operating-system-timezone
69 operating-system-locale
5dae0186 70 operating-system-mapped-devices
83bcd0b8 71 operating-system-file-systems
b25937e3 72 operating-system-activation-script
033adfe7 73
1aa0033b 74 operating-system-derivation
83bcd0b8 75 operating-system-profile
6f436c54
LC
76 operating-system-grub.cfg
77
df5ce088 78 %setuid-programs
5dae0186
LC
79 %base-packages
80
81 luks-device-mapping))
033adfe7
LC
82
83;;; Commentary:
84;;;
85;;; This module supports whole-system configuration.
86;;;
87;;; Code:
88
89;; System-wide configuration.
90;; TODO: Add per-field docstrings/stexi.
91(define-record-type* <operating-system> operating-system
92 make-operating-system
93 operating-system?
94 (kernel operating-system-kernel ; package
95 (default linux-libre))
d5b429ab
LC
96 (bootloader operating-system-bootloader) ; <grub-configuration>
97
83bcd0b8 98 (initrd operating-system-initrd ; (list fs) -> M derivation
060238ae 99 (default base-initrd))
033adfe7
LC
100
101 (host-name operating-system-host-name) ; string
c65e1834
LC
102 (hosts-file operating-system-hosts-file ; M item | #f
103 (default #f))
033adfe7 104
5dae0186
LC
105 (mapped-devices operating-system-mapped-devices ; list of <mapped-device>
106 (default '()))
8a6d2731 107 (file-systems operating-system-file-systems) ; list of fs
2a13d05e
LC
108 (swap-devices operating-system-swap-devices ; list of strings
109 (default '()))
033adfe7
LC
110
111 (users operating-system-users ; list of user accounts
112 (default '()))
113 (groups operating-system-groups ; list of user groups
773e956d 114 (default %base-groups))
033adfe7 115
40281c54
LC
116 (skeletons operating-system-skeletons ; list of name/monadic value
117 (default (default-skeletons)))
548d4c13
LC
118 (issue operating-system-issue ; string
119 (default %default-issue))
40281c54 120
033adfe7 121 (packages operating-system-packages ; list of (PACKAGE OUTPUT...)
6f436c54 122 (default %base-packages)) ; or just PACKAGE
033adfe7
LC
123
124 (timezone operating-system-timezone) ; string
8a6d2731
LC
125 (locale operating-system-locale ; string
126 (default "en_US.UTF-8"))
033adfe7 127
217a5b85 128 (services operating-system-user-services ; list of monadic services
09e028f4
LC
129 (default %base-services))
130
131 (pam-services operating-system-pam-services ; list of PAM services
132 (default (base-pam-services)))
133 (setuid-programs operating-system-setuid-programs
69689380 134 (default %setuid-programs)) ; list of string-valued gexps
033adfe7 135
69689380
LC
136 (sudoers operating-system-sudoers ; /etc/sudoers contents
137 (default %sudoers-specification)))
033adfe7 138
2717a89a 139\f
033adfe7
LC
140;;;
141;;; Derivation.
142;;;
143
23f6056b 144(define* (file-union name files)
033adfe7
LC
145 "Return a derivation that builds a directory containing all of FILES. Each
146item in FILES must be a list where the first element is the file name to use
23f6056b
LC
147in the new directory, and the second element is a gexp denoting the target
148file."
149 (define builder
150 #~(begin
151 (mkdir #$output)
152 (chdir #$output)
153 #$@(map (match-lambda
154 ((target source)
155 #~(symlink #$source #$target)))
156 files)))
033adfe7 157
23f6056b 158 (gexp->derivation name builder))
033adfe7 159
40281c54
LC
160\f
161;;;
162;;; Services.
163;;;
164
722554a3 165(define (open-luks-device source target)
5dae0186
LC
166 "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
167'cryptsetup'."
168 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
169 "open" "--type" "luks"
170 #$source #$target)))
171
722554a3
LC
172(define (close-luks-device source target)
173 "Return a gexp that closes TARGET, a LUKS device."
174 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
175 "close" #$target)))
176
177(define luks-device-mapping
178 ;; The type of LUKS mapped devices.
179 (mapped-device-kind
180 (open open-luks-device)
181 (close close-luks-device)))
182
023f391c
LC
183(define (other-file-system-services os)
184 "Return file system services for the file systems of OS that are not marked
185as 'needed-for-boot'."
186 (define file-systems
187 (remove (lambda (fs)
188 (or (file-system-needed-for-boot? fs)
189 (string=? "/" (file-system-mount-point fs))))
190 (operating-system-file-systems os)))
191
5dae0186
LC
192 (define (device-mappings fs)
193 (filter (lambda (md)
194 (string=? (string-append "/dev/mapper/"
195 (mapped-device-target md))
196 (file-system-device fs)))
197 (operating-system-mapped-devices os)))
198
199 (define (requirements fs)
200 (map (lambda (md)
201 (symbol-append 'device-mapping-
202 (string->symbol (mapped-device-target md))))
203 (device-mappings fs)))
204
023f391c 205 (sequence %store-monad
5dae0186
LC
206 (map (lambda (fs)
207 (match fs
208 (($ <file-system> device title target type flags opts
209 #f check? create?)
210 (file-system-service device target type
211 #:title title
212 #:requirements (requirements fs)
213 #:check? check?
214 #:create-mount-point? create?
215 #:options opts
216 #:flags flags))))
023f391c
LC
217 file-systems)))
218
de1c158f
LC
219(define (mapped-device-user device file-systems)
220 "Return a file system among FILE-SYSTEMS that uses DEVICE, or #f."
221 (let ((target (string-append "/dev/mapper/" (mapped-device-target device))))
222 (find (lambda (fs)
223 (string=? (file-system-device fs) target))
224 file-systems)))
225
226(define (operating-system-user-mapped-devices os)
227 "Return the subset of mapped devices that can be installed in
228user-land--i.e., those not needed during boot."
229 (let ((devices (operating-system-mapped-devices os))
230 (file-systems (operating-system-file-systems os)))
231 (filter (lambda (md)
232 (let ((user (mapped-device-user md file-systems)))
233 (or (not user)
234 (not (file-system-needed-for-boot? user)))))
235 devices)))
236
237(define (operating-system-boot-mapped-devices os)
238 "Return the subset of mapped devices that must be installed during boot,
239from the initrd."
240 (let ((devices (operating-system-mapped-devices os))
241 (file-systems (operating-system-file-systems os)))
242 (filter (lambda (md)
243 (let ((user (mapped-device-user md file-systems)))
244 (and user (file-system-needed-for-boot? user))))
245 devices)))
246
5dae0186
LC
247(define (device-mapping-services os)
248 "Return the list of device-mapping services for OS as a monadic list."
249 (sequence %store-monad
250 (map (lambda (md)
722554a3
LC
251 (let* ((source (mapped-device-source md))
252 (target (mapped-device-target md))
253 (type (mapped-device-type md))
254 (open (mapped-device-kind-open type))
255 (close (mapped-device-kind-close type)))
5dae0186 256 (device-mapping-service target
722554a3
LC
257 (open source target)
258 (close source target))))
de1c158f 259 (operating-system-user-mapped-devices os))))
5dae0186 260
2a13d05e
LC
261(define (swap-services os)
262 "Return the list of swap services for OS as a monadic list."
263 (sequence %store-monad
264 (map swap-service (operating-system-swap-devices os))))
265
217a5b85
LC
266(define (essential-services os)
267 "Return the list of essential services for OS. These are special services
268that implement part of what's declared in OS are responsible for low-level
269bookkeeping."
5dae0186
LC
270 (mlet* %store-monad ((mappings (device-mapping-services os))
271 (root-fs (root-file-system-service))
023f391c 272 (other-fs (other-file-system-services os))
2a13d05e 273 (swaps (swap-services os))
023f391c
LC
274 (procs (user-processes-service
275 (map (compose first service-provision)
276 other-fs)))
277 (host-name (host-name-service
278 (operating-system-host-name os))))
5dae0186 279 (return (cons* host-name procs root-fs
2a13d05e 280 (append other-fs mappings swaps)))))
217a5b85
LC
281
282(define (operating-system-services os)
283 "Return all the services of OS, including \"internal\" services that do not
284explicitly appear in OS."
285 (mlet %store-monad
286 ((user (sequence %store-monad (operating-system-user-services os)))
287 (essential (essential-services os)))
288 (return (append essential user))))
289
40281c54
LC
290\f
291;;;
292;;; /etc.
293;;;
294
6f436c54
LC
295(define %base-packages
296 ;; Default set of packages globally visible. It should include anything
297 ;; required for basic administrator tasks.
55e70e65 298 (cons* procps psmisc which less zile nano
bdb36958 299 (@ (gnu packages admin) dmd) guix
55e70e65 300 lsof ;for Guix's 'list-runtime-roots'
a68c6967 301 util-linux inetutils isc-dhcp wireless-tools
9b762b8d 302 net-tools ; XXX: remove when Inetutils suffices
03e9998f
LC
303
304 ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev
305 ;; already depends on it anyway.
8a7330fd 306 kmod eudev
03e9998f 307
b63dbd44 308 e2fsprogs kbd
9b762b8d
LC
309
310 ;; The packages below are also in %FINAL-INPUTS, so take them from
311 ;; there to avoid duplication.
312 (map canonical-package
a68c6967 313 (list guile-2.0 bash coreutils findutils grep sed
ba544e78 314 diffutils gawk tar gzip bzip2 xz lzip))))
6f436c54 315
548d4c13
LC
316(define %default-issue
317 ;; Default contents for /etc/issue.
318 "
319This is the GNU system. Welcome.\n")
320
c65e1834
LC
321(define (default-/etc/hosts host-name)
322 "Return the default /etc/hosts file."
323 (text-file "hosts"
7d6a52c0
LC
324 (string-append "127.0.0.1 localhost " host-name "\n"
325 "::1 localhost " host-name "\n")))
c65e1834 326
033adfe7 327(define* (etc-directory #:key
3141a8bd 328 (locale "C") (timezone "Europe/Paris")
548d4c13 329 (issue "Hello!\n")
40281c54 330 (skeletons '())
033adfe7 331 (pam-services '())
b4140694 332 (profile "/run/current-system/profile")
c65e1834 333 hosts-file
69689380 334 (sudoers ""))
033adfe7
LC
335 "Return a derivation that builds the static part of the /etc directory."
336 (mlet* %store-monad
ab6a279a 337 ((pam.d (pam-services->directory pam-services))
69689380 338 (sudoers (text-file "sudoers" sudoers))
033adfe7 339 (login.defs (text-file "login.defs" "# Empty for now.\n"))
9038298c
LC
340 (shells (text-file "shells" ; used by xterm and others
341 "\
342/bin/sh
b4140694
LC
343/run/current-system/profile/bin/sh
344/run/current-system/profile/bin/bash\n"))
548d4c13 345 (issue (text-file "issue" issue))
033adfe7 346
07b08343
LC
347 ;; For now, generate a basic config so that /etc/hosts is honored.
348 (nsswitch (text-file "nsswitch.conf"
349 "hosts: files dns\n"))
350
033adfe7 351 ;; TODO: Generate bashrc from packages' search-paths.
7aec3683 352 (bashrc (text-file* "bashrc" "
c851400b 353export PS1='\\u@\\h \\w\\$ '
3141a8bd
LC
354
355export LC_ALL=\"" locale "\"
356export TZ=\"" timezone "\"
7aec3683 357export TZDIR=\"" tzdata "/share/zoneinfo\"
3141a8bd 358
d3bbe992 359# Tell 'modprobe' & co. where to look for modules.
62f0a479 360export LINUX_MODULE_DIRECTORY=/run/booted-system/kernel/lib/modules
d3bbe992 361
585c6519
LC
362export PATH=$HOME/.guix-profile/bin:/run/current-system/profile/bin
363export PATH=/run/setuid-programs:/run/current-system/profile/sbin:$PATH
033adfe7
LC
364export CPATH=$HOME/.guix-profile/include:" profile "/include
365export LIBRARY_PATH=$HOME/.guix-profile/lib:" profile "/lib
366alias ls='ls -p --color'
367alias ll='ls -l'
40281c54
LC
368"))
369 (skel (skeleton-directory skeletons)))
23f6056b
LC
370 (file-union "etc"
371 `(("services" ,#~(string-append #$net-base "/etc/services"))
372 ("protocols" ,#~(string-append #$net-base "/etc/protocols"))
373 ("rpc" ,#~(string-append #$net-base "/etc/rpc"))
374 ("pam.d" ,#~#$pam.d)
375 ("login.defs" ,#~#$login.defs)
376 ("issue" ,#~#$issue)
07b08343 377 ("nsswitch.conf" ,#~#$nsswitch)
40281c54 378 ("skel" ,#~#$skel)
23f6056b
LC
379 ("shells" ,#~#$shells)
380 ("profile" ,#~#$bashrc)
c65e1834 381 ("hosts" ,#~#$hosts-file)
23f6056b
LC
382 ("localtime" ,#~(string-append #$tzdata "/share/zoneinfo/"
383 #$timezone))
69689380 384 ("sudoers" ,#~#$sudoers)))))
033adfe7 385
1aa0033b 386(define (operating-system-profile os)
29fce8b6
LC
387 "Return a derivation that builds the system profile of OS."
388 (profile-derivation (manifest (map package->manifest-entry
389 (operating-system-packages os)))))
f6a9d048 390
ab6a279a
LC
391(define %root-account
392 ;; Default root account.
393 (user-account
394 (name "root")
395 (password "")
396 (uid 0) (group "root")
397 (comment "System administrator")
398 (home-directory "/root")))
399
0b6f49ef
LC
400(define (operating-system-accounts os)
401 "Return the user accounts for OS, including an obligatory 'root' account."
ab6a279a
LC
402 (define users
403 ;; Make sure there's a root account.
404 (if (find (lambda (user)
405 (and=> (user-account-uid user) zero?))
406 (operating-system-users os))
407 (operating-system-users os)
408 (cons %root-account (operating-system-users os))))
409
217a5b85 410 (mlet %store-monad ((services (operating-system-services os)))
ab6a279a
LC
411 (return (append users
412 (append-map service-user-accounts services)))))
0b6f49ef
LC
413
414(define (operating-system-etc-directory os)
415 "Return that static part of the /etc directory of OS."
033adfe7 416 (mlet* %store-monad
217a5b85 417 ((services (operating-system-services os))
033adfe7
LC
418 (pam-services ->
419 ;; Services known to PAM.
420 (delete-duplicates
09e028f4
LC
421 (append (operating-system-pam-services os)
422 (append-map service-pam-services services))))
40281c54 423 (profile-drv (operating-system-profile os))
c65e1834
LC
424 (skeletons (operating-system-skeletons os))
425 (/etc/hosts (or (operating-system-hosts-file os)
426 (default-/etc/hosts (operating-system-host-name os)))))
62f0a479 427 (etc-directory #:pam-services pam-services
40281c54 428 #:skeletons skeletons
548d4c13 429 #:issue (operating-system-issue os)
0b6f49ef
LC
430 #:locale (operating-system-locale os)
431 #:timezone (operating-system-timezone os)
c65e1834 432 #:hosts-file /etc/hosts
69689380 433 #:sudoers (operating-system-sudoers os)
0b6f49ef 434 #:profile profile-drv)))
033adfe7 435
09e028f4
LC
436(define %setuid-programs
437 ;; Default set of setuid-root programs.
438 (let ((shadow (@ (gnu packages admin) shadow)))
439 (list #~(string-append #$shadow "/bin/passwd")
440 #~(string-append #$shadow "/bin/su")
69689380 441 #~(string-append #$inetutils "/bin/ping")
8a07c289
LC
442 #~(string-append #$sudo "/bin/sudo")
443 #~(string-append #$fuse "/bin/fusermount"))))
69689380
LC
444
445(define %sudoers-specification
446 ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel'
447 ;; group can do anything. See
448 ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>.
449 ;; TODO: Add a declarative API.
450 "root ALL=(ALL) ALL
451%wheel ALL=(ALL) ALL\n")
09e028f4 452
ab6a279a
LC
453(define (user-group->gexp group)
454 "Turn GROUP, a <user-group> object, into a list-valued gexp suitable for
455'active-groups'."
456 #~(list #$(user-group-name group)
457 #$(user-group-password group)
c8fa3426
LC
458 #$(user-group-id group)
459 #$(user-group-system? group)))
ab6a279a
LC
460
461(define (user-account->gexp account)
462 "Turn ACCOUNT, a <user-account> object, into a list-valued gexp suitable for
463'activate-users'."
464 #~`(#$(user-account-name account)
465 #$(user-account-uid account)
466 #$(user-account-group account)
467 #$(user-account-supplementary-groups account)
468 #$(user-account-comment account)
469 #$(user-account-home-directory account)
470 ,#$(user-account-shell account) ; this one is a gexp
459dd9ea
LC
471 #$(user-account-password account)
472 #$(user-account-system? account)))
ab6a279a 473
484a2b3a
LC
474(define (operating-system-activation-script os)
475 "Return the activation script for OS---i.e., the code that \"activates\" the
476stateful part of OS, including user accounts and groups, special directories,
477etc."
09e028f4 478 (define %modules
548f7a8f 479 '((gnu build activation)
8a9e21d1 480 (gnu build linux-boot)
e2f4b305 481 (gnu build file-systems)
548f7a8f 482 (guix build utils)))
09e028f4 483
55ccc388
LC
484 (define (service-activations services)
485 ;; Return the activation scripts for SERVICES.
486 (let ((gexps (filter-map service-activate services)))
487 (sequence %store-monad (map (cut gexp->file "activate-service.scm" <>)
488 gexps))))
489
ab6a279a 490 (mlet* %store-monad ((services (operating-system-services os))
55ccc388 491 (actions (service-activations services))
ab6a279a
LC
492 (etc (operating-system-etc-directory os))
493 (modules (imported-modules %modules))
494 (compiled (compiled-modules %modules))
ab6a279a 495 (accounts (operating-system-accounts os)))
09e028f4
LC
496 (define setuid-progs
497 (operating-system-setuid-programs os))
498
ab6a279a
LC
499 (define user-specs
500 (map user-account->gexp accounts))
501
502 (define groups
503 (append (operating-system-groups os)
504 (append-map service-user-groups services)))
505
506 (define group-specs
507 (map user-group->gexp groups))
508
4654439b 509 (gexp->file "activate"
4dfe6c58
LC
510 #~(begin
511 (eval-when (expand load eval)
512 ;; Make sure 'use-modules' below succeeds.
513 (set! %load-path (cons #$modules %load-path))
514 (set! %load-compiled-path
515 (cons #$compiled %load-compiled-path)))
516
548f7a8f 517 (use-modules (gnu build activation))
4dfe6c58 518
ee248b6a
LC
519 ;; Make sure /bin/sh is valid and current.
520 (activate-/bin/sh
521 (string-append #$(canonical-package bash)
522 "/bin/sh"))
523
4dfe6c58
LC
524 ;; Populate /etc.
525 (activate-etc #$etc)
526
ab6a279a
LC
527 ;; Add users and user groups.
528 (setenv "PATH"
529 (string-append #$(@ (gnu packages admin) shadow)
530 "/sbin"))
531 (activate-users+groups (list #$@user-specs)
532 (list #$@group-specs))
533
09e028f4
LC
534 ;; Activate setuid programs.
535 (activate-setuid-programs (list #$@setuid-progs))
536
55ccc388
LC
537 ;; Run the services' activation snippets.
538 ;; TODO: Use 'load-compiled'.
539 (for-each primitive-load '#$actions)
540
b4140694 541 ;; Set up /run/current-system.
484a2b3a
LC
542 (activate-current-system)))))
543
544(define (operating-system-boot-script os)
545 "Return the boot script for OS---i.e., the code started by the initrd once
546we're running in the final root."
547 (mlet* %store-monad ((services (operating-system-services os))
548 (activate (operating-system-activation-script os))
549 (dmd-conf (dmd-configuration-file services)))
550 (gexp->file "boot"
551 #~(begin
552 ;; Activate the system.
553 ;; TODO: Use 'load-compiled'.
554 (primitive-load #$activate)
555
556 ;; Keep track of the booted system.
557 (false-if-exception (delete-file "/run/booted-system"))
558 (symlink (readlink "/run/current-system")
559 "/run/booted-system")
b4140694 560
26a728eb
LC
561 ;; Close any remaining open file descriptors to be on the
562 ;; safe side. This must be the very last thing we do,
563 ;; because Guile has internal FDs such as 'sleep_pipe'
564 ;; that need to be alive.
565 (let loop ((fd 3))
566 (when (< fd 1024)
567 (false-if-exception (close-fdes fd))
568 (loop (+ 1 fd))))
569
4dfe6c58
LC
570 ;; Start dmd.
571 (execl (string-append #$dmd "/bin/dmd")
572 "dmd" "--config" #$dmd-conf)))))
2106d3fc 573
83bcd0b8
LC
574(define (operating-system-root-file-system os)
575 "Return the root file system of OS."
576 (find (match-lambda
d4c87617 577 (($ <file-system> _ _ "/") #t)
83bcd0b8
LC
578 (_ #f))
579 (operating-system-file-systems os)))
580
b4140694
LC
581(define (operating-system-initrd-file os)
582 "Return a gexp denoting the initrd file of OS."
83bcd0b8
LC
583 (define boot-file-systems
584 (filter (match-lambda
d4c87617 585 (($ <file-system> device title "/")
3c05b4bc 586 #t)
d4c87617
LC
587 (($ <file-system> device title mount-point type flags
588 options boot?)
3c05b4bc 589 boot?))
83bcd0b8
LC
590 (operating-system-file-systems os)))
591
de1c158f
LC
592 (define mapped-devices
593 (operating-system-boot-mapped-devices os))
594
595 (define make-initrd
596 (operating-system-initrd os))
597
598 (mlet %store-monad ((initrd (make-initrd boot-file-systems
599 #:mapped-devices mapped-devices)))
b4140694
LC
600 (return #~(string-append #$initrd "/initrd"))))
601
2d23e6f0
LC
602(define (kernel->grub-label kernel)
603 "Return a label for the GRUB menu entry that boots KERNEL."
604 (string-append "GNU system with "
605 (string-titlecase (package-name kernel)) " "
606 (package-version kernel)
607 " (technology preview)"))
608
fe6e3fe2
LC
609(define* (operating-system-grub.cfg os #:optional (old-entries '()))
610 "Return the GRUB configuration file for OS. Use OLD-ENTRIES to populate the
611\"old entries\" menu."
0b6f49ef 612 (mlet* %store-monad
b4140694 613 ((system (operating-system-derivation os))
83bcd0b8 614 (root-fs -> (operating-system-root-file-system os))
b4140694 615 (kernel -> (operating-system-kernel os))
033adfe7 616 (entries -> (list (menu-entry
2d23e6f0 617 (label (kernel->grub-label kernel))
033adfe7 618 (linux kernel)
f6a7b21d 619 (linux-arguments
83bcd0b8
LC
620 (list (string-append "--root="
621 (file-system-device root-fs))
b4140694
LC
622 #~(string-append "--system=" #$system)
623 #~(string-append "--load=" #$system
624 "/boot")))
625 (initrd #~(string-append #$system "/initrd"))))))
fe6e3fe2
LC
626 (grub-configuration-file (operating-system-bootloader os) entries
627 #:old-entries old-entries)))
b4140694 628
64e40dbb
LC
629(define (operating-system-parameters-file os)
630 "Return a file that describes the boot parameters of OS. The primary use of
631this file is the reconstruction of GRUB menu entries for old configurations."
632 (mlet %store-monad ((initrd (operating-system-initrd-file os))
633 (root -> (operating-system-root-file-system os))
634 (label -> (kernel->grub-label
635 (operating-system-kernel os))))
636 (gexp->file "parameters"
637 #~(boot-parameters (version 0)
638 (label #$label)
639 (root-device #$(file-system-device root))
640 (kernel #$(operating-system-kernel os))
641 (initrd #$initrd)))))
642
b4140694
LC
643(define (operating-system-derivation os)
644 "Return a derivation that builds OS."
645 (mlet* %store-monad
646 ((profile (operating-system-profile os))
647 (etc (operating-system-etc-directory os))
648 (boot (operating-system-boot-script os))
649 (kernel -> (operating-system-kernel os))
64e40dbb
LC
650 (initrd (operating-system-initrd-file os))
651 (params (operating-system-parameters-file os)))
23f6056b 652 (file-union "system"
f6a7b21d 653 `(("boot" ,#~#$boot)
23f6056b 654 ("kernel" ,#~#$kernel)
64e40dbb 655 ("parameters" ,#~#$params)
b4140694 656 ("initrd" ,initrd)
23f6056b 657 ("profile" ,#~#$profile)
23f6056b 658 ("etc" ,#~#$etc)))))
033adfe7
LC
659
660;;; system.scm ends here