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