Commit | Line | Data |
---|---|---|
033adfe7 | 1 | ;;; GNU Guix --- Functional package management for GNU |
cda75110 | 2 | ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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> |
5c79f238 | 8 | ;;; Copyright © 2020 Danny Milosavljevic <dannym@scratchpost.org> |
93664fee | 9 | ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re> |
e06664da | 10 | ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de> |
b460ba79 | 11 | ;;; Copyright © 2020 Maxim Cournoyer <maxim.cournoyer@gmail.com> |
45b2cb43 | 12 | ;;; Copyright © 2020 Jan (janneke) Nieuwenhuizen <jannek@gnu.org> |
033adfe7 LC |
13 | ;;; |
14 | ;;; This file is part of GNU Guix. | |
15 | ;;; | |
16 | ;;; GNU Guix is free software; you can redistribute it and/or modify it | |
17 | ;;; under the terms of the GNU General Public License as published by | |
18 | ;;; the Free Software Foundation; either version 3 of the License, or (at | |
19 | ;;; your option) any later version. | |
20 | ;;; | |
21 | ;;; GNU Guix is distributed in the hope that it will be useful, but | |
22 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of | |
23 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
24 | ;;; GNU General Public License for more details. | |
25 | ;;; | |
26 | ;;; You should have received a copy of the GNU General Public License | |
27 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. | |
28 | ||
29 | (define-module (gnu system) | |
bdc61ff9 | 30 | #:use-module (guix inferior) |
033adfe7 LC |
31 | #:use-module (guix store) |
32 | #:use-module (guix monads) | |
02100028 | 33 | #:use-module (guix gexp) |
033adfe7 LC |
34 | #:use-module (guix records) |
35 | #:use-module (guix packages) | |
36 | #:use-module (guix derivations) | |
29fce8b6 | 37 | #:use-module (guix profiles) |
84765839 | 38 | #:use-module (guix ui) |
f91ad0b1 | 39 | #:use-module (guix utils) |
033adfe7 LC |
40 | #:use-module (gnu packages base) |
41 | #:use-module (gnu packages bash) | |
912b857e | 42 | #:use-module (gnu packages cross-base) |
bdb36958 | 43 | #:use-module (gnu packages guile) |
01ac0e6b | 44 | #:use-module (gnu packages guile-xyz) |
9de46ffb | 45 | #:use-module (gnu packages admin) |
912b857e | 46 | #:use-module (gnu packages hurd) |
8a07c289 | 47 | #:use-module (gnu packages linux) |
a96a82d7 | 48 | #:use-module (gnu packages pciutils) |
033adfe7 | 49 | #:use-module (gnu packages package-management) |
6f436c54 LC |
50 | #:use-module (gnu packages less) |
51 | #:use-module (gnu packages zile) | |
55e70e65 | 52 | #:use-module (gnu packages nano) |
a68c6967 | 53 | #:use-module (gnu packages gawk) |
18316d86 | 54 | #:use-module (gnu packages man) |
939c5c31 | 55 | #:use-module (gnu packages texinfo) |
a68c6967 | 56 | #:use-module (gnu packages compression) |
f34c56be | 57 | #:use-module (gnu packages firmware) |
db4fdc04 | 58 | #:use-module (gnu services) |
0190c1c0 | 59 | #:use-module (gnu services shepherd) |
db4fdc04 | 60 | #:use-module (gnu services base) |
b09a8da4 | 61 | #:use-module (gnu bootloader) |
033adfe7 | 62 | #:use-module (gnu system shadow) |
996ed739 | 63 | #:use-module (gnu system nss) |
598e19dc | 64 | #:use-module (gnu system locale) |
6e828634 | 65 | #:use-module (gnu system pam) |
735c6dd7 | 66 | #:use-module (gnu system linux-initrd) |
9b336338 | 67 | #:use-module (gnu system uuid) |
c5df1839 | 68 | #:use-module (gnu system file-systems) |
060d62a7 | 69 | #:use-module (gnu system mapped-devices) |
033adfe7 LC |
70 | #:use-module (ice-9 match) |
71 | #:use-module (srfi srfi-1) | |
72 | #:use-module (srfi srfi-26) | |
598e19dc LC |
73 | #:use-module (srfi srfi-34) |
74 | #:use-module (srfi srfi-35) | |
3382bfe9 | 75 | #:use-module (rnrs bytevectors) |
033adfe7 LC |
76 | #:export (operating-system |
77 | operating-system? | |
d8bead6c | 78 | this-operating-system |
d5b429ab LC |
79 | |
80 | operating-system-bootloader | |
033adfe7 | 81 | operating-system-services |
69cae3d3 | 82 | operating-system-essential-services |
f8885eca | 83 | operating-system-default-essential-services |
217a5b85 | 84 | operating-system-user-services |
033adfe7 | 85 | operating-system-packages |
fd3bfc44 | 86 | operating-system-host-name |
c65e1834 | 87 | operating-system-hosts-file |
2018fb2a | 88 | operating-system-hurd |
fd3bfc44 | 89 | operating-system-kernel |
44d5f54e | 90 | operating-system-kernel-file |
33f0aa88 | 91 | operating-system-kernel-arguments |
3f03a198 LC |
92 | operating-system-label |
93 | operating-system-default-label | |
bc499b11 | 94 | operating-system-initrd-modules |
fd3bfc44 LC |
95 | operating-system-initrd |
96 | operating-system-users | |
97 | operating-system-groups | |
548d4c13 | 98 | operating-system-issue |
fd3bfc44 LC |
99 | operating-system-timezone |
100 | operating-system-locale | |
598e19dc | 101 | operating-system-locale-definitions |
34760ae7 | 102 | operating-system-locale-libcs |
5dae0186 | 103 | operating-system-mapped-devices |
83bcd0b8 | 104 | operating-system-file-systems |
6b779207 | 105 | operating-system-store-file-system |
2bdd7ac1 LC |
106 | operating-system-user-mapped-devices |
107 | operating-system-boot-mapped-devices | |
b25937e3 | 108 | operating-system-activation-script |
b2fef041 LC |
109 | operating-system-user-accounts |
110 | operating-system-shepherd-service-names | |
20abb8c4 | 111 | operating-system-user-kernel-arguments |
9ef37e81 BW |
112 | operating-system-firmware |
113 | operating-system-keyboard-layout | |
114 | operating-system-name-service-switch | |
115 | operating-system-pam-services | |
116 | operating-system-setuid-programs | |
117 | operating-system-skeletons | |
118 | operating-system-sudoers-file | |
119 | operating-system-swap-devices | |
a9f2c210 | 120 | operating-system-kernel-loadable-modules |
9e12da31 | 121 | operating-system-location |
033adfe7 | 122 | |
1aa0033b | 123 | operating-system-derivation |
83bcd0b8 | 124 | operating-system-profile |
c76b3046 | 125 | operating-system-bootcfg |
239db054 DT |
126 | operating-system-etc-directory |
127 | operating-system-locale-directory | |
128 | operating-system-boot-script | |
78fbf2bd | 129 | operating-system-uuid |
239db054 | 130 | |
43fe431c | 131 | system-linux-image-file-name |
9fcfe30d | 132 | operating-system-with-gc-roots |
33b7cb7a | 133 | operating-system-with-provenance |
43fe431c | 134 | |
45b2cb43 JN |
135 | hurd-default-essential-services |
136 | ||
b8300494 AK |
137 | boot-parameters |
138 | boot-parameters? | |
139 | boot-parameters-label | |
140 | boot-parameters-root-device | |
f96752e3 | 141 | boot-parameters-bootloader-name |
a28cfee8 | 142 | boot-parameters-bootloader-menu-entries |
1ef8b72a CM |
143 | boot-parameters-store-device |
144 | boot-parameters-store-mount-point | |
b8300494 AK |
145 | boot-parameters-kernel |
146 | boot-parameters-kernel-arguments | |
d7b342d8 | 147 | boot-parameters-initrd |
912b857e | 148 | boot-parameters-multiboot-modules |
4e4e0185 | 149 | read-boot-parameters |
9530e73b | 150 | read-boot-parameters-file |
1975c754 | 151 | boot-parameters->menu-entry |
b8300494 | 152 | |
568841d4 | 153 | local-host-aliases |
d0f3a672 | 154 | %root-account |
df5ce088 | 155 | %setuid-programs |
f6b95031 | 156 | %sudoers-specification |
5dae0186 | 157 | %base-packages |
93664fee BW |
158 | %base-packages-interactive |
159 | %base-packages-linux | |
160 | %base-packages-networking | |
161 | %base-packages-utils | |
e06664da FP |
162 | %base-firmware |
163 | %default-kernel-arguments)) | |
033adfe7 LC |
164 | |
165 | ;;; Commentary: | |
166 | ;;; | |
167 | ;;; This module supports whole-system configuration. | |
168 | ;;; | |
169 | ;;; Code: | |
170 | ||
a7ef45d9 LC |
171 | (define (bootable-kernel-arguments system root-device) |
172 | "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE." | |
173 | (list (string-append "--root=" | |
99e676db MC |
174 | ;; Note: Always use the DCE format because that's what |
175 | ;; (gnu build linux-boot) expects for the '--root' | |
176 | ;; kernel command-line option. | |
177 | (file-system-device->string root-device | |
178 | #:uuid-type 'dce)) | |
a7ef45d9 LC |
179 | #~(string-append "--system=" #$system) |
180 | #~(string-append "--load=" #$system "/boot"))) | |
33f0aa88 | 181 | |
033adfe7 LC |
182 | ;; System-wide configuration. |
183 | ;; TODO: Add per-field docstrings/stexi. | |
184 | (define-record-type* <operating-system> operating-system | |
185 | make-operating-system | |
186 | operating-system? | |
d8bead6c LC |
187 | this-operating-system |
188 | ||
033adfe7 | 189 | (kernel operating-system-kernel ; package |
57082417 | 190 | (default linux-libre)) |
5c79f238 DM |
191 | (kernel-loadable-modules operating-system-kernel-loadable-modules |
192 | (default '())) ; list of packages | |
af98d25a | 193 | (kernel-arguments operating-system-user-kernel-arguments |
e06664da | 194 | (default %default-kernel-arguments)) ; list of gexps/strings |
2018fb2a JN |
195 | (hurd operating-system-hurd |
196 | (default #f)) ; package | |
b09a8da4 | 197 | (bootloader operating-system-bootloader) ; <bootloader-configuration> |
3f03a198 LC |
198 | (label operating-system-label ; string |
199 | (thunked) | |
200 | (default (operating-system-default-label this-operating-system))) | |
d5b429ab | 201 | |
ae7a316b LC |
202 | (keyboard-layout operating-system-keyboard-layout ;#f | <keyboard-layout> |
203 | (default #f)) | |
e34ae75d | 204 | (initrd operating-system-initrd ; (list fs) -> file-like |
060238ae | 205 | (default base-initrd)) |
bc499b11 LC |
206 | (initrd-modules operating-system-initrd-modules ; list of strings |
207 | (thunked) ; it's system-dependent | |
208 | (default %base-initrd-modules)) | |
209 | ||
f34c56be LC |
210 | (firmware operating-system-firmware ; list of packages |
211 | (default %base-firmware)) | |
033adfe7 LC |
212 | |
213 | (host-name operating-system-host-name) ; string | |
24e02c28 | 214 | (hosts-file operating-system-hosts-file ; file-like | #f |
c65e1834 | 215 | (default #f)) |
033adfe7 | 216 | |
5dae0186 LC |
217 | (mapped-devices operating-system-mapped-devices ; list of <mapped-device> |
218 | (default '())) | |
8a6d2731 | 219 | (file-systems operating-system-file-systems) ; list of fs |
2a13d05e LC |
220 | (swap-devices operating-system-swap-devices ; list of strings |
221 | (default '())) | |
033adfe7 LC |
222 | |
223 | (users operating-system-users ; list of user accounts | |
bf87f38a | 224 | (default %base-user-accounts)) |
033adfe7 | 225 | (groups operating-system-groups ; list of user groups |
773e956d | 226 | (default %base-groups)) |
033adfe7 | 227 | |
ac3c14fb | 228 | (skeletons operating-system-skeletons ; list of name/file-like value |
40281c54 | 229 | (default (default-skeletons))) |
548d4c13 LC |
230 | (issue operating-system-issue ; string |
231 | (default %default-issue)) | |
40281c54 | 232 | |
033adfe7 | 233 | (packages operating-system-packages ; list of (PACKAGE OUTPUT...) |
6f436c54 | 234 | (default %base-packages)) ; or just PACKAGE |
033adfe7 LC |
235 | |
236 | (timezone operating-system-timezone) ; string | |
8a6d2731 | 237 | (locale operating-system-locale ; string |
598e19dc LC |
238 | (default "en_US.utf8")) |
239 | (locale-definitions operating-system-locale-definitions ; list of <locale-definition> | |
240 | (default %default-locale-definitions)) | |
34760ae7 LC |
241 | (locale-libcs operating-system-locale-libcs ; list of <packages> |
242 | (default %default-locale-libcs)) | |
996ed739 LC |
243 | (name-service-switch operating-system-name-service-switch ; <name-service-switch> |
244 | (default %default-nss)) | |
033adfe7 | 245 | |
69cae3d3 LC |
246 | (essential-services operating-system-essential-services ; list of services |
247 | (thunked) | |
f8885eca LC |
248 | (default (operating-system-default-essential-services |
249 | this-operating-system))) | |
ac3c14fb | 250 | (services operating-system-user-services ; list of services |
09e028f4 LC |
251 | (default %base-services)) |
252 | ||
253 | (pam-services operating-system-pam-services ; list of PAM services | |
254 | (default (base-pam-services))) | |
255 | (setuid-programs operating-system-setuid-programs | |
69689380 | 256 | (default %setuid-programs)) ; list of string-valued gexps |
033adfe7 | 257 | |
f5a9ffa0 | 258 | (sudoers-file operating-system-sudoers-file ; file-like |
9e12da31 LC |
259 | (default %sudoers-specification)) |
260 | ||
261 | (location operating-system-location ; <location> | |
262 | (default (and=> (current-source-location) | |
263 | source-properties->location)) | |
264 | (innate))) | |
033adfe7 | 265 | |
a7ef45d9 | 266 | (define (operating-system-kernel-arguments os root-device) |
33f0aa88 DM |
267 | "Return all the kernel arguments, including the ones not specified |
268 | directly by the user." | |
a7ef45d9 LC |
269 | (append (bootable-kernel-arguments os root-device) |
270 | (operating-system-user-kernel-arguments os))) | |
33f0aa88 | 271 | |
2717a89a | 272 | \f |
8e815c5b LC |
273 | ;;; |
274 | ;;; Boot parameters | |
275 | ;;; | |
276 | ||
277 | (define-record-type* <boot-parameters> | |
278 | boot-parameters make-boot-parameters boot-parameters? | |
279 | (label boot-parameters-label) | |
280 | ;; Because we will use the 'store-device' to create the GRUB search command, | |
281 | ;; the 'store-device' has slightly different semantics than 'root-device'. | |
282 | ;; The 'store-device' can be a file system uuid, a file system label, or #f, | |
283 | ;; but it cannot be a device path such as "/dev/sda3", since GRUB would not | |
284 | ;; understand that. The 'root-device', on the other hand, corresponds | |
285 | ;; exactly to the device field of the <file-system> object representing the | |
286 | ;; OS's root file system, so it might be a device path like "/dev/sda3". | |
287 | (root-device boot-parameters-root-device) | |
f96752e3 | 288 | (bootloader-name boot-parameters-bootloader-name) |
a28cfee8 LC |
289 | (bootloader-menu-entries ;list of <menu-entry> |
290 | boot-parameters-bootloader-menu-entries) | |
8e815c5b LC |
291 | (store-device boot-parameters-store-device) |
292 | (store-mount-point boot-parameters-store-mount-point) | |
293 | (kernel boot-parameters-kernel) | |
294 | (kernel-arguments boot-parameters-kernel-arguments) | |
912b857e JN |
295 | (initrd boot-parameters-initrd) |
296 | (multiboot-modules boot-parameters-multiboot-modules)) | |
8e815c5b | 297 | |
90d23ed9 LC |
298 | (define (ensure-not-/dev device) |
299 | "If DEVICE starts with a slash, return #f. This is meant to filter out | |
300 | Linux device names such as /dev/sda, and to preserve GRUB device names and | |
301 | file system labels." | |
302 | (if (and (string? device) (string-prefix? "/" device)) | |
303 | #f | |
304 | device)) | |
305 | ||
8e815c5b LC |
306 | (define (read-boot-parameters port) |
307 | "Read boot parameters from PORT and return the corresponding | |
308 | <boot-parameters> object or #f if the format is unrecognized." | |
075681d3 LC |
309 | (define device-sexp->device |
310 | (match-lambda | |
311 | (('uuid (? symbol? type) (? bytevector? bv)) | |
312 | (bytevector->uuid bv type)) | |
a5acc17a LC |
313 | (('file-system-label (? string? label)) |
314 | (file-system-label label)) | |
075681d3 LC |
315 | ((? bytevector? bv) ;old format |
316 | (bytevector->uuid bv 'dce)) | |
317 | ((? string? device) | |
a5acc17a LC |
318 | ;; It used to be that we would not distinguish between labels and |
319 | ;; device names. Try to infer the right thing here. | |
320 | (if (string-prefix? "/dev/" device) | |
321 | device | |
322 | (file-system-label device))))) | |
075681d3 | 323 | |
8e815c5b LC |
324 | (match (read port) |
325 | (('boot-parameters ('version 0) | |
326 | ('label label) ('root-device root) | |
912b857e | 327 | ('kernel kernel) |
8e815c5b LC |
328 | rest ...) |
329 | (boot-parameters | |
330 | (label label) | |
7940188e | 331 | (root-device (device-sexp->device root)) |
8e815c5b | 332 | |
f96752e3 MO |
333 | (bootloader-name |
334 | (match (assq 'bootloader-name rest) | |
bcaf67c4 MO |
335 | ((_ args) args) |
336 | (#f 'grub))) ; for compatibility reasons. | |
337 | ||
a28cfee8 LC |
338 | (bootloader-menu-entries |
339 | (match (assq 'bootloader-menu-entries rest) | |
340 | ((_ entries) (map sexp->menu-entry entries)) | |
341 | (#f '()))) | |
342 | ||
912b857e JN |
343 | ;; In the past, we would store the directory name of linux instead of |
344 | ;; the absolute file name of its image. Detect that and correct it. | |
345 | (kernel (if (string=? kernel (direct-store-path kernel)) | |
346 | (string-append kernel "/" | |
8e815c5b | 347 | (system-linux-image-file-name)) |
912b857e | 348 | kernel)) |
8e815c5b LC |
349 | |
350 | (kernel-arguments | |
351 | (match (assq 'kernel-arguments rest) | |
352 | ((_ args) args) | |
353 | (#f '()))) ;the old format | |
354 | ||
355 | (initrd | |
356 | (match (assq 'initrd rest) | |
357 | (('initrd ('string-append directory file)) ;the old format | |
358 | (string-append directory file)) | |
359 | (('initrd (? string? file)) | |
12906d3e JN |
360 | file) |
361 | (#f #f))) | |
8e815c5b | 362 | |
aa864ebd JN |
363 | (multiboot-modules |
364 | (match (assq 'multiboot-modules rest) | |
365 | ((_ args) args) | |
366 | (#f '()))) | |
912b857e | 367 | |
8e815c5b | 368 | (store-device |
db4e8fd5 LC |
369 | ;; Linux device names like "/dev/sda1" are not suitable GRUB device |
370 | ;; identifiers, so we just filter them out. | |
371 | (ensure-not-/dev | |
372 | (match (assq 'store rest) | |
373 | (('store ('device #f) _ ...) | |
374 | root-device) | |
375 | (('store ('device device) _ ...) | |
376 | (device-sexp->device device)) | |
377 | (_ ;the old format | |
378 | root-device)))) | |
8e815c5b LC |
379 | |
380 | (store-mount-point | |
381 | (match (assq 'store rest) | |
382 | (('store ('device _) ('mount-point mount-point) _ ...) | |
383 | mount-point) | |
384 | (_ ;the old format | |
385 | "/"))))) | |
386 | (x ;unsupported format | |
b1059b38 LC |
387 | (warning (G_ "unrecognized boot parameters at '~a'~%") |
388 | (port-filename port)) | |
8e815c5b LC |
389 | #f))) |
390 | ||
391 | (define (read-boot-parameters-file system) | |
392 | "Read boot parameters from SYSTEM's (system or generation) \"parameters\" | |
393 | file and returns the corresponding <boot-parameters> object or #f if the | |
394 | format is unrecognized. | |
395 | The object has its kernel-arguments extended in order to make it bootable." | |
396 | (let* ((file (string-append system "/parameters")) | |
397 | (params (call-with-input-file file read-boot-parameters)) | |
a7ef45d9 LC |
398 | (root (boot-parameters-root-device params))) |
399 | (boot-parameters | |
400 | (inherit params) | |
401 | (kernel-arguments (append (bootable-kernel-arguments system root) | |
402 | (boot-parameters-kernel-arguments params)))))) | |
8b22107e | 403 | |
1975c754 | 404 | (define (boot-parameters->menu-entry conf) |
912b857e JN |
405 | (let* ((kernel (boot-parameters-kernel conf)) |
406 | (multiboot-modules (boot-parameters-multiboot-modules conf)) | |
407 | (multiboot? (pair? multiboot-modules))) | |
408 | (menu-entry | |
409 | (label (boot-parameters-label conf)) | |
410 | (device (boot-parameters-store-device conf)) | |
411 | (device-mount-point (boot-parameters-store-mount-point conf)) | |
412 | (linux (and (not multiboot?) kernel)) | |
535a6be2 | 413 | (linux-arguments (if (not multiboot?) |
912b857e JN |
414 | (boot-parameters-kernel-arguments conf) |
415 | '())) | |
416 | (initrd (boot-parameters-initrd conf)) | |
417 | (multiboot-kernel (and multiboot? kernel)) | |
418 | (multiboot-arguments (if multiboot? | |
419 | (boot-parameters-kernel-arguments conf) | |
420 | '())) | |
421 | (multiboot-modules (if multiboot? | |
422 | (boot-parameters-multiboot-modules conf) | |
423 | '()))))) | |
8b22107e | 424 | |
8e815c5b | 425 | \f |
40281c54 LC |
426 | ;;; |
427 | ;;; Services. | |
428 | ;;; | |
429 | ||
aa1145df LC |
430 | (define (non-boot-file-system-service os) |
431 | "Return the file system service for the file systems of OS that are not | |
432 | marked as 'needed-for-boot'." | |
023f391c | 433 | (define file-systems |
4d6b879c | 434 | (remove file-system-needed-for-boot? |
023f391c LC |
435 | (operating-system-file-systems os))) |
436 | ||
68a58775 LC |
437 | (define mapped-devices-for-boot |
438 | (operating-system-boot-mapped-devices os)) | |
439 | ||
5dae0186 | 440 | (define (device-mappings fs) |
ab64483f | 441 | (let ((device (file-system-device fs))) |
29824d80 | 442 | (if (string? device) ;title is 'device |
ab64483f LC |
443 | (filter (lambda (md) |
444 | (string=? (string-append "/dev/mapper/" | |
445 | (mapped-device-target md)) | |
446 | device)) | |
447 | (operating-system-mapped-devices os)) | |
448 | '()))) | |
5dae0186 | 449 | |
e502bf89 LC |
450 | (define (add-dependencies fs) |
451 | ;; Add the dependencies due to device mappings to FS. | |
452 | (file-system | |
453 | (inherit fs) | |
454 | (dependencies | |
68a58775 LC |
455 | (delete-duplicates |
456 | (remove (cut member <> mapped-devices-for-boot) | |
457 | (append (device-mappings fs) | |
458 | (file-system-dependencies fs))) | |
459 | eq?)))) | |
e502bf89 | 460 | |
aa1145df LC |
461 | (service file-system-service-type |
462 | (map add-dependencies file-systems))) | |
023f391c | 463 | |
68a58775 LC |
464 | (define (mapped-device-users device file-systems) |
465 | "Return the subset of FILE-SYSTEMS that use DEVICE." | |
de1c158f | 466 | (let ((target (string-append "/dev/mapper/" (mapped-device-target device)))) |
68a58775 LC |
467 | (filter (lambda (fs) |
468 | (or (member device (file-system-dependencies fs)) | |
469 | (and (string? (file-system-device fs)) | |
470 | (string=? (file-system-device fs) target)))) | |
471 | file-systems))) | |
de1c158f LC |
472 | |
473 | (define (operating-system-user-mapped-devices os) | |
474 | "Return the subset of mapped devices that can be installed in | |
475 | user-land--i.e., those not needed during boot." | |
9cb426b8 LC |
476 | (let ((devices (operating-system-mapped-devices os)) |
477 | (file-systems (operating-system-file-systems os))) | |
478 | (filter (lambda (md) | |
68a58775 LC |
479 | (let ((users (mapped-device-users md file-systems))) |
480 | (not (any file-system-needed-for-boot? users)))) | |
9cb426b8 | 481 | devices))) |
de1c158f LC |
482 | |
483 | (define (operating-system-boot-mapped-devices os) | |
484 | "Return the subset of mapped devices that must be installed during boot, | |
485 | from the initrd." | |
9cb426b8 LC |
486 | (let ((devices (operating-system-mapped-devices os)) |
487 | (file-systems (operating-system-file-systems os))) | |
488 | (filter (lambda (md) | |
68a58775 LC |
489 | (let ((users (mapped-device-users md file-systems))) |
490 | (any file-system-needed-for-boot? users))) | |
9cb426b8 | 491 | devices))) |
de1c158f | 492 | |
5dae0186 | 493 | (define (device-mapping-services os) |
be1c2c54 | 494 | "Return the list of device-mapping services for OS as a list." |
4da8c19e | 495 | (map device-mapping-service |
be1c2c54 | 496 | (operating-system-user-mapped-devices os))) |
5dae0186 | 497 | |
2a13d05e | 498 | (define (swap-services os) |
be1c2c54 LC |
499 | "Return the list of swap services for OS." |
500 | (map swap-service (operating-system-swap-devices os))) | |
2a13d05e | 501 | |
0c053a39 LC |
502 | (define* (system-linux-image-file-name #:optional |
503 | (target (or (%current-target-system) | |
504 | (%current-system)))) | |
505 | "Return the basename of the kernel image file for TARGET." | |
506 | (cond | |
507 | ((string-prefix? "arm" target) "zImage") | |
508 | ((string-prefix? "mips" target) "vmlinuz") | |
509 | ((string-prefix? "aarch64" target) "Image") | |
510 | (else "bzImage"))) | |
44d5f54e LC |
511 | |
512 | (define (operating-system-kernel-file os) | |
513 | "Return an object representing the absolute file name of the kernel image of | |
514 | OS." | |
912b857e JN |
515 | (if (operating-system-hurd os) |
516 | (file-append (operating-system-kernel os) "/boot/gnumach") | |
517 | (file-append (operating-system-kernel os) | |
518 | "/" (system-linux-image-file-name)))) | |
44d5f54e | 519 | |
f91ad0b1 DM |
520 | (define (package-for-kernel target-kernel module-package) |
521 | "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if | |
522 | possible (that is if there's a LINUX keyword argument in the build system)." | |
523 | (package | |
524 | (inherit module-package) | |
525 | (arguments | |
526 | (substitute-keyword-arguments (package-arguments module-package) | |
527 | ((#:linux kernel #f) | |
528 | target-kernel))))) | |
529 | ||
e06664da FP |
530 | (define %default-modprobe-blacklist |
531 | ;; List of kernel modules to blacklist by default. | |
fd31731b FP |
532 | '("usbmouse" ;races with bcm5974, see <https://bugs.gnu.org/35574> |
533 | "usbkbd")) ;races with usbhid, see <https://issues.guix.gnu.org/35574#18> | |
e06664da FP |
534 | |
535 | (define %default-kernel-arguments | |
536 | ;; Default arguments passed to the kernel. | |
537 | (list (string-append "modprobe.blacklist=" | |
538 | (string-join %default-modprobe-blacklist ",")) | |
539 | "quiet")) | |
540 | ||
69cae3d3 | 541 | (define* (operating-system-directory-base-entries os) |
d62e201c LC |
542 | "Return the basic entries of the 'system' directory of OS for use as the |
543 | value of the SYSTEM-SERVICE-TYPE service." | |
cda75110 LC |
544 | (let* ((locale (operating-system-locale-directory os)) |
545 | (kernel (operating-system-kernel os)) | |
2b76179e | 546 | (hurd (operating-system-hurd os)) |
cda75110 | 547 | (modules (operating-system-kernel-loadable-modules os)) |
2b76179e JN |
548 | (kernel (if hurd |
549 | kernel | |
550 | (profile | |
551 | (content (packages->manifest | |
552 | (cons kernel | |
553 | (map (lambda (module) | |
554 | (if (package? module) | |
555 | (package-for-kernel kernel | |
556 | module) | |
557 | module)) | |
558 | modules)))) | |
559 | (hooks (list linux-module-database))))) | |
560 | (initrd (and (not hurd) (operating-system-initrd-file os))) | |
cda75110 | 561 | (params (operating-system-boot-parameters-file os))) |
0e5c2d5e | 562 | `(("kernel" ,kernel) |
2b76179e | 563 | ,@(if hurd `(("hurd" ,hurd)) '()) |
0e5c2d5e | 564 | ("parameters" ,params) |
2b76179e | 565 | ,@(if initrd `(("initrd" ,initrd)) '()) |
0e5c2d5e | 566 | ("locale" ,locale)))) ;used by libc |
69cae3d3 | 567 | |
f8885eca | 568 | (define (operating-system-default-essential-services os) |
217a5b85 LC |
569 | "Return the list of essential services for OS. These are special services |
570 | that implement part of what's declared in OS are responsible for low-level | |
69cae3d3 | 571 | bookkeeping." |
d6e2a622 LC |
572 | (define known-fs |
573 | (map file-system-mount-point (operating-system-file-systems os))) | |
574 | ||
be1c2c54 LC |
575 | (let* ((mappings (device-mapping-services os)) |
576 | (root-fs (root-file-system-service)) | |
aa1145df | 577 | (other-fs (non-boot-file-system-service os)) |
be1c2c54 | 578 | (swaps (swap-services os)) |
206a28d8 | 579 | (procs (service user-processes-service-type)) |
d62e201c | 580 | (host-name (host-name-service (operating-system-host-name os))) |
69cae3d3 | 581 | (entries (operating-system-directory-base-entries os))) |
d62e201c LC |
582 | (cons* (service system-service-type entries) |
583 | %boot-service | |
0adfe95a | 584 | |
661c237b | 585 | ;; %SHEPHERD-ROOT-SERVICE must come last so that the gexp that |
d4053c71 | 586 | ;; execs shepherd comes last in the boot script (XXX). Likewise, |
661c237b | 587 | ;; the cleanup service must come first so that its gexp runs before |
d4053c71 | 588 | ;; activation code. |
be7be9e8 | 589 | (service cleanup-service-type #f) |
661c237b LC |
590 | %activation-service |
591 | %shepherd-root-service | |
0adfe95a LC |
592 | |
593 | (pam-root-service (operating-system-pam-services os)) | |
594 | (account-service (append (operating-system-accounts os) | |
595 | (operating-system-groups os)) | |
596 | (operating-system-skeletons os)) | |
597 | (operating-system-etc-service os) | |
aea1a42e LC |
598 | (service fstab-service-type |
599 | (filter file-system-needed-for-boot? | |
600 | (operating-system-file-systems os))) | |
6bad7524 SB |
601 | (session-environment-service |
602 | (operating-system-environment-variables os)) | |
6c445817 | 603 | host-name procs root-fs |
0adfe95a LC |
604 | (service setuid-program-service-type |
605 | (operating-system-setuid-programs os)) | |
af4c3fd5 LC |
606 | (service profile-service-type |
607 | (operating-system-packages os)) | |
aa1145df LC |
608 | other-fs |
609 | (append mappings swaps | |
0adfe95a | 610 | |
69cae3d3 LC |
611 | ;; Add the firmware service. |
612 | (list %linux-bare-metal-service | |
613 | (service firmware-service-type | |
614 | (operating-system-firmware os))))))) | |
615 | ||
45b2cb43 | 616 | (define (hurd-default-essential-services os) |
2b76179e JN |
617 | (let ((entries (operating-system-directory-base-entries os))) |
618 | (list (service system-service-type entries) | |
619 | %boot-service | |
620 | %hurd-startup-service | |
621 | %activation-service | |
622 | %shepherd-root-service | |
623 | (service user-processes-service-type) | |
624 | (account-service (append (operating-system-accounts os) | |
625 | (operating-system-groups os)) | |
626 | (operating-system-skeletons os)) | |
627 | (root-file-system-service) | |
628 | (service file-system-service-type '()) | |
629 | (service fstab-service-type | |
630 | (filter file-system-needed-for-boot? | |
631 | (operating-system-file-systems os))) | |
632 | (pam-root-service (operating-system-pam-services os)) | |
633 | (operating-system-etc-service os) | |
634 | (service profile-service-type (operating-system-packages os))))) | |
45b2cb43 | 635 | |
69cae3d3 LC |
636 | (define* (operating-system-services os) |
637 | "Return all the services of OS, including \"essential\" services." | |
d466b1fc LC |
638 | (instantiate-missing-services |
639 | (append (operating-system-user-services os) | |
69cae3d3 | 640 | (operating-system-essential-services os)))) |
217a5b85 | 641 | |
9fcfe30d LC |
642 | (define (operating-system-with-gc-roots os roots) |
643 | "Return a variant of OS where ROOTS are registered as GC roots." | |
644 | (operating-system | |
645 | (inherit os) | |
646 | ||
647 | ;; We use this procedure for the installation OS, which already defines GC | |
648 | ;; roots. Add ROOTS to those. | |
649 | (services (cons (simple-service 'extra-root | |
650 | gc-root-service-type roots) | |
651 | (operating-system-user-services os))))) | |
652 | ||
33b7cb7a LC |
653 | (define* (operating-system-with-provenance os #:optional config-file) |
654 | "Return a variant of OS that stores its own provenance information, | |
655 | including CONFIG-FILE, if available. This is achieved by adding an instance | |
656 | of PROVENANCE-SERVICE-TYPE to its services." | |
657 | (operating-system | |
658 | (inherit os) | |
659 | (services (cons (service provenance-service-type config-file) | |
660 | (operating-system-user-services os))))) | |
661 | ||
40281c54 LC |
662 | \f |
663 | ;;; | |
664 | ;;; /etc. | |
665 | ;;; | |
666 | ||
f34c56be LC |
667 | (define %base-firmware |
668 | ;; Firmware usable by default. | |
52db41af EB |
669 | (list ath9k-htc-firmware |
670 | openfwwf-firmware)) | |
f34c56be | 671 | |
93664fee BW |
672 | (define %base-packages-utils |
673 | ;; Default set of utilities packages. | |
674 | (cons* procps psmisc which | |
675 | (@ (gnu packages admin) shadow) ;for 'passwd' | |
676 | ||
030f6f48 | 677 | guile-3.0 |
93664fee BW |
678 | |
679 | ;; The packages below are also in %FINAL-INPUTS, so take them from | |
680 | ;; there to avoid duplication. | |
030f6f48 MB |
681 | (list bash coreutils findutils grep sed |
682 | diffutils patch gawk tar gzip bzip2 xz lzip))) | |
93664fee BW |
683 | |
684 | (define %base-packages-linux | |
685 | ;; Default set of linux specific packages. | |
686 | (list pciutils usbutils | |
687 | util-linux+udev | |
688 | ;; Get 'insmod' & co. from kmod, not module-init-tools, since udev | |
689 | ;; already depends on it anyway. | |
690 | kmod eudev)) | |
691 | ||
692 | (define %base-packages-interactive | |
693 | ;; Default set of common interactive packages. | |
694 | (list less zile nano | |
695 | man-db | |
696 | info-reader ;the standalone Info reader (no Perl) | |
697 | bash-completion | |
698 | kbd | |
699 | ;; The 'sudo' command is already in %SETUID-PROGRAMS, but we also | |
700 | ;; want the other commands and the man pages (notably because | |
701 | ;; auto-completion in Emacs shell relies on man pages.) | |
702 | sudo | |
703 | guile-readline guile-colorized)) | |
704 | ||
705 | (define %base-packages-networking | |
706 | ;; Default set of networking packages. | |
707 | (list inetutils isc-dhcp | |
708 | iproute | |
709 | ;; wireless-tools is deprecated in favor of iw, but it's still what | |
710 | ;; many people are familiar with, so keep it around. | |
711 | iw wireless-tools)) | |
712 | ||
6f436c54 LC |
713 | (define %base-packages |
714 | ;; Default set of packages globally visible. It should include anything | |
715 | ;; required for basic administrator tasks. | |
93664fee BW |
716 | (append (list e2fsprogs) |
717 | %base-packages-interactive | |
718 | %base-packages-linux | |
719 | %base-packages-networking | |
720 | %base-packages-utils)) | |
6f436c54 | 721 | |
548d4c13 LC |
722 | (define %default-issue |
723 | ;; Default contents for /etc/issue. | |
724 | " | |
725 | This is the GNU system. Welcome.\n") | |
726 | ||
568841d4 LC |
727 | (define (local-host-aliases host-name) |
728 | "Return aliases for HOST-NAME, to be used in /etc/hosts." | |
729 | (string-append "127.0.0.1 localhost " host-name "\n" | |
730 | "::1 localhost " host-name "\n")) | |
731 | ||
c65e1834 LC |
732 | (define (default-/etc/hosts host-name) |
733 | "Return the default /etc/hosts file." | |
24e02c28 | 734 | (plain-file "hosts" (local-host-aliases host-name))) |
c65e1834 | 735 | |
0adfe95a LC |
736 | (define* (operating-system-etc-service os) |
737 | "Return a <service> that builds containing the static part of the /etc | |
738 | directory." | |
f5ca79d2 | 739 | (let* ((login.defs |
e453da13 LF |
740 | (plain-file "login.defs" |
741 | (string-append | |
742 | "# Default paths for non-login shells started by su(1).\n" | |
743 | "ENV_PATH /run/setuid-programs:" | |
744 | "/run/current-system/profile/bin:" | |
745 | "/run/current-system/profile/sbin\n" | |
746 | "ENV_SUPATH /run/setuid-programs:" | |
747 | "/run/current-system/profile/bin:" | |
748 | "/run/current-system/profile/sbin\n"))) | |
0adfe95a | 749 | |
f5ca79d2 JN |
750 | (hurd (operating-system-hurd os)) |
751 | (issue (plain-file "issue" (operating-system-issue os))) | |
752 | (nsswitch (operating-system-name-service-switch os)) | |
753 | (nsswitch (and nsswitch | |
754 | (plain-file "nsswitch.conf" | |
755 | (name-service-switch->string nsswitch)))) | |
756 | (sudoers (operating-system-sudoers-file os)) | |
0adfe95a LC |
757 | |
758 | ;; Startup file for POSIX-compliant login shells, which set system-wide | |
759 | ;; environment variables. | |
760 | (profile (mixed-text-file "profile" "\ | |
c05c4321 | 761 | # Crucial variables that could be missing in the profiles' 'etc/profile' |
d9959421 LC |
762 | # because they would require combining both profiles. |
763 | # FIXME: See <http://bugs.gnu.org/20255>. | |
97ab2c0f | 764 | export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man |
8d09bfe2 | 765 | export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info |
00239d05 SB |
766 | export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share |
767 | export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg | |
768 | ||
ce380150 TD |
769 | # Make sure libXcursor finds cursors installed into user or system profiles. See <http://bugs.gnu.org/24445> |
770 | export XCURSOR_PATH=$HOME/.icons:$HOME/.guix-profile/share/icons:/run/current-system/profile/share/icons | |
771 | ||
d9959421 LC |
772 | # Ignore the default value of 'PATH'. |
773 | unset PATH | |
774 | ||
775 | # Load the system profile's settings. | |
bd7e136d | 776 | GUIX_PROFILE=/run/current-system/profile ; \\ |
669786da | 777 | . /run/current-system/profile/etc/profile |
d9959421 | 778 | |
cad7e6ab CSLL |
779 | # Since 'lshd' does not use pam_env, /etc/environment must be explicitly |
780 | # loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>. | |
781 | # We need 'PATH' to be defined here, for 'cat' and 'cut'. Do this before | |
782 | # reading the user's 'etc/profile' to allow variables to be overridden. | |
783 | if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\ | |
784 | -a -z \"$LINUX_MODULE_DIRECTORY\" ] | |
785 | then | |
786 | . /etc/environment | |
787 | export `cat /etc/environment | cut -d= -f1` | |
788 | fi | |
789 | ||
8d09bfe2 LC |
790 | # Arrange so that ~/.config/guix/current comes first. |
791 | for profile in \"$HOME/.guix-profile\" \"$HOME/.config/guix/current\" | |
cdc5b932 LC |
792 | do |
793 | if [ -f \"$profile/etc/profile\" ] | |
794 | then | |
795 | # Load the user profile's settings. | |
796 | GUIX_PROFILE=\"$profile\" ; \\ | |
797 | . \"$profile/etc/profile\" | |
798 | else | |
799 | # At least define this one so that basic things just work | |
800 | # when the user installs their first package. | |
801 | export PATH=\"$profile/bin:$PATH\" | |
802 | fi | |
803 | done | |
d9959421 | 804 | |
a854525a LC |
805 | # Prepend setuid programs. |
806 | export PATH=/run/setuid-programs:$PATH | |
807 | ||
8d09bfe2 LC |
808 | # Arrange so that ~/.config/guix/current/share/info comes first. |
809 | export INFOPATH=\"$HOME/.config/guix/current/share/info:$INFOPATH\" | |
810 | ||
11202482 LC |
811 | # Set the umask, notably for users logging in via 'lsh'. |
812 | # See <http://bugs.gnu.org/22650>. | |
813 | umask 022 | |
2a5f0db4 | 814 | |
c08da2ee LC |
815 | # Allow Hunspell-based applications (IceCat, LibreOffice, etc.) to |
816 | # find dictionaries. | |
817 | export DICPATH=\"$HOME/.guix-profile/share/hunspell:/run/current-system/profile/share/hunspell\" | |
818 | ||
4af7c83b LC |
819 | # Allow GStreamer-based applications to find plugins. |
820 | export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\" | |
821 | ||
1d167b6e LC |
822 | if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ] |
823 | then | |
824 | # Load Bash-specific initialization code. | |
669786da | 825 | . /etc/bashrc |
1d167b6e | 826 | fi |
40281c54 | 827 | ")) |
1d167b6e | 828 | |
0adfe95a | 829 | (bashrc (plain-file "bashrc" "\ |
1d167b6e LC |
830 | # Bash-specific initialization. |
831 | ||
832 | # The 'bash-completion' package. | |
833 | if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ] | |
834 | then | |
835 | # Bash-completion sources ~/.bash_completion. It installs a dynamic | |
836 | # completion loader that searches its own completion files as well | |
837 | # as those in ~/.guix-profile and /run/current-system/profile. | |
838 | source /run/current-system/profile/etc/profile.d/bash_completion.sh | |
0adfe95a LC |
839 | fi\n"))) |
840 | (etc-service | |
9e41130b LC |
841 | `(("services" ,(file-append net-base "/etc/services")) |
842 | ("protocols" ,(file-append net-base "/etc/protocols")) | |
843 | ("rpc" ,(file-append net-base "/etc/rpc")) | |
0adfe95a LC |
844 | ("login.defs" ,#~#$login.defs) |
845 | ("issue" ,#~#$issue) | |
f5ca79d2 | 846 | ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '()) |
0adfe95a LC |
847 | ("profile" ,#~#$profile) |
848 | ("bashrc" ,#~#$bashrc) | |
849 | ("hosts" ,#~#$(or (operating-system-hosts-file os) | |
850 | (default-/etc/hosts (operating-system-host-name os)))) | |
c694520b TD |
851 | ;; Write the operating-system-host-name to /etc/hostname to prevent |
852 | ;; NetworkManager from changing the system's hostname when connecting | |
853 | ;; to certain networks. Some discussion at | |
854 | ;; https://lists.gnu.org/archive/html/help-guix/2017-09/msg00037.html | |
855 | ("hostname" ,(plain-file "hostname" (operating-system-host-name os))) | |
2a80d9e5 TS |
856 | ;; Some programs (e.g., GLib) look at /etc/timezone to find the |
857 | ;; name of the current timezone. For details, see | |
858 | ;; https://lists.gnu.org/archive/html/guix-devel/2019-07/msg00166.html | |
859 | ("timezone" ,(plain-file "timezone" (operating-system-timezone os))) | |
9e41130b LC |
860 | ("localtime" ,(file-append tzdata "/share/zoneinfo/" |
861 | (operating-system-timezone os))) | |
f5ca79d2 JN |
862 | ,@(if sudoers `(("sudoers" ,sudoers)) '()) |
863 | ,@(if hurd | |
864 | `(("login" ,(file-append hurd "/etc/login")) | |
5681ce50 JN |
865 | ("motd" ,(file-append hurd "/etc/motd")) |
866 | ("ttys" ,(file-append hurd "/etc/ttys"))) | |
f5ca79d2 | 867 | '()))))) |
033adfe7 | 868 | |
ab6a279a LC |
869 | (define %root-account |
870 | ;; Default root account. | |
871 | (user-account | |
872 | (name "root") | |
873 | (password "") | |
874 | (uid 0) (group "root") | |
875 | (comment "System administrator") | |
876 | (home-directory "/root"))) | |
877 | ||
0b6f49ef | 878 | (define (operating-system-accounts os) |
0adfe95a LC |
879 | "Return the user accounts for OS, including an obligatory 'root' account, |
880 | and excluding accounts requested by services." | |
881 | ;; Make sure there's a root account. | |
882 | (if (find (lambda (user) | |
883 | (and=> (user-account-uid user) zero?)) | |
884 | (operating-system-users os)) | |
885 | (operating-system-users os) | |
886 | (cons %root-account (operating-system-users os)))) | |
0b6f49ef | 887 | |
84765839 LC |
888 | (define (maybe-string->file file-name thing) |
889 | "If THING is a string, return a <plain-file> with THING as its content. | |
890 | Otherwise just return THING. | |
891 | ||
892 | This is for backward-compatibility of fields that used to be strings and are | |
893 | now file-like objects.." | |
894 | (match thing | |
895 | ((? string?) | |
69daee23 | 896 | (warning (G_ "using a string for file '~a' is deprecated; \ |
84765839 LC |
897 | use 'plain-file' instead~%") |
898 | file-name) | |
899 | (plain-file file-name thing)) | |
900 | (x | |
901 | x))) | |
902 | ||
24e02c28 LC |
903 | (define (maybe-file->monadic file-name thing) |
904 | "If THING is a value in %STORE-MONAD, return it as is; otherwise return | |
905 | THING in the %STORE-MONAD. | |
906 | ||
907 | This is for backward-compatibility of fields that used to be monadic values | |
908 | and are now file-like objects." | |
909 | (with-monad %store-monad | |
910 | (match thing | |
911 | ((? procedure?) | |
69daee23 | 912 | (warning (G_ "using a monadic value for '~a' is deprecated; \ |
24e02c28 LC |
913 | use 'plain-file' instead~%") |
914 | file-name) | |
915 | thing) | |
916 | (x | |
917 | (return x))))) | |
918 | ||
0b6f49ef LC |
919 | (define (operating-system-etc-directory os) |
920 | "Return that static part of the /etc directory of OS." | |
0adfe95a LC |
921 | (etc-directory |
922 | (fold-services (operating-system-services os) | |
923 | #:target-type etc-service-type))) | |
033adfe7 | 924 | |
6bad7524 SB |
925 | (define (operating-system-environment-variables os) |
926 | "Return the environment variables of OS for | |
927 | @var{session-environment-service-type}, to be used in @file{/etc/environment}." | |
928 | `(("LANG" . ,(operating-system-locale os)) | |
54757499 LC |
929 | ;; Note: No need to set 'TZ' since (1) we provide /etc/localtime, and (2) |
930 | ;; it doesn't work for setuid binaries. See <https://bugs.gnu.org/29212>. | |
9e41130b | 931 | ("TZDIR" . ,(file-append tzdata "/share/zoneinfo")) |
6bad7524 SB |
932 | ;; Tell 'modprobe' & co. where to look for modules. |
933 | ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules") | |
934 | ;; These variables are honored by OpenSSL (libssl) and Git. | |
935 | ("SSL_CERT_DIR" . "/etc/ssl/certs") | |
936 | ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt") | |
937 | ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt") | |
ae05e366 LC |
938 | |
939 | ;; 'GTK_DATA_PREFIX' must name one directory where GTK+ themes are | |
940 | ;; searched for. | |
941 | ("GTK_DATA_PREFIX" . "/run/current-system/profile") | |
942 | ||
6bad7524 SB |
943 | ;; By default, applications that use D-Bus, such as Emacs, abort at startup |
944 | ;; when /etc/machine-id is missing. Make sure these warnings are non-fatal. | |
946465bb LC |
945 | ("DBUS_FATAL_WARNINGS" . "0") |
946 | ||
947 | ;; XXX: Normally we wouldn't need to do this, but our glibc@2.23 package | |
948 | ;; used to look things up in 'PREFIX/lib/locale' instead of | |
949 | ;; '/run/current-system/locale' as was intended. Keep this hack around so | |
950 | ;; that people who still have glibc@2.23-using packages in their profiles | |
951 | ;; can use them correctly. | |
952 | ;; TODO: Remove when glibc@2.23 is long gone. | |
953 | ("GUIX_LOCPATH" . "/run/current-system/locale"))) | |
6bad7524 | 954 | |
09e028f4 LC |
955 | (define %setuid-programs |
956 | ;; Default set of setuid-root programs. | |
3b65abac | 957 | (let ((shadow (@ (gnu packages admin) shadow))) |
9e41130b | 958 | (list (file-append shadow "/bin/passwd") |
f6c6970e | 959 | (file-append shadow "/bin/sg") |
9e41130b | 960 | (file-append shadow "/bin/su") |
f6c6970e | 961 | (file-append shadow "/bin/newgrp") |
852241eb SB |
962 | (file-append shadow "/bin/newuidmap") |
963 | (file-append shadow "/bin/newgidmap") | |
9e41130b LC |
964 | (file-append inetutils "/bin/ping") |
965 | (file-append inetutils "/bin/ping6") | |
966 | (file-append sudo "/bin/sudo") | |
5144df2c | 967 | (file-append sudo "/bin/sudoedit") |
19944227 LC |
968 | (file-append fuse "/bin/fusermount") |
969 | ||
970 | ;; To allow mounts with the "user" option, "mount" and "umount" must | |
971 | ;; be setuid-root. | |
972 | (file-append util-linux "/bin/mount") | |
973 | (file-append util-linux "/bin/umount")))) | |
69689380 LC |
974 | |
975 | (define %sudoers-specification | |
976 | ;; Default /etc/sudoers contents: 'root' and all members of the 'wheel' | |
977 | ;; group can do anything. See | |
978 | ;; <http://www.sudo.ws/sudo/man/1.8.10/sudoers.man.html>. | |
979 | ;; TODO: Add a declarative API. | |
84765839 LC |
980 | (plain-file "sudoers" "\ |
981 | root ALL=(ALL) ALL | |
982 | %wheel ALL=(ALL) ALL\n")) | |
09e028f4 | 983 | |
69cae3d3 | 984 | (define* (operating-system-activation-script os) |
484a2b3a LC |
985 | "Return the activation script for OS---i.e., the code that \"activates\" the |
986 | stateful part of OS, including user accounts and groups, special directories, | |
987 | etc." | |
69cae3d3 | 988 | (let* ((services (operating-system-services os)) |
0adfe95a LC |
989 | (activation (fold-services services |
990 | #:target-type activation-service-type))) | |
991 | (activation-service->script activation))) | |
484a2b3a | 992 | |
69cae3d3 | 993 | (define* (operating-system-boot-script os) |
484a2b3a | 994 | "Return the boot script for OS---i.e., the code started by the initrd once |
69cae3d3 LC |
995 | we're running in the final root." |
996 | (let* ((services (operating-system-services os)) | |
d62e201c | 997 | (boot (fold-services services #:target-type boot-service-type))) |
efe7d19a | 998 | (service-value boot))) |
2106d3fc | 999 | |
b2fef041 LC |
1000 | (define (operating-system-user-accounts os) |
1001 | "Return the list of user accounts of OS." | |
1002 | (let* ((services (operating-system-services os)) | |
1003 | (account (fold-services services | |
1004 | #:target-type account-service-type))) | |
1005 | (filter user-account? | |
efe7d19a | 1006 | (service-value account)))) |
b2fef041 LC |
1007 | |
1008 | (define (operating-system-shepherd-service-names os) | |
1009 | "Return the list of Shepherd service names for OS." | |
1010 | (append-map shepherd-service-provision | |
efe7d19a | 1011 | (service-value |
b2fef041 LC |
1012 | (fold-services (operating-system-services os) |
1013 | #:target-type | |
1014 | shepherd-root-service-type)))) | |
1015 | ||
69cae3d3 | 1016 | (define* (operating-system-derivation os) |
d62e201c | 1017 | "Return a derivation that builds OS." |
69cae3d3 | 1018 | (let* ((services (operating-system-services os)) |
d62e201c LC |
1019 | (system (fold-services services))) |
1020 | ;; SYSTEM contains the derivation as a monadic value. | |
efe7d19a | 1021 | (service-value system))) |
d62e201c | 1022 | |
69cae3d3 | 1023 | (define* (operating-system-profile os) |
af4c3fd5 LC |
1024 | "Return a derivation that builds the system profile of OS." |
1025 | (mlet* %store-monad | |
69cae3d3 | 1026 | ((services -> (operating-system-services os)) |
af4c3fd5 LC |
1027 | (profile (fold-services services |
1028 | #:target-type profile-service-type))) | |
1029 | (match profile | |
1030 | (("profile" profile) | |
1031 | (return profile))))) | |
1032 | ||
83bcd0b8 LC |
1033 | (define (operating-system-root-file-system os) |
1034 | "Return the root file system of OS." | |
d7e9e0bb LC |
1035 | (or (find (lambda (fs) |
1036 | (string=? "/" (file-system-mount-point fs))) | |
1037 | (operating-system-file-systems os)) | |
1038 | (raise (condition | |
1039 | (&message (message "missing root file system")) | |
1040 | (&error-location | |
1041 | (location (operating-system-location os))))))) | |
83bcd0b8 | 1042 | |
b4140694 LC |
1043 | (define (operating-system-initrd-file os) |
1044 | "Return a gexp denoting the initrd file of OS." | |
83bcd0b8 | 1045 | (define boot-file-systems |
4d6b879c | 1046 | (filter file-system-needed-for-boot? |
83bcd0b8 LC |
1047 | (operating-system-file-systems os))) |
1048 | ||
de1c158f LC |
1049 | (define mapped-devices |
1050 | (operating-system-boot-mapped-devices os)) | |
1051 | ||
1052 | (define make-initrd | |
1053 | (operating-system-initrd os)) | |
1054 | ||
d422cbb3 LC |
1055 | (make-initrd boot-file-systems |
1056 | #:linux (operating-system-kernel os) | |
1057 | #:linux-modules | |
1058 | (operating-system-initrd-modules os) | |
ae7a316b LC |
1059 | #:mapped-devices mapped-devices |
1060 | #:keyboard-layout (operating-system-keyboard-layout os))) | |
b4140694 | 1061 | |
78fbf2bd MO |
1062 | (define* (operating-system-uuid os #:optional (type 'dce)) |
1063 | "Compute UUID object with a deterministic \"UUID\" for OS, of the given | |
1064 | TYPE (one of 'iso9660 or 'dce). Return a UUID object." | |
1065 | ;; Note: For this to be deterministic, we must not hash things that contains | |
1066 | ;; (directly or indirectly) procedures, for example. That rules out | |
1067 | ;; anything that contains gexps, thunk or delayed record fields, etc. | |
1068 | ||
1069 | (define service-name | |
1070 | (compose service-type-name service-kind)) | |
1071 | ||
1072 | (define (file-system-digest fs) | |
1073 | ;; Return a hashable digest that does not contain 'dependencies' since | |
1074 | ;; this field can contain procedures. | |
1075 | (let ((device (file-system-device fs))) | |
1076 | (list (file-system-mount-point fs) | |
1077 | (file-system-type fs) | |
1078 | (file-system-device->string device) | |
1079 | (file-system-options fs)))) | |
1080 | ||
1081 | (if (eq? type 'iso9660) | |
1082 | (let ((pad (compose (cut string-pad <> 2 #\0) | |
1083 | number->string)) | |
1084 | (h (hash (map service-name (operating-system-services os)) | |
1085 | 3600))) | |
1086 | (bytevector->uuid | |
1087 | (string->iso9660-uuid | |
1088 | (string-append "1970-01-01-" | |
1089 | (pad (hash (operating-system-host-name os) 24)) "-" | |
1090 | (pad (quotient h 60)) "-" | |
1091 | (pad (modulo h 60)) "-" | |
1092 | (pad (hash (map file-system-digest | |
1093 | (operating-system-file-systems os)) | |
1094 | 100)))) | |
1095 | 'iso9660)) | |
1096 | (bytevector->uuid | |
1097 | (uint-list->bytevector | |
1098 | (list (hash (map file-system-digest | |
1099 | (operating-system-file-systems os)) | |
1100 | (- (expt 2 32) 1)) | |
1101 | (hash (operating-system-host-name os) | |
1102 | (- (expt 2 32) 1)) | |
1103 | (hash (map service-name (operating-system-services os)) | |
1104 | (- (expt 2 32) 1)) | |
1105 | (hash (map file-system-digest (operating-system-file-systems os)) | |
1106 | (- (expt 2 32) 1))) | |
1107 | (endianness little) | |
1108 | 4) | |
1109 | type))) | |
1110 | ||
f5582b2c LC |
1111 | (define (locale-name->definition* name) |
1112 | "Variant of 'locale-name->definition' that raises an error upon failure." | |
1113 | (match (locale-name->definition name) | |
1114 | (#f | |
1115 | (raise (condition | |
1116 | (&message | |
69daee23 | 1117 | (message (format #f (G_ "~a: invalid locale name") name)))))) |
f5582b2c LC |
1118 | (def def))) |
1119 | ||
598e19dc LC |
1120 | (define (operating-system-locale-directory os) |
1121 | "Return the directory containing the locales compiled for the definitions | |
1122 | listed in OS. The C library expects to find it under | |
1123 | /run/current-system/locale." | |
f5582b2c LC |
1124 | (define name |
1125 | (operating-system-locale os)) | |
1126 | ||
1127 | (define definitions | |
1128 | ;; While we're at it, check whether NAME is defined and add it if needed. | |
1129 | (if (member name (map locale-definition-name | |
1130 | (operating-system-locale-definitions os))) | |
1131 | (operating-system-locale-definitions os) | |
1132 | (cons (locale-name->definition* name) | |
1133 | (operating-system-locale-definitions os)))) | |
1134 | ||
1135 | (locale-directory definitions | |
34760ae7 | 1136 | #:libcs (operating-system-locale-libcs os))) |
598e19dc | 1137 | |
e6cd8581 | 1138 | (define* (kernel->boot-label kernel #:key hurd) |
c2e9942b | 1139 | "Return a label for the bootloader menu entry that boots KERNEL." |
e6cd8581 JN |
1140 | (cond ((package? hurd) |
1141 | (string-append "GNU with the " | |
1142 | (string-titlecase (package-name hurd)) " " | |
1143 | (package-version hurd))) | |
1144 | ((package? kernel) | |
bdc61ff9 P |
1145 | (string-append "GNU with " |
1146 | (string-titlecase (package-name kernel)) " " | |
4ce3a326 | 1147 | (package-version kernel))) |
bdc61ff9 P |
1148 | ((inferior-package? kernel) |
1149 | (string-append "GNU with " | |
b12f8720 | 1150 | (string-titlecase (inferior-package-name kernel)) " " |
4ce3a326 | 1151 | (inferior-package-version kernel))) |
bdc61ff9 | 1152 | (else "GNU"))) |
2d23e6f0 | 1153 | |
3f03a198 LC |
1154 | (define (operating-system-default-label os) |
1155 | "Return the default label for OS, as it will appear in the bootloader menu | |
1156 | entry." | |
e6cd8581 JN |
1157 | (kernel->boot-label (operating-system-kernel os) |
1158 | #:hurd (operating-system-hurd os))) | |
3f03a198 | 1159 | |
6b779207 LC |
1160 | (define (store-file-system file-systems) |
1161 | "Return the file system object among FILE-SYSTEMS that contains the store." | |
1162 | (match (filter (lambda (fs) | |
1163 | (and (file-system-mount? fs) | |
1164 | (not (memq 'bind-mount (file-system-flags fs))) | |
1165 | (string-prefix? (file-system-mount-point fs) | |
1166 | (%store-prefix)))) | |
1167 | file-systems) | |
1168 | ((and candidates (head . tail)) | |
1169 | (reduce (lambda (fs1 fs2) | |
1170 | (if (> (string-length (file-system-mount-point fs1)) | |
1171 | (string-length (file-system-mount-point fs2))) | |
1172 | fs1 | |
1173 | fs2)) | |
1174 | head | |
1175 | candidates)))) | |
1176 | ||
1177 | (define (operating-system-store-file-system os) | |
1178 | "Return the file system that contains the store of OS." | |
1179 | (store-file-system (operating-system-file-systems os))) | |
1180 | ||
c76b3046 | 1181 | (define* (operating-system-bootcfg os #:optional (old-entries '())) |
5ece56dc LC |
1182 | "Return the bootloader configuration file for OS. Use OLD-ENTRIES, |
1183 | a list of <menu-entry>, to populate the \"old entries\" menu." | |
b460ba79 MC |
1184 | (let* ((file-systems (operating-system-file-systems os)) |
1185 | (root-fs (operating-system-root-file-system os)) | |
9782c822 LC |
1186 | (root-device (file-system-device root-fs)) |
1187 | (params (operating-system-boot-parameters | |
1188 | os root-device | |
1189 | #:system-kernel-arguments? #t)) | |
1190 | (entry (boot-parameters->menu-entry params)) | |
1191 | (bootloader-conf (operating-system-bootloader os))) | |
b460ba79 | 1192 | |
46c296dc LC |
1193 | (define generate-config-file |
1194 | (bootloader-configuration-file-generator | |
1195 | (bootloader-configuration-bootloader bootloader-conf))) | |
1196 | ||
9782c822 | 1197 | (generate-config-file bootloader-conf (list entry) |
b460ba79 | 1198 | #:old-entries old-entries |
e7b86a0d | 1199 | #:store-directory-prefix |
b460ba79 | 1200 | (btrfs-store-subvolume-file-name file-systems)))) |
b4140694 | 1201 | |
912b857e JN |
1202 | (define (operating-system-multiboot-modules os) |
1203 | (if (operating-system-hurd os) (hurd-multiboot-modules os) '())) | |
1204 | ||
1205 | (define (hurd-multiboot-modules os) | |
1206 | (let* ((hurd (operating-system-hurd os)) | |
1207 | (root-file-system-command | |
1208 | (list (file-append hurd "/hurd/ext2fs.static") | |
1209 | "ext2fs" | |
1210 | "--multiboot-command-line='${kernel-command-line}'" | |
1211 | "--host-priv-port='${host-port}'" | |
1212 | "--device-master-port='${device-port}'" | |
1213 | "--exec-server-task='${exec-task}'" | |
1214 | "--store-type=typed" | |
f25e8f76 | 1215 | "--x-xattr-translator-records" |
912b857e JN |
1216 | "'${root}'" "'$(task-create)'" "'$(task-resume)'")) |
1217 | (target (%current-target-system)) | |
1218 | (libc (if target | |
1219 | (with-parameters ((%current-target-system #f)) | |
1220 | ;; TODO: cross-libc has extra patches for the Hurd; | |
1221 | ;; remove in next rebuild cycle | |
1222 | (cross-libc target)) | |
1223 | glibc)) | |
1224 | (exec-server-command | |
1225 | (list (file-append libc "/lib/ld.so.1") "exec" | |
1226 | (file-append hurd "/hurd/exec") "'$(exec-task=task-create)'"))) | |
1227 | (list root-file-system-command exec-server-command))) | |
1228 | ||
a7ef45d9 LC |
1229 | (define* (operating-system-boot-parameters os root-device |
1230 | #:key system-kernel-arguments?) | |
1231 | "Return a monadic <boot-parameters> record that describes the boot | |
1232 | parameters of OS. When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments | |
1233 | such as '--root' and '--load' to <boot-parameters>." | |
395782f2 | 1234 | (let* ((initrd (and (not (operating-system-hurd os)) |
912b857e | 1235 | (operating-system-initrd-file os))) |
35b44681 LC |
1236 | (store (operating-system-store-file-system os)) |
1237 | (bootloader (bootloader-configuration-bootloader | |
1238 | (operating-system-bootloader os))) | |
1239 | (bootloader-name (bootloader-name bootloader)) | |
912b857e JN |
1240 | (label (operating-system-label os)) |
1241 | (multiboot-modules (operating-system-multiboot-modules os))) | |
35b44681 LC |
1242 | (boot-parameters |
1243 | (label label) | |
1244 | (root-device root-device) | |
1245 | (kernel (operating-system-kernel-file os)) | |
1246 | (kernel-arguments | |
1247 | (if system-kernel-arguments? | |
1248 | (operating-system-kernel-arguments os root-device) | |
1249 | (operating-system-user-kernel-arguments os))) | |
1250 | (initrd initrd) | |
912b857e | 1251 | (multiboot-modules multiboot-modules) |
35b44681 | 1252 | (bootloader-name bootloader-name) |
a28cfee8 LC |
1253 | (bootloader-menu-entries |
1254 | (bootloader-configuration-menu-entries (operating-system-bootloader os))) | |
35b44681 LC |
1255 | (store-device (ensure-not-/dev (file-system-device store))) |
1256 | (store-mount-point (file-system-mount-point store))))) | |
40fad1c2 | 1257 | |
9b336338 LC |
1258 | (define (device->sexp device) |
1259 | "Serialize DEVICE as an sexp (really, as an object with a read syntax.)" | |
1260 | (match device | |
1261 | ((? uuid? uuid) | |
075681d3 | 1262 | `(uuid ,(uuid-type uuid) ,(uuid-bytevector uuid))) |
a5acc17a LC |
1263 | ((? file-system-label? label) |
1264 | `(file-system-label ,(file-system-label->string label))) | |
9b336338 LC |
1265 | (_ |
1266 | device))) | |
1267 | ||
a7ef45d9 LC |
1268 | (define* (operating-system-boot-parameters-file os |
1269 | #:key system-kernel-arguments?) | |
40fad1c2 DM |
1270 | "Return a file that describes the boot parameters of OS. The primary use of |
1271 | this file is the reconstruction of GRUB menu entries for old configurations. | |
a7ef45d9 LC |
1272 | |
1273 | When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments such as '--root' | |
1274 | and '--load' to the returned file (since the returned file is then usually | |
1275 | stored into the content-addressed \"system\" directory, it's usually not a | |
1276 | good idea to give it because the content hash would change by the content hash | |
40fad1c2 | 1277 | being stored into the \"parameters\" file)." |
35b44681 LC |
1278 | (let* ((root (operating-system-root-file-system os)) |
1279 | (device (file-system-device root)) | |
1280 | (params (operating-system-boot-parameters | |
1281 | os device | |
1282 | #:system-kernel-arguments? | |
1283 | system-kernel-arguments?))) | |
2e37d158 LC |
1284 | (scheme-file "parameters" |
1285 | #~(boot-parameters | |
1286 | (version 0) | |
1287 | (label #$(boot-parameters-label params)) | |
1288 | (root-device | |
1289 | #$(device->sexp | |
1290 | (boot-parameters-root-device params))) | |
1291 | (kernel #$(boot-parameters-kernel params)) | |
1292 | (kernel-arguments | |
1293 | #$(boot-parameters-kernel-arguments params)) | |
2b76179e JN |
1294 | #$@(if (boot-parameters-initrd params) |
1295 | #~((initrd #$(boot-parameters-initrd params))) | |
1296 | #~()) | |
1297 | #$@(if (pair? (boot-parameters-multiboot-modules params)) | |
1298 | #~((multiboot-modules | |
1299 | #$(boot-parameters-multiboot-modules params))) | |
1300 | #~()) | |
2e37d158 LC |
1301 | (bootloader-name #$(boot-parameters-bootloader-name params)) |
1302 | (bootloader-menu-entries | |
1303 | #$(map menu-entry->sexp | |
1304 | (or (and=> (operating-system-bootloader os) | |
1305 | bootloader-configuration-menu-entries) | |
1306 | '()))) | |
1307 | (store | |
1308 | (device | |
1309 | #$(device->sexp (boot-parameters-store-device params))) | |
1310 | (mount-point #$(boot-parameters-store-mount-point | |
1311 | params)))) | |
1312 | #:set-load-path? #f))) | |
64e40dbb | 1313 | |
96da5d62 LC |
1314 | (define-gexp-compiler (operating-system-compiler (os <operating-system>) |
1315 | system target) | |
1316 | ((store-lift | |
1317 | (lambda (store) | |
1318 | ;; XXX: This is not super elegant but we can't pass SYSTEM and TARGET to | |
1319 | ;; 'operating-system-derivation'. | |
1320 | (run-with-store store (operating-system-derivation os) | |
1321 | #:system system | |
1322 | #:target target))))) | |
1323 | ||
033adfe7 | 1324 | ;;; system.scm ends here |