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