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