tests: Add system installation test.
[jackhill/guix/guix.git] / gnu / system.scm
CommitLineData
033adfe7 1;;; GNU Guix --- Functional package management for GNU
29824d80 2;;; Copyright © 2013, 2014, 2015, 2016 Ludovic Courtès <ludo@gnu.org>
5e738ac2 3;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
5dccaffe 4;;; Copyright © 2015, 2016 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)
939c5c31 43 #:use-module (gnu packages texinfo)
a68c6967 44 #:use-module (gnu packages compression)
f34c56be 45 #:use-module (gnu packages firmware)
db4fdc04 46 #:use-module (gnu services)
0190c1c0 47 #:use-module (gnu services shepherd)
db4fdc04 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)
6e828634 53 #:use-module (gnu system pam)
735c6dd7 54 #:use-module (gnu system linux-initrd)
c5df1839 55 #:use-module (gnu system file-systems)
060d62a7 56 #:use-module (gnu system mapped-devices)
033adfe7
LC
57 #:use-module (ice-9 match)
58 #:use-module (srfi srfi-1)
59 #:use-module (srfi srfi-26)
598e19dc
LC
60 #:use-module (srfi srfi-34)
61 #:use-module (srfi srfi-35)
033adfe7
LC
62 #:export (operating-system
63 operating-system?
d5b429ab
LC
64
65 operating-system-bootloader
033adfe7 66 operating-system-services
217a5b85 67 operating-system-user-services
033adfe7 68 operating-system-packages
fd3bfc44 69 operating-system-host-name
c65e1834 70 operating-system-hosts-file
fd3bfc44 71 operating-system-kernel
ee2a6304 72 operating-system-kernel-arguments
fd3bfc44
LC
73 operating-system-initrd
74 operating-system-users
75 operating-system-groups
548d4c13 76 operating-system-issue
fd3bfc44
LC
77 operating-system-timezone
78 operating-system-locale
598e19dc 79 operating-system-locale-definitions
34760ae7 80 operating-system-locale-libcs
5dae0186 81 operating-system-mapped-devices
83bcd0b8 82 operating-system-file-systems
6b779207 83 operating-system-store-file-system
b25937e3 84 operating-system-activation-script
b2fef041
LC
85 operating-system-user-accounts
86 operating-system-shepherd-service-names
033adfe7 87
1aa0033b 88 operating-system-derivation
83bcd0b8 89 operating-system-profile
6f436c54 90 operating-system-grub.cfg
239db054
DT
91 operating-system-etc-directory
92 operating-system-locale-directory
93 operating-system-boot-script
94
b8300494
AK
95 boot-parameters
96 boot-parameters?
97 boot-parameters-label
98 boot-parameters-root-device
99 boot-parameters-kernel
100 boot-parameters-kernel-arguments
101 read-boot-parameters
102
568841d4 103 local-host-aliases
df5ce088 104 %setuid-programs
5dae0186 105 %base-packages
374f14c2 106 %base-firmware))
033adfe7
LC
107
108;;; Commentary:
109;;;
110;;; This module supports whole-system configuration.
111;;;
112;;; Code:
113
114;; System-wide configuration.
115;; TODO: Add per-field docstrings/stexi.
116(define-record-type* <operating-system> operating-system
117 make-operating-system
118 operating-system?
119 (kernel operating-system-kernel ; package
57082417 120 (default linux-libre))
ee2a6304
LC
121 (kernel-arguments operating-system-kernel-arguments
122 (default '())) ; list of gexps/strings
d5b429ab
LC
123 (bootloader operating-system-bootloader) ; <grub-configuration>
124
83bcd0b8 125 (initrd operating-system-initrd ; (list fs) -> M derivation
060238ae 126 (default base-initrd))
f34c56be
LC
127 (firmware operating-system-firmware ; list of packages
128 (default %base-firmware))
033adfe7
LC
129
130 (host-name operating-system-host-name) ; string
24e02c28 131 (hosts-file operating-system-hosts-file ; file-like | #f
c65e1834 132 (default #f))
033adfe7 133
5dae0186
LC
134 (mapped-devices operating-system-mapped-devices ; list of <mapped-device>
135 (default '()))
8a6d2731 136 (file-systems operating-system-file-systems) ; list of fs
2a13d05e
LC
137 (swap-devices operating-system-swap-devices ; list of strings
138 (default '()))
033adfe7
LC
139
140 (users operating-system-users ; list of user accounts
bf87f38a 141 (default %base-user-accounts))
033adfe7 142 (groups operating-system-groups ; list of user groups
773e956d 143 (default %base-groups))
033adfe7 144
40281c54
LC
145 (skeletons operating-system-skeletons ; list of name/monadic value
146 (default (default-skeletons)))
548d4c13
LC
147 (issue operating-system-issue ; string
148 (default %default-issue))
40281c54 149
033adfe7 150 (packages operating-system-packages ; list of (PACKAGE OUTPUT...)
6f436c54 151 (default %base-packages)) ; or just PACKAGE
033adfe7
LC
152
153 (timezone operating-system-timezone) ; string
8a6d2731 154 (locale operating-system-locale ; string
598e19dc
LC
155 (default "en_US.utf8"))
156 (locale-definitions operating-system-locale-definitions ; list of <locale-definition>
157 (default %default-locale-definitions))
34760ae7
LC
158 (locale-libcs operating-system-locale-libcs ; list of <packages>
159 (default %default-locale-libcs))
996ed739
LC
160 (name-service-switch operating-system-name-service-switch ; <name-service-switch>
161 (default %default-nss))
033adfe7 162
217a5b85 163 (services operating-system-user-services ; list of monadic services
09e028f4
LC
164 (default %base-services))
165
166 (pam-services operating-system-pam-services ; list of PAM services
167 (default (base-pam-services)))
168 (setuid-programs operating-system-setuid-programs
69689380 169 (default %setuid-programs)) ; list of string-valued gexps
033adfe7 170
f5a9ffa0
AK
171 (sudoers-file operating-system-sudoers-file ; file-like
172 (default %sudoers-specification)))
033adfe7 173
2717a89a 174\f
40281c54
LC
175;;;
176;;; Services.
177;;;
178
023f391c
LC
179(define (other-file-system-services os)
180 "Return file system services for the file systems of OS that are not marked
181as 'needed-for-boot'."
182 (define file-systems
4d6b879c 183 (remove file-system-needed-for-boot?
023f391c
LC
184 (operating-system-file-systems os)))
185
5dae0186 186 (define (device-mappings fs)
ab64483f 187 (let ((device (file-system-device fs)))
29824d80 188 (if (string? device) ;title is 'device
ab64483f
LC
189 (filter (lambda (md)
190 (string=? (string-append "/dev/mapper/"
191 (mapped-device-target md))
192 device))
193 (operating-system-mapped-devices os))
194 '())))
5dae0186 195
e502bf89
LC
196 (define (add-dependencies fs)
197 ;; Add the dependencies due to device mappings to FS.
198 (file-system
199 (inherit fs)
200 (dependencies
201 (delete-duplicates (append (device-mappings fs)
202 (file-system-dependencies fs))
203 eq?))))
204
205 (map (compose file-system-service add-dependencies) file-systems))
023f391c 206
de1c158f
LC
207(define (mapped-device-user device file-systems)
208 "Return a file system among FILE-SYSTEMS that uses DEVICE, or #f."
209 (let ((target (string-append "/dev/mapper/" (mapped-device-target device))))
210 (find (lambda (fs)
29824d80
LC
211 (and (eq? 'device (file-system-title fs))
212 (string=? (file-system-device fs) target)))
de1c158f
LC
213 file-systems)))
214
215(define (operating-system-user-mapped-devices os)
216 "Return the subset of mapped devices that can be installed in
217user-land--i.e., those not needed during boot."
9cb426b8
LC
218 (let ((devices (operating-system-mapped-devices os))
219 (file-systems (operating-system-file-systems os)))
220 (filter (lambda (md)
221 (let ((user (mapped-device-user md file-systems)))
222 (or (not user)
223 (not (file-system-needed-for-boot? user)))))
224 devices)))
de1c158f
LC
225
226(define (operating-system-boot-mapped-devices os)
227 "Return the subset of mapped devices that must be installed during boot,
228from the initrd."
9cb426b8
LC
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 (and user (file-system-needed-for-boot? user))))
234 devices)))
de1c158f 235
5dae0186 236(define (device-mapping-services os)
be1c2c54 237 "Return the list of device-mapping services for OS as a list."
4da8c19e 238 (map device-mapping-service
be1c2c54 239 (operating-system-user-mapped-devices os)))
5dae0186 240
2a13d05e 241(define (swap-services os)
be1c2c54
LC
242 "Return the list of swap services for OS."
243 (map swap-service (operating-system-swap-devices os)))
2a13d05e 244
d62e201c
LC
245(define* (operating-system-directory-base-entries os #:key container?)
246 "Return the basic entries of the 'system' directory of OS for use as the
247value of the SYSTEM-SERVICE-TYPE service."
af4c3fd5 248 (mlet %store-monad ((locale (operating-system-locale-directory os)))
d62e201c 249 (if container?
af4c3fd5 250 (return `(("locale" ,locale)))
d62e201c
LC
251 (mlet %store-monad
252 ((kernel -> (operating-system-kernel os))
253 (initrd (operating-system-initrd-file os))
254 (params (operating-system-parameters-file os)))
255 (return `(("kernel" ,kernel)
256 ("parameters" ,params)
257 ("initrd" ,initrd)
d62e201c
LC
258 ("locale" ,locale))))))) ;used by libc
259
0adfe95a 260(define* (essential-services os #:key container?)
217a5b85
LC
261 "Return the list of essential services for OS. These are special services
262that implement part of what's declared in OS are responsible for low-level
0adfe95a
LC
263bookkeeping. CONTAINER? determines whether to return the list of services for
264a container or that of a \"bare metal\" system."
d6e2a622
LC
265 (define known-fs
266 (map file-system-mount-point (operating-system-file-systems os)))
267
be1c2c54
LC
268 (let* ((mappings (device-mapping-services os))
269 (root-fs (root-file-system-service))
270 (other-fs (other-file-system-services os))
271 (unmount (user-unmount-service known-fs))
272 (swaps (swap-services os))
273 (procs (user-processes-service
0adfe95a 274 (map service-parameters other-fs)))
d62e201c
LC
275 (host-name (host-name-service (operating-system-host-name os)))
276 (entries (operating-system-directory-base-entries
277 os #:container? container?)))
278 (cons* (service system-service-type entries)
279 %boot-service
0adfe95a 280
d4053c71
AK
281 ;; %SHEPHERD-ROOT-SERVICE must come first so that the gexp that
282 ;; execs shepherd comes last in the boot script (XXX). Likewise,
283 ;; the cleanup service must come last so that its gexp runs before
284 ;; activation code.
285 %shepherd-root-service
be7be9e8
LC
286 %activation-service
287 (service cleanup-service-type #f)
0adfe95a
LC
288
289 (pam-root-service (operating-system-pam-services os))
290 (account-service (append (operating-system-accounts os)
291 (operating-system-groups os))
292 (operating-system-skeletons os))
293 (operating-system-etc-service os)
e43e84ba 294 (service fstab-service-type '())
6bad7524
SB
295 (session-environment-service
296 (operating-system-environment-variables os))
0adfe95a
LC
297 host-name procs root-fs unmount
298 (service setuid-program-service-type
299 (operating-system-setuid-programs os))
af4c3fd5
LC
300 (service profile-service-type
301 (operating-system-packages os))
0adfe95a
LC
302 (append other-fs mappings swaps
303
304 ;; Add the firmware service, unless we are building for a
305 ;; container.
306 (if container?
307 '()
a241a7ac
LC
308 (list %linux-bare-metal-service
309 (service firmware-service-type
0adfe95a
LC
310 (operating-system-firmware os))))))))
311
312(define* (operating-system-services os #:key container?)
217a5b85
LC
313 "Return all the services of OS, including \"internal\" services that do not
314explicitly appear in OS."
be1c2c54 315 (append (operating-system-user-services os)
0adfe95a 316 (essential-services os #:container? container?)))
217a5b85 317
40281c54
LC
318\f
319;;;
320;;; /etc.
321;;;
322
f34c56be
LC
323(define %base-firmware
324 ;; Firmware usable by default.
325 (list ath9k-htc-firmware))
326
6f436c54
LC
327(define %base-packages
328 ;; Default set of packages globally visible. It should include anything
329 ;; required for basic administrator tasks.
55e70e65 330 (cons* procps psmisc which less zile nano
55e70e65 331 lsof ;for Guix's 'list-runtime-roots'
a96a82d7 332 pciutils usbutils
be681773
LC
333 util-linux inetutils isc-dhcp
334
335 ;; wireless-tools is deprecated in favor of iw, but it's still what
336 ;; many people are familiar with, so keep it around.
16cc9961 337 iw wireless-tools rfkill
be681773 338
5dccaffe 339 iproute
9b762b8d 340 net-tools ; XXX: remove when Inetutils suffices
18316d86 341 man-db
02683c33 342 info-reader ;the standalone Info reader (no Perl)
03e9998f 343
a8a086e3
LC
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
03e9998f
LC
349 ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev
350 ;; already depends on it anyway.
255f7308 351 kmod eudev
03e9998f 352
b63dbd44 353 e2fsprogs kbd
9b762b8d 354
1d167b6e
LC
355 bash-completion
356
9b762b8d
LC
357 ;; The packages below are also in %FINAL-INPUTS, so take them from
358 ;; there to avoid duplication.
359 (map canonical-package
a68c6967 360 (list guile-2.0 bash coreutils findutils grep sed
4b164c45 361 diffutils patch gawk tar gzip bzip2 xz lzip))))
6f436c54 362
548d4c13
LC
363(define %default-issue
364 ;; Default contents for /etc/issue.
365 "
366This is the GNU system. Welcome.\n")
367
568841d4
LC
368(define (local-host-aliases host-name)
369 "Return aliases for HOST-NAME, to be used in /etc/hosts."
370 (string-append "127.0.0.1 localhost " host-name "\n"
371 "::1 localhost " host-name "\n"))
372
c65e1834
LC
373(define (default-/etc/hosts host-name)
374 "Return the default /etc/hosts file."
24e02c28 375 (plain-file "hosts" (local-host-aliases host-name)))
c65e1834 376
0adfe95a
LC
377(define* (operating-system-etc-service os)
378 "Return a <service> that builds containing the static part of the /etc
379directory."
380 (let ((login.defs (plain-file "login.defs" "# Empty for now.\n"))
381
0adfe95a
LC
382 (issue (plain-file "issue" (operating-system-issue os)))
383 (nsswitch (plain-file "nsswitch.conf"
384 (name-service-switch->string
385 (operating-system-name-service-switch os))))
386
387 ;; Startup file for POSIX-compliant login shells, which set system-wide
388 ;; environment variables.
389 (profile (mixed-text-file "profile" "\
c05c4321 390# Crucial variables that could be missing in the profiles' 'etc/profile'
d9959421
LC
391# because they would require combining both profiles.
392# FIXME: See <http://bugs.gnu.org/20255>.
97ab2c0f 393export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man
95f92d4e 394export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info
00239d05
SB
395export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share
396export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg
397
d9959421
LC
398# Ignore the default value of 'PATH'.
399unset PATH
400
401# Load the system profile's settings.
402GUIX_PROFILE=/run/current-system/profile \\
669786da 403. /run/current-system/profile/etc/profile
d9959421
LC
404
405# Prepend setuid programs.
406export PATH=/run/setuid-programs:$PATH
407
507c71d6 408if [ -f \"$HOME/.guix-profile/etc/profile\" ]
d9959421
LC
409then
410 # Load the user profile's settings.
411 GUIX_PROFILE=\"$HOME/.guix-profile\" \\
669786da 412 . \"$HOME/.guix-profile/etc/profile\"
d9959421
LC
413else
414 # At least define this one so that basic things just work
415 # when the user installs their first package.
416 export PATH=\"$HOME/.guix-profile/bin:$PATH\"
417fi
418
2a5f0db4
LC
419# Since 'lshd' does not use pam_env, /etc/environment must be explicitly
420# loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>.
421# We need 'PATH' to be defined here, for 'cat' and 'cut'.
422if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\
423 -a -z \"$LINUX_MODULE_DIRECTORY\" ]
424then
425 . /etc/environment
426 export `cat /etc/environment | cut -d= -f1`
427fi
428
11202482
LC
429# Set the umask, notably for users logging in via 'lsh'.
430# See <http://bugs.gnu.org/22650>.
431umask 022
2a5f0db4 432
4af7c83b
LC
433# Allow GStreamer-based applications to find plugins.
434export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
435
1d167b6e
LC
436if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
437then
438 # Load Bash-specific initialization code.
669786da 439 . /etc/bashrc
1d167b6e 440fi
40281c54 441"))
1d167b6e 442
0adfe95a 443 (bashrc (plain-file "bashrc" "\
1d167b6e
LC
444# Bash-specific initialization.
445
446# The 'bash-completion' package.
447if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
448then
449 # Bash-completion sources ~/.bash_completion. It installs a dynamic
450 # completion loader that searches its own completion files as well
451 # as those in ~/.guix-profile and /run/current-system/profile.
452 source /run/current-system/profile/etc/profile.d/bash_completion.sh
0adfe95a
LC
453fi\n")))
454 (etc-service
455 `(("services" ,#~(string-append #$net-base "/etc/services"))
456 ("protocols" ,#~(string-append #$net-base "/etc/protocols"))
457 ("rpc" ,#~(string-append #$net-base "/etc/rpc"))
0adfe95a
LC
458 ("login.defs" ,#~#$login.defs)
459 ("issue" ,#~#$issue)
460 ("nsswitch.conf" ,#~#$nsswitch)
0adfe95a
LC
461 ("profile" ,#~#$profile)
462 ("bashrc" ,#~#$bashrc)
463 ("hosts" ,#~#$(or (operating-system-hosts-file os)
464 (default-/etc/hosts (operating-system-host-name os))))
465 ("localtime" ,#~(string-append #$tzdata "/share/zoneinfo/"
466 #$(operating-system-timezone os)))
467 ("sudoers" ,(operating-system-sudoers-file os))))))
033adfe7 468
ab6a279a
LC
469(define %root-account
470 ;; Default root account.
471 (user-account
472 (name "root")
473 (password "")
474 (uid 0) (group "root")
475 (comment "System administrator")
476 (home-directory "/root")))
477
0b6f49ef 478(define (operating-system-accounts os)
0adfe95a
LC
479 "Return the user accounts for OS, including an obligatory 'root' account,
480and excluding accounts requested by services."
481 ;; Make sure there's a root account.
482 (if (find (lambda (user)
483 (and=> (user-account-uid user) zero?))
484 (operating-system-users os))
485 (operating-system-users os)
486 (cons %root-account (operating-system-users os))))
0b6f49ef 487
84765839
LC
488(define (maybe-string->file file-name thing)
489 "If THING is a string, return a <plain-file> with THING as its content.
490Otherwise just return THING.
491
492This is for backward-compatibility of fields that used to be strings and are
493now file-like objects.."
494 (match thing
495 ((? string?)
496 (warning (_ "using a string for file '~a' is deprecated; \
497use 'plain-file' instead~%")
498 file-name)
499 (plain-file file-name thing))
500 (x
501 x)))
502
24e02c28
LC
503(define (maybe-file->monadic file-name thing)
504 "If THING is a value in %STORE-MONAD, return it as is; otherwise return
505THING in the %STORE-MONAD.
506
507This is for backward-compatibility of fields that used to be monadic values
508and are now file-like objects."
509 (with-monad %store-monad
510 (match thing
511 ((? procedure?)
512 (warning (_ "using a monadic value for '~a' is deprecated; \
513use 'plain-file' instead~%")
514 file-name)
515 thing)
516 (x
517 (return x)))))
518
0b6f49ef
LC
519(define (operating-system-etc-directory os)
520 "Return that static part of the /etc directory of OS."
0adfe95a
LC
521 (etc-directory
522 (fold-services (operating-system-services os)
523 #:target-type etc-service-type)))
033adfe7 524
6bad7524
SB
525(define (operating-system-environment-variables os)
526 "Return the environment variables of OS for
527@var{session-environment-service-type}, to be used in @file{/etc/environment}."
528 `(("LANG" . ,(operating-system-locale os))
529 ("TZ" . ,(operating-system-timezone os))
530 ("TZDIR" . ,#~(string-append #$tzdata "/share/zoneinfo"))
531 ;; Tell 'modprobe' & co. where to look for modules.
532 ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules")
533 ;; These variables are honored by OpenSSL (libssl) and Git.
534 ("SSL_CERT_DIR" . "/etc/ssl/certs")
535 ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt")
536 ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt")
ae05e366
LC
537
538 ;; 'GTK_DATA_PREFIX' must name one directory where GTK+ themes are
539 ;; searched for.
540 ("GTK_DATA_PREFIX" . "/run/current-system/profile")
541
6bad7524
SB
542 ;; By default, applications that use D-Bus, such as Emacs, abort at startup
543 ;; when /etc/machine-id is missing. Make sure these warnings are non-fatal.
544 ("DBUS_FATAL_WARNINGS" . "0")))
545
09e028f4
LC
546(define %setuid-programs
547 ;; Default set of setuid-root programs.
3b65abac 548 (let ((shadow (@ (gnu packages admin) shadow)))
09e028f4
LC
549 (list #~(string-append #$shadow "/bin/passwd")
550 #~(string-append #$shadow "/bin/su")
69689380 551 #~(string-append #$inetutils "/bin/ping")
5b9da1f9 552 #~(string-append #$inetutils "/bin/ping6")
8a07c289 553 #~(string-append #$sudo "/bin/sudo")
3b65abac 554 #~(string-append #$fuse "/bin/fusermount"))))
69689380
LC
555
556(define %sudoers-specification
557 ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel'
558 ;; group can do anything. See
559 ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>.
560 ;; TODO: Add a declarative API.
84765839
LC
561 (plain-file "sudoers" "\
562root ALL=(ALL) ALL
563%wheel ALL=(ALL) ALL\n"))
09e028f4 564
239db054 565(define* (operating-system-activation-script os #:key container?)
484a2b3a
LC
566 "Return the activation script for OS---i.e., the code that \"activates\" the
567stateful part of OS, including user accounts and groups, special directories,
568etc."
0adfe95a
LC
569 (let* ((services (operating-system-services os #:container? container?))
570 (activation (fold-services services
571 #:target-type activation-service-type)))
572 (activation-service->script activation)))
484a2b3a 573
239db054 574(define* (operating-system-boot-script os #:key container?)
484a2b3a 575 "Return the boot script for OS---i.e., the code started by the initrd once
239db054
DT
576we're running in the final root. When CONTAINER? is true, skip all
577hardware-related operations as necessary when booting a Linux container."
0adfe95a 578 (let* ((services (operating-system-services os #:container? container?))
d62e201c 579 (boot (fold-services services #:target-type boot-service-type)))
0adfe95a
LC
580 ;; BOOT is the script as a monadic value.
581 (service-parameters boot)))
2106d3fc 582
b2fef041
LC
583(define (operating-system-user-accounts os)
584 "Return the list of user accounts of OS."
585 (let* ((services (operating-system-services os))
586 (account (fold-services services
587 #:target-type account-service-type)))
588 (filter user-account?
589 (service-parameters account))))
590
591(define (operating-system-shepherd-service-names os)
592 "Return the list of Shepherd service names for OS."
593 (append-map shepherd-service-provision
594 (service-parameters
595 (fold-services (operating-system-services os)
596 #:target-type
597 shepherd-root-service-type))))
598
d62e201c
LC
599(define* (operating-system-derivation os #:key container?)
600 "Return a derivation that builds OS."
601 (let* ((services (operating-system-services os #:container? container?))
602 (system (fold-services services)))
603 ;; SYSTEM contains the derivation as a monadic value.
604 (service-parameters system)))
605
af4c3fd5
LC
606(define* (operating-system-profile os #:key container?)
607 "Return a derivation that builds the system profile of OS."
608 (mlet* %store-monad
609 ((services -> (operating-system-services os #:container? container?))
610 (profile (fold-services services
611 #:target-type profile-service-type)))
612 (match profile
613 (("profile" profile)
614 (return profile)))))
615
83bcd0b8
LC
616(define (operating-system-root-file-system os)
617 "Return the root file system of OS."
618 (find (match-lambda
d4c87617 619 (($ <file-system> _ _ "/") #t)
83bcd0b8
LC
620 (_ #f))
621 (operating-system-file-systems os)))
622
b4140694
LC
623(define (operating-system-initrd-file os)
624 "Return a gexp denoting the initrd file of OS."
83bcd0b8 625 (define boot-file-systems
4d6b879c 626 (filter file-system-needed-for-boot?
83bcd0b8
LC
627 (operating-system-file-systems os)))
628
de1c158f
LC
629 (define mapped-devices
630 (operating-system-boot-mapped-devices os))
631
632 (define make-initrd
633 (operating-system-initrd os))
634
635 (mlet %store-monad ((initrd (make-initrd boot-file-systems
0d275f4a 636 #:linux (operating-system-kernel os)
de1c158f 637 #:mapped-devices mapped-devices)))
b4140694
LC
638 (return #~(string-append #$initrd "/initrd"))))
639
f5582b2c
LC
640(define (locale-name->definition* name)
641 "Variant of 'locale-name->definition' that raises an error upon failure."
642 (match (locale-name->definition name)
643 (#f
644 (raise (condition
645 (&message
646 (message (format #f (_ "~a: invalid locale name") name))))))
647 (def def)))
648
598e19dc
LC
649(define (operating-system-locale-directory os)
650 "Return the directory containing the locales compiled for the definitions
651listed in OS. The C library expects to find it under
652/run/current-system/locale."
f5582b2c
LC
653 (define name
654 (operating-system-locale os))
655
656 (define definitions
657 ;; While we're at it, check whether NAME is defined and add it if needed.
658 (if (member name (map locale-definition-name
659 (operating-system-locale-definitions os)))
660 (operating-system-locale-definitions os)
661 (cons (locale-name->definition* name)
662 (operating-system-locale-definitions os))))
663
664 (locale-directory definitions
34760ae7 665 #:libcs (operating-system-locale-libcs os)))
598e19dc 666
2d23e6f0
LC
667(define (kernel->grub-label kernel)
668 "Return a label for the GRUB menu entry that boots KERNEL."
42de9608 669 (string-append "GNU with "
2d23e6f0
LC
670 (string-titlecase (package-name kernel)) " "
671 (package-version kernel)
d0a65256 672 " (beta)"))
2d23e6f0 673
6b779207
LC
674(define (store-file-system file-systems)
675 "Return the file system object among FILE-SYSTEMS that contains the store."
676 (match (filter (lambda (fs)
677 (and (file-system-mount? fs)
678 (not (memq 'bind-mount (file-system-flags fs)))
679 (string-prefix? (file-system-mount-point fs)
680 (%store-prefix))))
681 file-systems)
682 ((and candidates (head . tail))
683 (reduce (lambda (fs1 fs2)
684 (if (> (string-length (file-system-mount-point fs1))
685 (string-length (file-system-mount-point fs2)))
686 fs1
687 fs2))
688 head
689 candidates))))
690
691(define (operating-system-store-file-system os)
692 "Return the file system that contains the store of OS."
693 (store-file-system (operating-system-file-systems os)))
694
fe6e3fe2
LC
695(define* (operating-system-grub.cfg os #:optional (old-entries '()))
696 "Return the GRUB configuration file for OS. Use OLD-ENTRIES to populate the
697\"old entries\" menu."
0b6f49ef 698 (mlet* %store-monad
b4140694 699 ((system (operating-system-derivation os))
83bcd0b8 700 (root-fs -> (operating-system-root-file-system os))
6b779207 701 (store-fs -> (operating-system-store-file-system os))
b4140694 702 (kernel -> (operating-system-kernel os))
f453f637
LC
703 (root-device -> (if (eq? 'uuid (file-system-title root-fs))
704 (uuid->string (file-system-device root-fs))
705 (file-system-device root-fs)))
033adfe7 706 (entries -> (list (menu-entry
2d23e6f0 707 (label (kernel->grub-label kernel))
033adfe7 708 (linux kernel)
f6a7b21d 709 (linux-arguments
f453f637 710 (cons* (string-append "--root=" root-device)
ee2a6304
LC
711 #~(string-append "--system=" #$system)
712 #~(string-append "--load=" #$system
713 "/boot")
714 (operating-system-kernel-arguments os)))
b4140694 715 (initrd #~(string-append #$system "/initrd"))))))
6b779207
LC
716 (grub-configuration-file (operating-system-bootloader os)
717 store-fs entries
fe6e3fe2 718 #:old-entries old-entries)))
b4140694 719
64e40dbb
LC
720(define (operating-system-parameters-file os)
721 "Return a file that describes the boot parameters of OS. The primary use of
722this file is the reconstruction of GRUB menu entries for old configurations."
723 (mlet %store-monad ((initrd (operating-system-initrd-file os))
724 (root -> (operating-system-root-file-system os))
725 (label -> (kernel->grub-label
726 (operating-system-kernel os))))
727 (gexp->file "parameters"
728 #~(boot-parameters (version 0)
729 (label #$label)
730 (root-device #$(file-system-device root))
731 (kernel #$(operating-system-kernel os))
ee2a6304
LC
732 (kernel-arguments
733 #$(operating-system-kernel-arguments os))
64e40dbb
LC
734 (initrd #$initrd)))))
735
b8300494
AK
736\f
737;;;
738;;; Boot parameters
739;;;
740
741(define-record-type* <boot-parameters>
742 boot-parameters make-boot-parameters boot-parameters?
743 (label boot-parameters-label)
744 (root-device boot-parameters-root-device)
745 (kernel boot-parameters-kernel)
746 (kernel-arguments boot-parameters-kernel-arguments))
747
748(define (read-boot-parameters port)
749 "Read boot parameters from PORT and return the corresponding
750<boot-parameters> object or #f if the format is unrecognized."
751 (match (read port)
752 (('boot-parameters ('version 0)
753 ('label label) ('root-device root)
754 ('kernel linux)
755 rest ...)
756 (boot-parameters
757 (label label)
758 (root-device root)
759 (kernel linux)
760 (kernel-arguments
761 (match (assq 'kernel-arguments rest)
762 ((_ args) args)
763 (#f '()))))) ;the old format
764 (x ;unsupported format
765 (warning (_ "unrecognized boot parameters for '~a'~%")
766 system)
767 #f)))
768
033adfe7 769;;; system.scm ends here