system: Define 'GST_PLUGIN_PATH' in /etc/profile.
[jackhill/guix/guix.git] / gnu / system.scm
CommitLineData
033adfe7 1;;; GNU Guix --- Functional package management for GNU
be681773 2;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
5e738ac2 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
f5a9ffa0 4;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
033adfe7
LC
5;;;
6;;; This file is part of GNU Guix.
7;;;
8;;; GNU Guix is free software; you can redistribute it and/or modify it
9;;; under the terms of the GNU General Public License as published by
10;;; the Free Software Foundation; either version 3 of the License, or (at
11;;; your option) any later version.
12;;;
13;;; GNU Guix is distributed in the hope that it will be useful, but
14;;; WITHOUT ANY WARRANTY; without even the implied warranty of
15;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16;;; GNU General Public License for more details.
17;;;
18;;; You should have received a copy of the GNU General Public License
19;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
20
21(define-module (gnu system)
22 #:use-module (guix store)
23 #:use-module (guix monads)
02100028 24 #:use-module (guix gexp)
033adfe7
LC
25 #:use-module (guix records)
26 #:use-module (guix packages)
27 #:use-module (guix derivations)
29fce8b6 28 #:use-module (guix profiles)
84765839 29 #:use-module (guix ui)
033adfe7
LC
30 #:use-module (gnu packages base)
31 #:use-module (gnu packages bash)
bdb36958 32 #:use-module (gnu packages guile)
9de46ffb 33 #:use-module (gnu packages admin)
8a07c289 34 #:use-module (gnu packages linux)
a96a82d7 35 #:use-module (gnu packages pciutils)
033adfe7 36 #:use-module (gnu packages package-management)
6f436c54
LC
37 #:use-module (gnu packages less)
38 #:use-module (gnu packages zile)
55e70e65
LC
39 #:use-module (gnu packages nano)
40 #:use-module (gnu packages lsof)
a68c6967 41 #:use-module (gnu packages gawk)
18316d86 42 #:use-module (gnu packages man)
a68c6967 43 #:use-module (gnu packages compression)
f34c56be 44 #:use-module (gnu packages firmware)
a68c6967 45 #:autoload (gnu packages cryptsetup) (cryptsetup)
db4fdc04
LC
46 #:use-module (gnu services)
47 #:use-module (gnu services dmd)
48 #:use-module (gnu services base)
033adfe7
LC
49 #:use-module (gnu system grub)
50 #:use-module (gnu system shadow)
996ed739 51 #:use-module (gnu system nss)
598e19dc 52 #:use-module (gnu system locale)
033adfe7 53 #:use-module (gnu system linux)
735c6dd7 54 #:use-module (gnu system linux-initrd)
c5df1839 55 #:use-module (gnu system file-systems)
033adfe7
LC
56 #:use-module (ice-9 match)
57 #:use-module (srfi srfi-1)
58 #:use-module (srfi srfi-26)
598e19dc
LC
59 #:use-module (srfi srfi-34)
60 #:use-module (srfi srfi-35)
033adfe7
LC
61 #:export (operating-system
62 operating-system?
d5b429ab
LC
63
64 operating-system-bootloader
033adfe7 65 operating-system-services
217a5b85 66 operating-system-user-services
033adfe7 67 operating-system-packages
fd3bfc44 68 operating-system-host-name
c65e1834 69 operating-system-hosts-file
fd3bfc44 70 operating-system-kernel
ee2a6304 71 operating-system-kernel-arguments
fd3bfc44
LC
72 operating-system-initrd
73 operating-system-users
74 operating-system-groups
548d4c13 75 operating-system-issue
fd3bfc44
LC
76 operating-system-timezone
77 operating-system-locale
598e19dc 78 operating-system-locale-definitions
5dae0186 79 operating-system-mapped-devices
83bcd0b8 80 operating-system-file-systems
b25937e3 81 operating-system-activation-script
033adfe7 82
1aa0033b 83 operating-system-derivation
83bcd0b8 84 operating-system-profile
6f436c54 85 operating-system-grub.cfg
239db054
DT
86 operating-system-etc-directory
87 operating-system-locale-directory
88 operating-system-boot-script
89
568841d4 90 local-host-aliases
df5ce088 91 %setuid-programs
5dae0186 92 %base-packages
f34c56be 93 %base-firmware
5dae0186
LC
94
95 luks-device-mapping))
033adfe7
LC
96
97;;; Commentary:
98;;;
99;;; This module supports whole-system configuration.
100;;;
101;;; Code:
102
103;; System-wide configuration.
104;; TODO: Add per-field docstrings/stexi.
105(define-record-type* <operating-system> operating-system
106 make-operating-system
107 operating-system?
108 (kernel operating-system-kernel ; package
57082417 109 (default linux-libre))
ee2a6304
LC
110 (kernel-arguments operating-system-kernel-arguments
111 (default '())) ; list of gexps/strings
d5b429ab
LC
112 (bootloader operating-system-bootloader) ; <grub-configuration>
113
83bcd0b8 114 (initrd operating-system-initrd ; (list fs) -> M derivation
060238ae 115 (default base-initrd))
f34c56be
LC
116 (firmware operating-system-firmware ; list of packages
117 (default %base-firmware))
033adfe7
LC
118
119 (host-name operating-system-host-name) ; string
24e02c28 120 (hosts-file operating-system-hosts-file ; file-like | #f
c65e1834 121 (default #f))
033adfe7 122
5dae0186
LC
123 (mapped-devices operating-system-mapped-devices ; list of <mapped-device>
124 (default '()))
8a6d2731 125 (file-systems operating-system-file-systems) ; list of fs
2a13d05e
LC
126 (swap-devices operating-system-swap-devices ; list of strings
127 (default '()))
033adfe7
LC
128
129 (users operating-system-users ; list of user accounts
bf87f38a 130 (default %base-user-accounts))
033adfe7 131 (groups operating-system-groups ; list of user groups
773e956d 132 (default %base-groups))
033adfe7 133
40281c54
LC
134 (skeletons operating-system-skeletons ; list of name/monadic value
135 (default (default-skeletons)))
548d4c13
LC
136 (issue operating-system-issue ; string
137 (default %default-issue))
40281c54 138
033adfe7 139 (packages operating-system-packages ; list of (PACKAGE OUTPUT...)
6f436c54 140 (default %base-packages)) ; or just PACKAGE
033adfe7
LC
141
142 (timezone operating-system-timezone) ; string
8a6d2731 143 (locale operating-system-locale ; string
598e19dc
LC
144 (default "en_US.utf8"))
145 (locale-definitions operating-system-locale-definitions ; list of <locale-definition>
146 (default %default-locale-definitions))
996ed739
LC
147 (name-service-switch operating-system-name-service-switch ; <name-service-switch>
148 (default %default-nss))
033adfe7 149
217a5b85 150 (services operating-system-user-services ; list of monadic services
09e028f4
LC
151 (default %base-services))
152
153 (pam-services operating-system-pam-services ; list of PAM services
154 (default (base-pam-services)))
155 (setuid-programs operating-system-setuid-programs
69689380 156 (default %setuid-programs)) ; list of string-valued gexps
033adfe7 157
f5a9ffa0
AK
158 (sudoers-file operating-system-sudoers-file ; file-like
159 (default %sudoers-specification)))
033adfe7 160
2717a89a 161\f
40281c54
LC
162;;;
163;;; Services.
164;;;
165
722554a3 166(define (open-luks-device source target)
5dae0186
LC
167 "Return a gexp that maps SOURCE to TARGET as a LUKS device, using
168'cryptsetup'."
169 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
170 "open" "--type" "luks"
171 #$source #$target)))
172
722554a3
LC
173(define (close-luks-device source target)
174 "Return a gexp that closes TARGET, a LUKS device."
175 #~(zero? (system* (string-append #$cryptsetup "/sbin/cryptsetup")
176 "close" #$target)))
177
178(define luks-device-mapping
179 ;; The type of LUKS mapped devices.
180 (mapped-device-kind
181 (open open-luks-device)
182 (close close-luks-device)))
183
023f391c
LC
184(define (other-file-system-services os)
185 "Return file system services for the file systems of OS that are not marked
186as 'needed-for-boot'."
187 (define file-systems
4d6b879c 188 (remove file-system-needed-for-boot?
023f391c
LC
189 (operating-system-file-systems os)))
190
5dae0186
LC
191 (define (device-mappings fs)
192 (filter (lambda (md)
193 (string=? (string-append "/dev/mapper/"
194 (mapped-device-target md))
195 (file-system-device fs)))
196 (operating-system-mapped-devices os)))
197
198 (define (requirements fs)
e51710d1
LC
199 ;; XXX: Fiddling with dmd service names is not nice.
200 (append (map (lambda (fs)
201 (symbol-append 'file-system-
202 (string->symbol
203 (file-system-mount-point fs))))
204 (file-system-dependencies fs))
205 (map (lambda (md)
206 (symbol-append 'device-mapping-
207 (string->symbol (mapped-device-target md))))
208 (device-mappings fs))))
5dae0186 209
0adfe95a 210 (map file-system-service file-systems))
023f391c 211
de1c158f
LC
212(define (mapped-device-user device file-systems)
213 "Return a file system among FILE-SYSTEMS that uses DEVICE, or #f."
214 (let ((target (string-append "/dev/mapper/" (mapped-device-target device))))
215 (find (lambda (fs)
216 (string=? (file-system-device fs) target))
217 file-systems)))
218
219(define (operating-system-user-mapped-devices os)
220 "Return the subset of mapped devices that can be installed in
221user-land--i.e., those not needed during boot."
9cb426b8
LC
222 (let ((devices (operating-system-mapped-devices os))
223 (file-systems (operating-system-file-systems os)))
224 (filter (lambda (md)
225 (let ((user (mapped-device-user md file-systems)))
226 (or (not user)
227 (not (file-system-needed-for-boot? user)))))
228 devices)))
de1c158f
LC
229
230(define (operating-system-boot-mapped-devices os)
231 "Return the subset of mapped devices that must be installed during boot,
232from the initrd."
9cb426b8
LC
233 (let ((devices (operating-system-mapped-devices os))
234 (file-systems (operating-system-file-systems os)))
235 (filter (lambda (md)
236 (let ((user (mapped-device-user md file-systems)))
237 (and user (file-system-needed-for-boot? user))))
238 devices)))
de1c158f 239
5dae0186 240(define (device-mapping-services os)
be1c2c54
LC
241 "Return the list of device-mapping services for OS as a list."
242 (map (lambda (md)
243 (let* ((source (mapped-device-source md))
244 (target (mapped-device-target md))
245 (type (mapped-device-type md))
246 (open (mapped-device-kind-open type))
247 (close (mapped-device-kind-close type)))
248 (device-mapping-service target
249 (open source target)
250 (close source target))))
251 (operating-system-user-mapped-devices os)))
5dae0186 252
2a13d05e 253(define (swap-services os)
be1c2c54
LC
254 "Return the list of swap services for OS."
255 (map swap-service (operating-system-swap-devices os)))
2a13d05e 256
0adfe95a 257(define* (essential-services os #:key container?)
217a5b85
LC
258 "Return the list of essential services for OS. These are special services
259that implement part of what's declared in OS are responsible for low-level
0adfe95a
LC
260bookkeeping. CONTAINER? determines whether to return the list of services for
261a container or that of a \"bare metal\" system."
d6e2a622
LC
262 (define known-fs
263 (map file-system-mount-point (operating-system-file-systems os)))
264
be1c2c54
LC
265 (let* ((mappings (device-mapping-services os))
266 (root-fs (root-file-system-service))
267 (other-fs (other-file-system-services os))
268 (unmount (user-unmount-service known-fs))
269 (swaps (swap-services os))
270 (procs (user-processes-service
0adfe95a 271 (map service-parameters other-fs)))
be1c2c54 272 (host-name (host-name-service (operating-system-host-name os))))
0adfe95a
LC
273 (cons* %boot-service
274
275 ;; %DMD-ROOT-SERVICE must come first so that the gexp that execs
276 ;; dmd comes last in the boot script (XXX).
277 %dmd-root-service %activation-service
278
279 (pam-root-service (operating-system-pam-services os))
280 (account-service (append (operating-system-accounts os)
281 (operating-system-groups os))
282 (operating-system-skeletons os))
283 (operating-system-etc-service os)
284 host-name procs root-fs unmount
285 (service setuid-program-service-type
286 (operating-system-setuid-programs os))
287 (append other-fs mappings swaps
288
289 ;; Add the firmware service, unless we are building for a
290 ;; container.
291 (if container?
292 '()
293 (list (service firmware-service-type
294 (operating-system-firmware os))))))))
295
296(define* (operating-system-services os #:key container?)
217a5b85
LC
297 "Return all the services of OS, including \"internal\" services that do not
298explicitly appear in OS."
be1c2c54 299 (append (operating-system-user-services os)
0adfe95a 300 (essential-services os #:container? container?)))
217a5b85 301
40281c54
LC
302\f
303;;;
304;;; /etc.
305;;;
306
f34c56be
LC
307(define %base-firmware
308 ;; Firmware usable by default.
309 (list ath9k-htc-firmware))
310
6f436c54
LC
311(define %base-packages
312 ;; Default set of packages globally visible. It should include anything
313 ;; required for basic administrator tasks.
55e70e65 314 (cons* procps psmisc which less zile nano
bdb36958 315 (@ (gnu packages admin) dmd) guix
55e70e65 316 lsof ;for Guix's 'list-runtime-roots'
a96a82d7 317 pciutils usbutils
be681773
LC
318 util-linux inetutils isc-dhcp
319
320 ;; wireless-tools is deprecated in favor of iw, but it's still what
321 ;; many people are familiar with, so keep it around.
322 iw wireless-tools
323
9b762b8d 324 net-tools ; XXX: remove when Inetutils suffices
18316d86 325 man-db
03e9998f 326
a8a086e3
LC
327 ;; The 'sudo' command is already in %SETUID-PROGRAMS, but we also
328 ;; want the other commands and the man pages (notably because
329 ;; auto-completion in Emacs shell relies on man pages.)
330 sudo
331
03e9998f
LC
332 ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev
333 ;; already depends on it anyway.
8a7330fd 334 kmod eudev
03e9998f 335
b63dbd44 336 e2fsprogs kbd
9b762b8d 337
1d167b6e
LC
338 bash-completion
339
9b762b8d
LC
340 ;; The packages below are also in %FINAL-INPUTS, so take them from
341 ;; there to avoid duplication.
342 (map canonical-package
a68c6967 343 (list guile-2.0 bash coreutils findutils grep sed
4b164c45 344 diffutils patch gawk tar gzip bzip2 xz lzip))))
6f436c54 345
548d4c13
LC
346(define %default-issue
347 ;; Default contents for /etc/issue.
348 "
349This is the GNU system. Welcome.\n")
350
568841d4
LC
351(define (local-host-aliases host-name)
352 "Return aliases for HOST-NAME, to be used in /etc/hosts."
353 (string-append "127.0.0.1 localhost " host-name "\n"
354 "::1 localhost " host-name "\n"))
355
c65e1834
LC
356(define (default-/etc/hosts host-name)
357 "Return the default /etc/hosts file."
24e02c28 358 (plain-file "hosts" (local-host-aliases host-name)))
c65e1834 359
0a051769
LC
360(define (emacs-site-file)
361 "Return the Emacs 'site-start.el' file. That file contains the necessary
362settings for 'guix.el' to work out-of-the-box."
0adfe95a
LC
363 (scheme-file "site-start.el"
364 #~(progn
365 ;; Add the "normal" elisp directory to the search path;
366 ;; guix.el may be there.
367 (add-to-list
368 'load-path
369 "/run/current-system/profile/share/emacs/site-lisp")
0a051769 370
0adfe95a
LC
371 ;; Attempt to load guix.el.
372 (require 'guix-init nil t)
0a051769 373
0adfe95a
LC
374 ;; Attempt to load geiser.
375 (require 'geiser-install nil t))))
0a051769
LC
376
377(define (emacs-site-directory)
378 "Return the Emacs site directory, aka. /etc/emacs."
0adfe95a
LC
379 (computed-file "emacs"
380 #~(begin
381 (mkdir #$output)
382 (chdir #$output)
383 (symlink #$(emacs-site-file) "site-start.el"))))
0a051769 384
8e974b9b
LC
385(define (user-shells os)
386 "Return the list of all the shells used by the accounts of OS. These may be
387gexps or strings."
be1c2c54 388 (map user-account-shell (operating-system-accounts os)))
8e974b9b
LC
389
390(define (shells-file shells)
0adfe95a
LC
391 "Return a file-like object that builds a shell list for use as /etc/shells
392based on SHELLS. /etc/shells is used by xterm, polkit, and other programs."
393 (computed-file "shells"
394 #~(begin
395 (use-modules (srfi srfi-1))
396
397 (define shells
398 (delete-duplicates (list #$@shells)))
399
400 (call-with-output-file #$output
401 (lambda (port)
402 (display "\
8e974b9b
LC
403/bin/sh
404/run/current-system/profile/bin/sh
405/run/current-system/profile/bin/bash\n" port)
0adfe95a
LC
406 (for-each (lambda (shell)
407 (display shell port)
408 (newline port))
409 shells))))))
410
411(define* (operating-system-etc-service os)
412 "Return a <service> that builds containing the static part of the /etc
413directory."
414 (let ((login.defs (plain-file "login.defs" "# Empty for now.\n"))
415
416 (shells (shells-file (user-shells os)))
417 (emacs (emacs-site-directory))
418 (issue (plain-file "issue" (operating-system-issue os)))
419 (nsswitch (plain-file "nsswitch.conf"
420 (name-service-switch->string
421 (operating-system-name-service-switch os))))
422
423 ;; Startup file for POSIX-compliant login shells, which set system-wide
424 ;; environment variables.
425 (profile (mixed-text-file "profile" "\
426export LANG=\"" (operating-system-locale os) "\"
427export TZ=\"" (operating-system-timezone os) "\"
7aec3683 428export TZDIR=\"" tzdata "/share/zoneinfo\"
3141a8bd 429
d3bbe992 430# Tell 'modprobe' & co. where to look for modules.
62f0a479 431export LINUX_MODULE_DIRECTORY=/run/booted-system/kernel/lib/modules
d3bbe992 432
d9959421
LC
433# These variables are honored by OpenSSL (libssl) and Git.
434export SSL_CERT_DIR=/etc/ssl/certs
435export SSL_CERT_FILE=\"$SSL_CERT_DIR/ca-certificates.crt\"
436export GIT_SSL_CAINFO=\"$SSL_CERT_FILE\"
437
c05c4321 438# Crucial variables that could be missing in the profiles' 'etc/profile'
d9959421
LC
439# because they would require combining both profiles.
440# FIXME: See <http://bugs.gnu.org/20255>.
97ab2c0f 441export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man
95f92d4e 442export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info
00239d05
SB
443export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share
444export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg
445
d9959421
LC
446# Ignore the default value of 'PATH'.
447unset PATH
448
449# Load the system profile's settings.
450GUIX_PROFILE=/run/current-system/profile \\
669786da 451. /run/current-system/profile/etc/profile
d9959421
LC
452
453# Prepend setuid programs.
454export PATH=/run/setuid-programs:$PATH
455
507c71d6 456if [ -f \"$HOME/.guix-profile/etc/profile\" ]
d9959421
LC
457then
458 # Load the user profile's settings.
459 GUIX_PROFILE=\"$HOME/.guix-profile\" \\
669786da 460 . \"$HOME/.guix-profile/etc/profile\"
d9959421
LC
461else
462 # At least define this one so that basic things just work
463 # when the user installs their first package.
464 export PATH=\"$HOME/.guix-profile/bin:$PATH\"
465fi
466
0a051769
LC
467# Append the directory of 'site-start.el' to the search path.
468export EMACSLOADPATH=:/etc/emacs
8c9267a4
LC
469
470# By default, applications that use D-Bus, such as Emacs, abort at startup
471# when /etc/machine-id is missing. Make sure these warnings are non-fatal.
472export DBUS_FATAL_WARNINGS=0
3761792c
LC
473
474# Allow Aspell to find dictionaries installed in the user profile.
475export ASPELL_CONF=\"dict-dir $HOME/.guix-profile/lib/aspell\"
1d167b6e 476
4af7c83b
LC
477# Allow GStreamer-based applications to find plugins.
478export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
479
1d167b6e
LC
480if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
481then
482 # Load Bash-specific initialization code.
669786da 483 . /etc/bashrc
1d167b6e 484fi
40281c54 485"))
1d167b6e 486
0adfe95a 487 (bashrc (plain-file "bashrc" "\
1d167b6e
LC
488# Bash-specific initialization.
489
490# The 'bash-completion' package.
491if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
492then
493 # Bash-completion sources ~/.bash_completion. It installs a dynamic
494 # completion loader that searches its own completion files as well
495 # as those in ~/.guix-profile and /run/current-system/profile.
496 source /run/current-system/profile/etc/profile.d/bash_completion.sh
0adfe95a
LC
497fi\n")))
498 (etc-service
499 `(("services" ,#~(string-append #$net-base "/etc/services"))
500 ("protocols" ,#~(string-append #$net-base "/etc/protocols"))
501 ("rpc" ,#~(string-append #$net-base "/etc/rpc"))
502 ("emacs" ,#~#$emacs)
503 ("login.defs" ,#~#$login.defs)
504 ("issue" ,#~#$issue)
505 ("nsswitch.conf" ,#~#$nsswitch)
506 ("shells" ,#~#$shells)
507 ("profile" ,#~#$profile)
508 ("bashrc" ,#~#$bashrc)
509 ("hosts" ,#~#$(or (operating-system-hosts-file os)
510 (default-/etc/hosts (operating-system-host-name os))))
511 ("localtime" ,#~(string-append #$tzdata "/share/zoneinfo/"
512 #$(operating-system-timezone os)))
513 ("sudoers" ,(operating-system-sudoers-file os))))))
033adfe7 514
1aa0033b 515(define (operating-system-profile os)
29fce8b6
LC
516 "Return a derivation that builds the system profile of OS."
517 (profile-derivation (manifest (map package->manifest-entry
518 (operating-system-packages os)))))
f6a9d048 519
ab6a279a
LC
520(define %root-account
521 ;; Default root account.
522 (user-account
523 (name "root")
524 (password "")
525 (uid 0) (group "root")
526 (comment "System administrator")
527 (home-directory "/root")))
528
0b6f49ef 529(define (operating-system-accounts os)
0adfe95a
LC
530 "Return the user accounts for OS, including an obligatory 'root' account,
531and excluding accounts requested by services."
532 ;; Make sure there's a root account.
533 (if (find (lambda (user)
534 (and=> (user-account-uid user) zero?))
535 (operating-system-users os))
536 (operating-system-users os)
537 (cons %root-account (operating-system-users os))))
0b6f49ef 538
84765839
LC
539(define (maybe-string->file file-name thing)
540 "If THING is a string, return a <plain-file> with THING as its content.
541Otherwise just return THING.
542
543This is for backward-compatibility of fields that used to be strings and are
544now file-like objects.."
545 (match thing
546 ((? string?)
547 (warning (_ "using a string for file '~a' is deprecated; \
548use 'plain-file' instead~%")
549 file-name)
550 (plain-file file-name thing))
551 (x
552 x)))
553
24e02c28
LC
554(define (maybe-file->monadic file-name thing)
555 "If THING is a value in %STORE-MONAD, return it as is; otherwise return
556THING in the %STORE-MONAD.
557
558This is for backward-compatibility of fields that used to be monadic values
559and are now file-like objects."
560 (with-monad %store-monad
561 (match thing
562 ((? procedure?)
563 (warning (_ "using a monadic value for '~a' is deprecated; \
564use 'plain-file' instead~%")
565 file-name)
566 thing)
567 (x
568 (return x)))))
569
0b6f49ef
LC
570(define (operating-system-etc-directory os)
571 "Return that static part of the /etc directory of OS."
0adfe95a
LC
572 (etc-directory
573 (fold-services (operating-system-services os)
574 #:target-type etc-service-type)))
033adfe7 575
09e028f4
LC
576(define %setuid-programs
577 ;; Default set of setuid-root programs.
3b65abac 578 (let ((shadow (@ (gnu packages admin) shadow)))
09e028f4
LC
579 (list #~(string-append #$shadow "/bin/passwd")
580 #~(string-append #$shadow "/bin/su")
69689380 581 #~(string-append #$inetutils "/bin/ping")
5b9da1f9 582 #~(string-append #$inetutils "/bin/ping6")
8a07c289 583 #~(string-append #$sudo "/bin/sudo")
3b65abac 584 #~(string-append #$fuse "/bin/fusermount"))))
69689380
LC
585
586(define %sudoers-specification
587 ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel'
588 ;; group can do anything. See
589 ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>.
590 ;; TODO: Add a declarative API.
84765839
LC
591 (plain-file "sudoers" "\
592root ALL=(ALL) ALL
593%wheel ALL=(ALL) ALL\n"))
09e028f4 594
239db054 595(define* (operating-system-activation-script os #:key container?)
484a2b3a
LC
596 "Return the activation script for OS---i.e., the code that \"activates\" the
597stateful part of OS, including user accounts and groups, special directories,
598etc."
0adfe95a
LC
599 (let* ((services (operating-system-services os #:container? container?))
600 (activation (fold-services services
601 #:target-type activation-service-type)))
602 (activation-service->script activation)))
484a2b3a 603
239db054 604(define* (operating-system-boot-script os #:key container?)
484a2b3a 605 "Return the boot script for OS---i.e., the code started by the initrd once
239db054
DT
606we're running in the final root. When CONTAINER? is true, skip all
607hardware-related operations as necessary when booting a Linux container."
0adfe95a
LC
608 (let* ((services (operating-system-services os #:container? container?))
609 (boot (fold-services services)))
610 ;; BOOT is the script as a monadic value.
611 (service-parameters boot)))
2106d3fc 612
83bcd0b8
LC
613(define (operating-system-root-file-system os)
614 "Return the root file system of OS."
615 (find (match-lambda
d4c87617 616 (($ <file-system> _ _ "/") #t)
83bcd0b8
LC
617 (_ #f))
618 (operating-system-file-systems os)))
619
b4140694
LC
620(define (operating-system-initrd-file os)
621 "Return a gexp denoting the initrd file of OS."
83bcd0b8 622 (define boot-file-systems
4d6b879c 623 (filter file-system-needed-for-boot?
83bcd0b8
LC
624 (operating-system-file-systems os)))
625
de1c158f
LC
626 (define mapped-devices
627 (operating-system-boot-mapped-devices os))
628
629 (define make-initrd
630 (operating-system-initrd os))
631
632 (mlet %store-monad ((initrd (make-initrd boot-file-systems
0d275f4a 633 #:linux (operating-system-kernel os)
de1c158f 634 #:mapped-devices mapped-devices)))
b4140694
LC
635 (return #~(string-append #$initrd "/initrd"))))
636
598e19dc
LC
637(define (operating-system-locale-directory os)
638 "Return the directory containing the locales compiled for the definitions
639listed in OS. The C library expects to find it under
640/run/current-system/locale."
641 ;; While we're at it, check whether the locale of OS is defined.
642 (unless (member (operating-system-locale os)
643 (map locale-definition-name
644 (operating-system-locale-definitions os)))
645 (raise (condition
646 (&message (message "system locale lacks a definition")))))
647
648 (locale-directory (operating-system-locale-definitions os)))
649
2d23e6f0
LC
650(define (kernel->grub-label kernel)
651 "Return a label for the GRUB menu entry that boots KERNEL."
42de9608 652 (string-append "GNU with "
2d23e6f0
LC
653 (string-titlecase (package-name kernel)) " "
654 (package-version kernel)
42de9608 655 " (alpha)"))
2d23e6f0 656
fe6e3fe2
LC
657(define* (operating-system-grub.cfg os #:optional (old-entries '()))
658 "Return the GRUB configuration file for OS. Use OLD-ENTRIES to populate the
659\"old entries\" menu."
0b6f49ef 660 (mlet* %store-monad
b4140694 661 ((system (operating-system-derivation os))
83bcd0b8 662 (root-fs -> (operating-system-root-file-system os))
b4140694 663 (kernel -> (operating-system-kernel os))
033adfe7 664 (entries -> (list (menu-entry
2d23e6f0 665 (label (kernel->grub-label kernel))
033adfe7 666 (linux kernel)
f6a7b21d 667 (linux-arguments
ee2a6304
LC
668 (cons* (string-append "--root="
669 (file-system-device root-fs))
670 #~(string-append "--system=" #$system)
671 #~(string-append "--load=" #$system
672 "/boot")
673 (operating-system-kernel-arguments os)))
b4140694 674 (initrd #~(string-append #$system "/initrd"))))))
fe6e3fe2
LC
675 (grub-configuration-file (operating-system-bootloader os) entries
676 #:old-entries old-entries)))
b4140694 677
64e40dbb
LC
678(define (operating-system-parameters-file os)
679 "Return a file that describes the boot parameters of OS. The primary use of
680this file is the reconstruction of GRUB menu entries for old configurations."
681 (mlet %store-monad ((initrd (operating-system-initrd-file os))
682 (root -> (operating-system-root-file-system os))
683 (label -> (kernel->grub-label
684 (operating-system-kernel os))))
685 (gexp->file "parameters"
686 #~(boot-parameters (version 0)
687 (label #$label)
688 (root-device #$(file-system-device root))
689 (kernel #$(operating-system-kernel os))
ee2a6304
LC
690 (kernel-arguments
691 #$(operating-system-kernel-arguments os))
64e40dbb
LC
692 (initrd #$initrd)))))
693
b4140694
LC
694(define (operating-system-derivation os)
695 "Return a derivation that builds OS."
696 (mlet* %store-monad
697 ((profile (operating-system-profile os))
0adfe95a 698 (etc -> (operating-system-etc-directory os))
b4140694
LC
699 (boot (operating-system-boot-script os))
700 (kernel -> (operating-system-kernel os))
64e40dbb 701 (initrd (operating-system-initrd-file os))
598e19dc 702 (locale (operating-system-locale-directory os))
64e40dbb 703 (params (operating-system-parameters-file os)))
0adfe95a
LC
704 (lower-object
705 (file-union "system"
706 `(("boot" ,#~#$boot)
707 ("kernel" ,#~#$kernel)
708 ("parameters" ,#~#$params)
709 ("initrd" ,initrd)
710 ("profile" ,#~#$profile)
711 ("locale" ,#~#$locale) ;used by libc
712 ("etc" ,#~#$etc))))))
033adfe7
LC
713
714;;; system.scm ends here