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