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