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