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