gnu: Add texlive-latex-base.
[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
LC
492 util-linux inetutils isc-dhcp
493
494 ;; wireless-tools is deprecated in favor of iw, but it's still what
495 ;; many people are familiar with, so keep it around.
16cc9961 496 iw wireless-tools rfkill
be681773 497
5dccaffe 498 iproute
9b762b8d 499 net-tools ; XXX: remove when Inetutils suffices
18316d86 500 man-db
02683c33 501 info-reader ;the standalone Info reader (no Perl)
03e9998f 502
a8a086e3
LC
503 ;; The 'sudo' command is already in %SETUID-PROGRAMS, but we also
504 ;; want the other commands and the man pages (notably because
505 ;; auto-completion in Emacs shell relies on man pages.)
506 sudo
507
03e9998f
LC
508 ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev
509 ;; already depends on it anyway.
255f7308 510 kmod eudev
03e9998f 511
b63dbd44 512 e2fsprogs kbd
9b762b8d 513
1d167b6e
LC
514 bash-completion
515
9b762b8d
LC
516 ;; The packages below are also in %FINAL-INPUTS, so take them from
517 ;; there to avoid duplication.
518 (map canonical-package
b55dd316 519 (list guile-2.2 bash coreutils-8.27 findutils grep sed
4b164c45 520 diffutils patch gawk tar gzip bzip2 xz lzip))))
6f436c54 521
548d4c13
LC
522(define %default-issue
523 ;; Default contents for /etc/issue.
524 "
525This is the GNU system. Welcome.\n")
526
568841d4
LC
527(define (local-host-aliases host-name)
528 "Return aliases for HOST-NAME, to be used in /etc/hosts."
529 (string-append "127.0.0.1 localhost " host-name "\n"
530 "::1 localhost " host-name "\n"))
531
c65e1834
LC
532(define (default-/etc/hosts host-name)
533 "Return the default /etc/hosts file."
24e02c28 534 (plain-file "hosts" (local-host-aliases host-name)))
c65e1834 535
0adfe95a
LC
536(define* (operating-system-etc-service os)
537 "Return a <service> that builds containing the static part of the /etc
538directory."
539 (let ((login.defs (plain-file "login.defs" "# Empty for now.\n"))
540
0adfe95a
LC
541 (issue (plain-file "issue" (operating-system-issue os)))
542 (nsswitch (plain-file "nsswitch.conf"
543 (name-service-switch->string
544 (operating-system-name-service-switch os))))
545
546 ;; Startup file for POSIX-compliant login shells, which set system-wide
547 ;; environment variables.
548 (profile (mixed-text-file "profile" "\
c05c4321 549# Crucial variables that could be missing in the profiles' 'etc/profile'
d9959421
LC
550# because they would require combining both profiles.
551# FIXME: See <http://bugs.gnu.org/20255>.
97ab2c0f 552export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man
95f92d4e 553export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info
00239d05
SB
554export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share
555export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg
556
d9959421
LC
557# Ignore the default value of 'PATH'.
558unset PATH
559
560# Load the system profile's settings.
561GUIX_PROFILE=/run/current-system/profile \\
669786da 562. /run/current-system/profile/etc/profile
d9959421
LC
563
564# Prepend setuid programs.
565export PATH=/run/setuid-programs:$PATH
566
cad7e6ab
CSLL
567# Since 'lshd' does not use pam_env, /etc/environment must be explicitly
568# loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>.
569# We need 'PATH' to be defined here, for 'cat' and 'cut'. Do this before
570# reading the user's 'etc/profile' to allow variables to be overridden.
571if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\
572 -a -z \"$LINUX_MODULE_DIRECTORY\" ]
573then
574 . /etc/environment
575 export `cat /etc/environment | cut -d= -f1`
576fi
577
507c71d6 578if [ -f \"$HOME/.guix-profile/etc/profile\" ]
d9959421
LC
579then
580 # Load the user profile's settings.
581 GUIX_PROFILE=\"$HOME/.guix-profile\" \\
669786da 582 . \"$HOME/.guix-profile/etc/profile\"
d9959421
LC
583else
584 # At least define this one so that basic things just work
585 # when the user installs their first package.
586 export PATH=\"$HOME/.guix-profile/bin:$PATH\"
587fi
588
11202482
LC
589# Set the umask, notably for users logging in via 'lsh'.
590# See <http://bugs.gnu.org/22650>.
591umask 022
2a5f0db4 592
4af7c83b
LC
593# Allow GStreamer-based applications to find plugins.
594export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
595
1d167b6e
LC
596if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
597then
598 # Load Bash-specific initialization code.
669786da 599 . /etc/bashrc
1d167b6e 600fi
40281c54 601"))
1d167b6e 602
0adfe95a 603 (bashrc (plain-file "bashrc" "\
1d167b6e
LC
604# Bash-specific initialization.
605
606# The 'bash-completion' package.
607if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
608then
609 # Bash-completion sources ~/.bash_completion. It installs a dynamic
610 # completion loader that searches its own completion files as well
611 # as those in ~/.guix-profile and /run/current-system/profile.
612 source /run/current-system/profile/etc/profile.d/bash_completion.sh
0adfe95a
LC
613fi\n")))
614 (etc-service
9e41130b
LC
615 `(("services" ,(file-append net-base "/etc/services"))
616 ("protocols" ,(file-append net-base "/etc/protocols"))
617 ("rpc" ,(file-append net-base "/etc/rpc"))
0adfe95a
LC
618 ("login.defs" ,#~#$login.defs)
619 ("issue" ,#~#$issue)
620 ("nsswitch.conf" ,#~#$nsswitch)
0adfe95a
LC
621 ("profile" ,#~#$profile)
622 ("bashrc" ,#~#$bashrc)
623 ("hosts" ,#~#$(or (operating-system-hosts-file os)
624 (default-/etc/hosts (operating-system-host-name os))))
9e41130b
LC
625 ("localtime" ,(file-append tzdata "/share/zoneinfo/"
626 (operating-system-timezone os)))
0adfe95a 627 ("sudoers" ,(operating-system-sudoers-file os))))))
033adfe7 628
ab6a279a
LC
629(define %root-account
630 ;; Default root account.
631 (user-account
632 (name "root")
633 (password "")
634 (uid 0) (group "root")
635 (comment "System administrator")
636 (home-directory "/root")))
637
0b6f49ef 638(define (operating-system-accounts os)
0adfe95a
LC
639 "Return the user accounts for OS, including an obligatory 'root' account,
640and excluding accounts requested by services."
641 ;; Make sure there's a root account.
642 (if (find (lambda (user)
643 (and=> (user-account-uid user) zero?))
644 (operating-system-users os))
645 (operating-system-users os)
646 (cons %root-account (operating-system-users os))))
0b6f49ef 647
84765839
LC
648(define (maybe-string->file file-name thing)
649 "If THING is a string, return a <plain-file> with THING as its content.
650Otherwise just return THING.
651
652This is for backward-compatibility of fields that used to be strings and are
653now file-like objects.."
654 (match thing
655 ((? string?)
69daee23 656 (warning (G_ "using a string for file '~a' is deprecated; \
84765839
LC
657use 'plain-file' instead~%")
658 file-name)
659 (plain-file file-name thing))
660 (x
661 x)))
662
24e02c28
LC
663(define (maybe-file->monadic file-name thing)
664 "If THING is a value in %STORE-MONAD, return it as is; otherwise return
665THING in the %STORE-MONAD.
666
667This is for backward-compatibility of fields that used to be monadic values
668and are now file-like objects."
669 (with-monad %store-monad
670 (match thing
671 ((? procedure?)
69daee23 672 (warning (G_ "using a monadic value for '~a' is deprecated; \
24e02c28
LC
673use 'plain-file' instead~%")
674 file-name)
675 thing)
676 (x
677 (return x)))))
678
0b6f49ef
LC
679(define (operating-system-etc-directory os)
680 "Return that static part of the /etc directory of OS."
0adfe95a
LC
681 (etc-directory
682 (fold-services (operating-system-services os)
683 #:target-type etc-service-type)))
033adfe7 684
6bad7524
SB
685(define (operating-system-environment-variables os)
686 "Return the environment variables of OS for
687@var{session-environment-service-type}, to be used in @file{/etc/environment}."
688 `(("LANG" . ,(operating-system-locale os))
689 ("TZ" . ,(operating-system-timezone os))
9e41130b 690 ("TZDIR" . ,(file-append tzdata "/share/zoneinfo"))
6bad7524
SB
691 ;; Tell 'modprobe' & co. where to look for modules.
692 ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules")
693 ;; These variables are honored by OpenSSL (libssl) and Git.
694 ("SSL_CERT_DIR" . "/etc/ssl/certs")
695 ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt")
696 ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt")
ae05e366
LC
697
698 ;; 'GTK_DATA_PREFIX' must name one directory where GTK+ themes are
699 ;; searched for.
700 ("GTK_DATA_PREFIX" . "/run/current-system/profile")
701
6bad7524
SB
702 ;; By default, applications that use D-Bus, such as Emacs, abort at startup
703 ;; when /etc/machine-id is missing. Make sure these warnings are non-fatal.
946465bb
LC
704 ("DBUS_FATAL_WARNINGS" . "0")
705
706 ;; XXX: Normally we wouldn't need to do this, but our glibc@2.23 package
707 ;; used to look things up in 'PREFIX/lib/locale' instead of
708 ;; '/run/current-system/locale' as was intended. Keep this hack around so
709 ;; that people who still have glibc@2.23-using packages in their profiles
710 ;; can use them correctly.
711 ;; TODO: Remove when glibc@2.23 is long gone.
712 ("GUIX_LOCPATH" . "/run/current-system/locale")))
6bad7524 713
09e028f4
LC
714(define %setuid-programs
715 ;; Default set of setuid-root programs.
3b65abac 716 (let ((shadow (@ (gnu packages admin) shadow)))
9e41130b
LC
717 (list (file-append shadow "/bin/passwd")
718 (file-append shadow "/bin/su")
719 (file-append inetutils "/bin/ping")
720 (file-append inetutils "/bin/ping6")
721 (file-append sudo "/bin/sudo")
722 (file-append fuse "/bin/fusermount"))))
69689380
LC
723
724(define %sudoers-specification
725 ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel'
726 ;; group can do anything. See
727 ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>.
728 ;; TODO: Add a declarative API.
84765839
LC
729 (plain-file "sudoers" "\
730root ALL=(ALL) ALL
731%wheel ALL=(ALL) ALL\n"))
09e028f4 732
239db054 733(define* (operating-system-activation-script os #:key container?)
484a2b3a
LC
734 "Return the activation script for OS---i.e., the code that \"activates\" the
735stateful part of OS, including user accounts and groups, special directories,
736etc."
0adfe95a
LC
737 (let* ((services (operating-system-services os #:container? container?))
738 (activation (fold-services services
739 #:target-type activation-service-type)))
740 (activation-service->script activation)))
484a2b3a 741
239db054 742(define* (operating-system-boot-script os #:key container?)
484a2b3a 743 "Return the boot script for OS---i.e., the code started by the initrd once
239db054
DT
744we're running in the final root. When CONTAINER? is true, skip all
745hardware-related operations as necessary when booting a Linux container."
0adfe95a 746 (let* ((services (operating-system-services os #:container? container?))
d62e201c 747 (boot (fold-services services #:target-type boot-service-type)))
0adfe95a 748 ;; BOOT is the script as a monadic value.
efe7d19a 749 (service-value boot)))
2106d3fc 750
b2fef041
LC
751(define (operating-system-user-accounts os)
752 "Return the list of user accounts of OS."
753 (let* ((services (operating-system-services os))
754 (account (fold-services services
755 #:target-type account-service-type)))
756 (filter user-account?
efe7d19a 757 (service-value account))))
b2fef041
LC
758
759(define (operating-system-shepherd-service-names os)
760 "Return the list of Shepherd service names for OS."
761 (append-map shepherd-service-provision
efe7d19a 762 (service-value
b2fef041
LC
763 (fold-services (operating-system-services os)
764 #:target-type
765 shepherd-root-service-type))))
766
d62e201c
LC
767(define* (operating-system-derivation os #:key container?)
768 "Return a derivation that builds OS."
769 (let* ((services (operating-system-services os #:container? container?))
770 (system (fold-services services)))
771 ;; SYSTEM contains the derivation as a monadic value.
efe7d19a 772 (service-value system)))
d62e201c 773
af4c3fd5
LC
774(define* (operating-system-profile os #:key container?)
775 "Return a derivation that builds the system profile of OS."
776 (mlet* %store-monad
777 ((services -> (operating-system-services os #:container? container?))
778 (profile (fold-services services
779 #:target-type profile-service-type)))
780 (match profile
781 (("profile" profile)
782 (return profile)))))
783
83bcd0b8
LC
784(define (operating-system-root-file-system os)
785 "Return the root file system of OS."
786 (find (match-lambda
856be823
LC
787 (($ <file-system> device title "/") #t)
788 (x #f))
83bcd0b8
LC
789 (operating-system-file-systems os)))
790
b4140694
LC
791(define (operating-system-initrd-file os)
792 "Return a gexp denoting the initrd file of OS."
83bcd0b8 793 (define boot-file-systems
4d6b879c 794 (filter file-system-needed-for-boot?
83bcd0b8
LC
795 (operating-system-file-systems os)))
796
de1c158f
LC
797 (define mapped-devices
798 (operating-system-boot-mapped-devices os))
799
800 (define make-initrd
801 (operating-system-initrd os))
802
803 (mlet %store-monad ((initrd (make-initrd boot-file-systems
0d275f4a 804 #:linux (operating-system-kernel os)
de1c158f 805 #:mapped-devices mapped-devices)))
ab20d74a 806 (return (file-append initrd "/initrd"))))
b4140694 807
f5582b2c
LC
808(define (locale-name->definition* name)
809 "Variant of 'locale-name->definition' that raises an error upon failure."
810 (match (locale-name->definition name)
811 (#f
812 (raise (condition
813 (&message
69daee23 814 (message (format #f (G_ "~a: invalid locale name") name))))))
f5582b2c
LC
815 (def def)))
816
598e19dc
LC
817(define (operating-system-locale-directory os)
818 "Return the directory containing the locales compiled for the definitions
819listed in OS. The C library expects to find it under
820/run/current-system/locale."
f5582b2c
LC
821 (define name
822 (operating-system-locale os))
823
824 (define definitions
825 ;; While we're at it, check whether NAME is defined and add it if needed.
826 (if (member name (map locale-definition-name
827 (operating-system-locale-definitions os)))
828 (operating-system-locale-definitions os)
829 (cons (locale-name->definition* name)
830 (operating-system-locale-definitions os))))
831
832 (locale-directory definitions
34760ae7 833 #:libcs (operating-system-locale-libcs os)))
598e19dc 834
c2e9942b
MO
835(define (kernel->boot-label kernel)
836 "Return a label for the bootloader menu entry that boots KERNEL."
42de9608 837 (string-append "GNU with "
2d23e6f0
LC
838 (string-titlecase (package-name kernel)) " "
839 (package-version kernel)
d0a65256 840 " (beta)"))
2d23e6f0 841
6b779207
LC
842(define (store-file-system file-systems)
843 "Return the file system object among FILE-SYSTEMS that contains the store."
844 (match (filter (lambda (fs)
845 (and (file-system-mount? fs)
846 (not (memq 'bind-mount (file-system-flags fs)))
847 (string-prefix? (file-system-mount-point fs)
848 (%store-prefix))))
849 file-systems)
850 ((and candidates (head . tail))
851 (reduce (lambda (fs1 fs2)
852 (if (> (string-length (file-system-mount-point fs1))
853 (string-length (file-system-mount-point fs2)))
854 fs1
855 fs2))
856 head
857 candidates))))
858
859(define (operating-system-store-file-system os)
860 "Return the file system that contains the store of OS."
861 (store-file-system (operating-system-file-systems os)))
862
c76b3046
MO
863(define* (operating-system-bootcfg os #:optional (old-entries '()))
864 "Return the bootloader configuration file for OS. Use OLD-ENTRIES to
865populate the \"old entries\" menu."
0b6f49ef 866 (mlet* %store-monad
b4140694 867 ((system (operating-system-derivation os))
83bcd0b8 868 (root-fs -> (operating-system-root-file-system os))
f453f637
LC
869 (root-device -> (if (eq? 'uuid (file-system-title root-fs))
870 (uuid->string (file-system-device root-fs))
871 (file-system-device root-fs)))
b09a8da4
MO
872 (entry (operating-system-boot-parameters os system root-device))
873 (bootloader-conf -> (operating-system-bootloader os)))
874 ((bootloader-configuration-file-generator
875 (bootloader-configuration-bootloader bootloader-conf))
876 bootloader-conf (list entry) #:old-entries old-entries)))
b4140694 877
7085ca96 878(define (fs->boot-device fs)
3382bfe9
CM
879 "Given FS, a <file-system> object, return a value suitable for use as the
880device in a <menu-entry>."
881 (case (file-system-title fs)
882 ((uuid) (file-system-device fs))
883 ((label) (file-system-device fs))
884 (else #f)))
885
360874dd
DM
886(define (operating-system-boot-parameters os system.drv root-device)
887 "Return a monadic <boot-parameters> record that describes the boot parameters
888of OS. SYSTEM.DRV is either a derivation or #f. If it's a derivation, adds
889kernel arguments for that derivation to <boot-parameters>."
40fad1c2
DM
890 (mlet* %store-monad
891 ((initrd (operating-system-initrd-file os))
892 (store -> (operating-system-store-file-system os))
bcaf67c4
MO
893 (bootloader -> (bootloader-configuration-bootloader
894 (operating-system-bootloader os)))
f96752e3 895 (bootloader-name -> (bootloader-name bootloader))
40fad1c2
DM
896 (label -> (kernel->boot-label (operating-system-kernel os))))
897 (return (boot-parameters
898 (label label)
899 (root-device root-device)
900 (kernel (operating-system-kernel-file os))
901 (kernel-arguments
360874dd
DM
902 (if system.drv
903 (operating-system-kernel-arguments os system.drv root-device)
904 (operating-system-user-kernel-arguments os)))
40fad1c2 905 (initrd initrd)
f96752e3 906 (bootloader-name bootloader-name)
40fad1c2
DM
907 (store-device (fs->boot-device store))
908 (store-mount-point (file-system-mount-point store))))))
909
910(define* (operating-system-boot-parameters-file os #:optional (system.drv #f))
911 "Return a file that describes the boot parameters of OS. The primary use of
912this file is the reconstruction of GRUB menu entries for old configurations.
913SYSTEM.DRV is optional. If given, adds kernel arguments for that system to the
914returned file (since the returned file is then usually stored into the
915content-addressed \"system\" directory, it's usually not a good idea
916to give it because the content hash would change by the content hash
917being stored into the \"parameters\" file)."
918 (mlet* %store-monad ((root -> (operating-system-root-file-system os))
919 (device -> (file-system-device root))
920 (params (operating-system-boot-parameters os
921 system.drv
922 device)))
923 (gexp->file "parameters"
924 #~(boot-parameters
925 (version 0)
926 (label #$(boot-parameters-label params))
927 (root-device #$(boot-parameters-root-device params))
928 (kernel #$(boot-parameters-kernel params))
929 (kernel-arguments
930 #$(boot-parameters-kernel-arguments params))
931 (initrd #$(boot-parameters-initrd params))
f96752e3 932 (bootloader-name #$(boot-parameters-bootloader-name params))
40fad1c2
DM
933 (store
934 (device #$(boot-parameters-store-device params))
935 (mount-point #$(boot-parameters-store-mount-point params))))
936 #:set-load-path? #f)))
64e40dbb 937
033adfe7 938;;; system.scm ends here