| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | |
| 13 | |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | |
| 20 | |
| 21 | |
| 22 | |
| 23 | |
| 24 | |
| 25 | |
| 26 | |
| 27 | |
| 28 | |
| 29 | |
| 30 |
|
| 31 | (define-module (gnu system)
|
| 32 | #:use-module (guix inferior)
|
| 33 | #:use-module (guix store)
|
| 34 | #:use-module (guix monads)
|
| 35 | #:use-module (guix gexp)
|
| 36 | #:use-module (guix records)
|
| 37 | #:use-module (guix packages)
|
| 38 | #:use-module (guix derivations)
|
| 39 | #:use-module (guix profiles)
|
| 40 | #:use-module ((guix utils) #:select (substitute-keyword-arguments))
|
| 41 | #:use-module (guix i18n)
|
| 42 | #:use-module (guix diagnostics)
|
| 43 | #:use-module (gnu packages admin)
|
| 44 | #:use-module (gnu packages base)
|
| 45 | #:use-module (gnu packages bash)
|
| 46 | #:use-module (gnu packages compression)
|
| 47 | #:use-module (gnu packages cross-base)
|
| 48 | #:use-module (gnu packages cryptsetup)
|
| 49 | #:use-module (gnu packages disk)
|
| 50 | #:use-module (gnu packages file-systems)
|
| 51 | #:use-module (gnu packages firmware)
|
| 52 | #:use-module (gnu packages gawk)
|
| 53 | #:use-module (gnu packages guile)
|
| 54 | #:use-module (gnu packages guile-xyz)
|
| 55 | #:use-module (gnu packages hurd)
|
| 56 | #:use-module (gnu packages less)
|
| 57 | #:use-module (gnu packages linux)
|
| 58 | #:use-module (gnu packages man)
|
| 59 | #:use-module (gnu packages nano)
|
| 60 | #:use-module (gnu packages nvi)
|
| 61 | #:use-module (gnu packages package-management)
|
| 62 | #:use-module (gnu packages pciutils)
|
| 63 | #:use-module (gnu packages texinfo)
|
| 64 | #:use-module (gnu packages zile)
|
| 65 | #:use-module (gnu services)
|
| 66 | #:use-module (gnu services shepherd)
|
| 67 | #:use-module (gnu services base)
|
| 68 | #:use-module (gnu bootloader)
|
| 69 | #:use-module (gnu system shadow)
|
| 70 | #:use-module (gnu system nss)
|
| 71 | #:use-module (gnu system locale)
|
| 72 | #:use-module (gnu system pam)
|
| 73 | #:use-module (gnu system linux-initrd)
|
| 74 | #:use-module (gnu system uuid)
|
| 75 | #:use-module (gnu system file-systems)
|
| 76 | #:use-module (gnu system mapped-devices)
|
| 77 | #:use-module (ice-9 match)
|
| 78 | #:use-module (srfi srfi-1)
|
| 79 | #:use-module (srfi srfi-26)
|
| 80 | #:use-module (srfi srfi-34)
|
| 81 | #:use-module (srfi srfi-35)
|
| 82 | #:use-module (rnrs bytevectors)
|
| 83 | #:export (operating-system
|
| 84 | operating-system?
|
| 85 | this-operating-system
|
| 86 |
|
| 87 | operating-system-bootloader
|
| 88 | operating-system-services
|
| 89 | operating-system-essential-services
|
| 90 | operating-system-default-essential-services
|
| 91 | operating-system-user-services
|
| 92 | operating-system-packages
|
| 93 | operating-system-host-name
|
| 94 | operating-system-hosts-file
|
| 95 | operating-system-hurd
|
| 96 | operating-system-kernel
|
| 97 | operating-system-kernel-file
|
| 98 | operating-system-kernel-arguments
|
| 99 | operating-system-label
|
| 100 | operating-system-default-label
|
| 101 | operating-system-initrd-modules
|
| 102 | operating-system-initrd
|
| 103 | operating-system-users
|
| 104 | operating-system-groups
|
| 105 | operating-system-issue
|
| 106 | operating-system-timezone
|
| 107 | operating-system-locale
|
| 108 | operating-system-locale-definitions
|
| 109 | operating-system-locale-libcs
|
| 110 | operating-system-mapped-devices
|
| 111 | operating-system-file-systems
|
| 112 | operating-system-store-file-system
|
| 113 | operating-system-user-mapped-devices
|
| 114 | operating-system-boot-mapped-devices
|
| 115 | operating-system-activation-script
|
| 116 | operating-system-user-accounts
|
| 117 | operating-system-shepherd-service-names
|
| 118 | operating-system-user-kernel-arguments
|
| 119 | operating-system-firmware
|
| 120 | operating-system-keyboard-layout
|
| 121 | operating-system-name-service-switch
|
| 122 | operating-system-pam-services
|
| 123 | operating-system-setuid-programs
|
| 124 | operating-system-skeletons
|
| 125 | operating-system-sudoers-file
|
| 126 | operating-system-swap-devices
|
| 127 | operating-system-kernel-loadable-modules
|
| 128 | operating-system-location
|
| 129 |
|
| 130 | operating-system-derivation
|
| 131 | operating-system-profile
|
| 132 | operating-system-bootcfg
|
| 133 | operating-system-etc-directory
|
| 134 | operating-system-locale-directory
|
| 135 | operating-system-boot-script
|
| 136 | operating-system-uuid
|
| 137 |
|
| 138 | system-linux-image-file-name
|
| 139 | operating-system-with-gc-roots
|
| 140 | operating-system-with-provenance
|
| 141 |
|
| 142 | hurd-default-essential-services
|
| 143 |
|
| 144 | boot-parameters
|
| 145 | boot-parameters?
|
| 146 | boot-parameters-label
|
| 147 | boot-parameters-root-device
|
| 148 | boot-parameters-bootloader-name
|
| 149 | boot-parameters-bootloader-menu-entries
|
| 150 | boot-parameters-store-device
|
| 151 | boot-parameters-store-directory-prefix
|
| 152 | boot-parameters-store-mount-point
|
| 153 | boot-parameters-locale
|
| 154 | boot-parameters-kernel
|
| 155 | boot-parameters-kernel-arguments
|
| 156 | boot-parameters-initrd
|
| 157 | boot-parameters-multiboot-modules
|
| 158 | read-boot-parameters
|
| 159 | read-boot-parameters-file
|
| 160 | boot-parameters->menu-entry
|
| 161 |
|
| 162 | local-host-aliases
|
| 163 | %root-account
|
| 164 | %setuid-programs
|
| 165 | %sudoers-specification
|
| 166 | %base-packages
|
| 167 | %base-packages-interactive
|
| 168 | %base-packages-linux
|
| 169 | %base-packages-networking
|
| 170 | %base-packages-disk-utilities
|
| 171 | %base-packages-utils
|
| 172 | %base-firmware
|
| 173 | %default-kernel-arguments))
|
| 174 |
|
| 175 | |
| 176 | |
| 177 | |
| 178 | |
| 179 | |
| 180 |
|
| 181 | (define (bootable-kernel-arguments system root-device)
|
| 182 | "Return a list of kernel arguments (gexps) to boot SYSTEM from ROOT-DEVICE."
|
| 183 | (list (string-append "--root="
|
| 184 | |
| 185 | |
| 186 | |
| 187 | (file-system-device->string root-device
|
| 188 | #:uuid-type 'dce))
|
| 189 | #~(string-append "--system=" #$system)
|
| 190 | #~(string-append "--load=" #$system "/boot")))
|
| 191 |
|
| 192 | |
| 193 | |
| 194 | (define-record-type* <operating-system> operating-system
|
| 195 | make-operating-system
|
| 196 | operating-system?
|
| 197 | this-operating-system
|
| 198 |
|
| 199 | (kernel operating-system-kernel |
| 200 | (default linux-libre))
|
| 201 | (kernel-loadable-modules operating-system-kernel-loadable-modules
|
| 202 | (default '())) |
| 203 | (kernel-arguments operating-system-user-kernel-arguments
|
| 204 | (default %default-kernel-arguments)) |
| 205 | (hurd operating-system-hurd
|
| 206 | (default #f)) |
| 207 | (bootloader operating-system-bootloader) |
| 208 | (label operating-system-label |
| 209 | (thunked)
|
| 210 | (default (operating-system-default-label this-operating-system)))
|
| 211 |
|
| 212 | (keyboard-layout operating-system-keyboard-layout |
| 213 | (default #f))
|
| 214 | (initrd operating-system-initrd |
| 215 | (default base-initrd))
|
| 216 | (initrd-modules operating-system-initrd-modules |
| 217 | (thunked) |
| 218 | (default %base-initrd-modules))
|
| 219 |
|
| 220 | (firmware operating-system-firmware |
| 221 | (default %base-firmware))
|
| 222 |
|
| 223 | (host-name operating-system-host-name) |
| 224 | (hosts-file operating-system-hosts-file |
| 225 | (default #f))
|
| 226 |
|
| 227 | (mapped-devices operating-system-mapped-devices |
| 228 | (default '()))
|
| 229 | (file-systems operating-system-file-systems) |
| 230 | (swap-devices operating-system-swap-devices |
| 231 | (default '()))
|
| 232 |
|
| 233 | (users operating-system-users |
| 234 | (default %base-user-accounts))
|
| 235 | (groups operating-system-groups |
| 236 | (default %base-groups))
|
| 237 |
|
| 238 | (skeletons operating-system-skeletons |
| 239 | (default (default-skeletons)))
|
| 240 | (issue operating-system-issue |
| 241 | (default %default-issue))
|
| 242 |
|
| 243 | (packages operating-system-packages |
| 244 | (default %base-packages)) |
| 245 |
|
| 246 | (timezone operating-system-timezone) |
| 247 | (locale operating-system-locale |
| 248 | (default "en_US.utf8"))
|
| 249 | (locale-definitions operating-system-locale-definitions |
| 250 | (default %default-locale-definitions))
|
| 251 | (locale-libcs operating-system-locale-libcs |
| 252 | (default %default-locale-libcs))
|
| 253 | (name-service-switch operating-system-name-service-switch |
| 254 | (default %default-nss))
|
| 255 |
|
| 256 | (essential-services operating-system-essential-services |
| 257 | (thunked)
|
| 258 | (default (operating-system-default-essential-services
|
| 259 | this-operating-system)))
|
| 260 | (services operating-system-user-services |
| 261 | (default %base-services))
|
| 262 |
|
| 263 | (pam-services operating-system-pam-services |
| 264 | (default (base-pam-services)))
|
| 265 | (setuid-programs operating-system-setuid-programs
|
| 266 | (default %setuid-programs)) |
| 267 |
|
| 268 | (sudoers-file operating-system-sudoers-file |
| 269 | (default %sudoers-specification))
|
| 270 |
|
| 271 | (location operating-system-location |
| 272 | (default (and=> (current-source-location)
|
| 273 | source-properties->location))
|
| 274 | (innate)))
|
| 275 |
|
| 276 | (define (operating-system-kernel-arguments os root-device)
|
| 277 | "Return all the kernel arguments, including the ones not specified
|
| 278 | directly by the user."
|
| 279 | (append (bootable-kernel-arguments os root-device)
|
| 280 | (operating-system-user-kernel-arguments os)))
|
| 281 |
|
| 282 |
|
| 283 | |
| 284 | |
| 285 | |
| 286 |
|
| 287 | (define-record-type* <boot-parameters>
|
| 288 | boot-parameters make-boot-parameters boot-parameters?
|
| 289 | (label boot-parameters-label)
|
| 290 | |
| 291 | |
| 292 | |
| 293 | |
| 294 | |
| 295 | |
| 296 | |
| 297 | |
| 298 | |
| 299 | |
| 300 | |
| 301 | (root-device boot-parameters-root-device)
|
| 302 | (bootloader-name boot-parameters-bootloader-name)
|
| 303 | (bootloader-menu-entries |
| 304 | boot-parameters-bootloader-menu-entries)
|
| 305 | (store-device boot-parameters-store-device)
|
| 306 | (store-mount-point boot-parameters-store-mount-point)
|
| 307 | (store-directory-prefix boot-parameters-store-directory-prefix)
|
| 308 | (locale boot-parameters-locale)
|
| 309 | (kernel boot-parameters-kernel)
|
| 310 | (kernel-arguments boot-parameters-kernel-arguments)
|
| 311 | (initrd boot-parameters-initrd)
|
| 312 | (multiboot-modules boot-parameters-multiboot-modules))
|
| 313 |
|
| 314 | (define (ensure-not-/dev device)
|
| 315 | "If DEVICE starts with a slash, return #f. This is meant to filter out
|
| 316 | Linux device names such as /dev/sda, and to preserve GRUB device names and
|
| 317 | file system labels."
|
| 318 | (if (and (string? device) (string-prefix? "/" device))
|
| 319 | #f
|
| 320 | device))
|
| 321 |
|
| 322 | (define (read-boot-parameters port)
|
| 323 | "Read boot parameters from PORT and return the corresponding
|
| 324 | <boot-parameters> object or #f if the format is unrecognized."
|
| 325 | (define device-sexp->device
|
| 326 | (match-lambda
|
| 327 | (('uuid (? symbol? type) (? bytevector? bv))
|
| 328 | (bytevector->uuid bv type))
|
| 329 | (('file-system-label (? string? label))
|
| 330 | (file-system-label label))
|
| 331 | ((? bytevector? bv) |
| 332 | (bytevector->uuid bv 'dce))
|
| 333 | ((? string? device)
|
| 334 | (if (string-contains device ":/")
|
| 335 | device |
| 336 | |
| 337 | |
| 338 | (if (string-prefix? "/" device)
|
| 339 | device
|
| 340 | (file-system-label device))))))
|
| 341 |
|
| 342 | (match (read port)
|
| 343 | (('boot-parameters ('version 0)
|
| 344 | ('label label) ('root-device root)
|
| 345 | ('kernel kernel)
|
| 346 | rest ...)
|
| 347 | (boot-parameters
|
| 348 | (label label)
|
| 349 | (root-device (device-sexp->device root))
|
| 350 |
|
| 351 | (bootloader-name
|
| 352 | (match (assq 'bootloader-name rest)
|
| 353 | ((_ args) args)
|
| 354 | (#f 'grub))) |
| 355 |
|
| 356 | (bootloader-menu-entries
|
| 357 | (match (assq 'bootloader-menu-entries rest)
|
| 358 | ((_ entries) (map sexp->menu-entry entries))
|
| 359 | (#f '())))
|
| 360 |
|
| 361 | |
| 362 | |
| 363 | (kernel (if (string=? kernel (direct-store-path kernel))
|
| 364 | (string-append kernel "/"
|
| 365 | (system-linux-image-file-name))
|
| 366 | kernel))
|
| 367 |
|
| 368 | (kernel-arguments
|
| 369 | (match (assq 'kernel-arguments rest)
|
| 370 | ((_ args) args)
|
| 371 | (#f '()))) |
| 372 |
|
| 373 | (initrd
|
| 374 | (match (assq 'initrd rest)
|
| 375 | (('initrd ('string-append directory file)) |
| 376 | (string-append directory file))
|
| 377 | (('initrd (? string? file))
|
| 378 | file)
|
| 379 | (#f #f)))
|
| 380 |
|
| 381 | (multiboot-modules
|
| 382 | (match (assq 'multiboot-modules rest)
|
| 383 | ((_ args) args)
|
| 384 | (#f '())))
|
| 385 |
|
| 386 | (locale
|
| 387 | (match (assq 'locale rest)
|
| 388 | ((_ locale) locale)
|
| 389 | (#f #f)))
|
| 390 |
|
| 391 | (store-device
|
| 392 | |
| 393 | |
| 394 | (ensure-not-/dev
|
| 395 | (match (assq 'store rest)
|
| 396 | (('store ('device #f) _ ...)
|
| 397 | root-device)
|
| 398 | (('store ('device device) _ ...)
|
| 399 | (device-sexp->device device))
|
| 400 | (_ |
| 401 | root-device))))
|
| 402 |
|
| 403 | (store-directory-prefix
|
| 404 | (match (assq 'store rest)
|
| 405 | (('store . store-data)
|
| 406 | (match (assq 'directory-prefix store-data)
|
| 407 | (('directory-prefix prefix) prefix)
|
| 408 | |
| 409 | (_ #f)))
|
| 410 | (_
|
| 411 | |
| 412 | #f)))
|
| 413 |
|
| 414 | (store-mount-point
|
| 415 | (match (assq 'store rest)
|
| 416 | (('store ('device _) ('mount-point mount-point) _ ...)
|
| 417 | mount-point)
|
| 418 | (_ |
| 419 | "/")))))
|
| 420 | (x |
| 421 | (warning (G_ "unrecognized boot parameters at '~a'~%")
|
| 422 | (port-filename port))
|
| 423 | #f)))
|
| 424 |
|
| 425 | (define (read-boot-parameters-file system)
|
| 426 | "Read boot parameters from SYSTEM's (system or generation) \"parameters\"
|
| 427 | file and returns the corresponding <boot-parameters> object or #f if the
|
| 428 | format is unrecognized.
|
| 429 | The object has its kernel-arguments extended in order to make it bootable."
|
| 430 | (let* ((file (string-append system "/parameters"))
|
| 431 | (params (call-with-input-file file read-boot-parameters))
|
| 432 | (root (boot-parameters-root-device params)))
|
| 433 | (boot-parameters
|
| 434 | (inherit params)
|
| 435 | (kernel-arguments (append (bootable-kernel-arguments system root)
|
| 436 | (boot-parameters-kernel-arguments params))))))
|
| 437 |
|
| 438 | (define (boot-parameters->menu-entry conf)
|
| 439 | (let* ((kernel (boot-parameters-kernel conf))
|
| 440 | (multiboot-modules (boot-parameters-multiboot-modules conf))
|
| 441 | (multiboot? (pair? multiboot-modules)))
|
| 442 | (menu-entry
|
| 443 | (label (boot-parameters-label conf))
|
| 444 | (device (boot-parameters-store-device conf))
|
| 445 | (device-mount-point (boot-parameters-store-mount-point conf))
|
| 446 | (linux (and (not multiboot?) kernel))
|
| 447 | (linux-arguments (if (not multiboot?)
|
| 448 | (boot-parameters-kernel-arguments conf)
|
| 449 | '()))
|
| 450 | (initrd (boot-parameters-initrd conf))
|
| 451 | (multiboot-kernel (and multiboot? kernel))
|
| 452 | (multiboot-arguments (if multiboot?
|
| 453 | (boot-parameters-kernel-arguments conf)
|
| 454 | '()))
|
| 455 | (multiboot-modules (if multiboot?
|
| 456 | (boot-parameters-multiboot-modules conf)
|
| 457 | '())))))
|
| 458 |
|
| 459 |
|
| 460 | |
| 461 | |
| 462 | |
| 463 |
|
| 464 | (define (non-boot-file-system-service os)
|
| 465 | "Return the file system service for the file systems of OS that are not
|
| 466 | marked as 'needed-for-boot'."
|
| 467 | (define file-systems
|
| 468 | (remove file-system-needed-for-boot?
|
| 469 | (operating-system-file-systems os)))
|
| 470 |
|
| 471 | (define mapped-devices-for-boot
|
| 472 | (operating-system-boot-mapped-devices os))
|
| 473 |
|
| 474 | (define (device-mappings fs)
|
| 475 | (let ((device (file-system-device fs)))
|
| 476 | (if (string? device) |
| 477 | (filter (lambda (md)
|
| 478 | (string=? (string-append "/dev/mapper/"
|
| 479 | (mapped-device-target md))
|
| 480 | device))
|
| 481 | (operating-system-mapped-devices os))
|
| 482 | '())))
|
| 483 |
|
| 484 | (define (add-dependencies fs)
|
| 485 | |
| 486 | (file-system
|
| 487 | (inherit fs)
|
| 488 | (dependencies
|
| 489 | (delete-duplicates
|
| 490 | (remove (cut member <> mapped-devices-for-boot)
|
| 491 | (append (device-mappings fs)
|
| 492 | (file-system-dependencies fs)))
|
| 493 | eq?))))
|
| 494 |
|
| 495 | (service file-system-service-type
|
| 496 | (map add-dependencies file-systems)))
|
| 497 |
|
| 498 | (define (mapped-device-users device file-systems)
|
| 499 | "Return the subset of FILE-SYSTEMS that use DEVICE."
|
| 500 | (let ((target (string-append "/dev/mapper/" (mapped-device-target device))))
|
| 501 | (filter (lambda (fs)
|
| 502 | (or (member device (file-system-dependencies fs))
|
| 503 | (and (string? (file-system-device fs))
|
| 504 | (string=? (file-system-device fs) target))))
|
| 505 | file-systems)))
|
| 506 |
|
| 507 | (define (operating-system-user-mapped-devices os)
|
| 508 | "Return the subset of mapped devices that can be installed in
|
| 509 | user-land--i.e., those not needed during boot."
|
| 510 | (let ((devices (operating-system-mapped-devices os))
|
| 511 | (file-systems (operating-system-file-systems os)))
|
| 512 | (filter (lambda (md)
|
| 513 | (let ((users (mapped-device-users md file-systems)))
|
| 514 | (not (any file-system-needed-for-boot? users))))
|
| 515 | devices)))
|
| 516 |
|
| 517 | (define (operating-system-boot-mapped-devices os)
|
| 518 | "Return the subset of mapped devices that must be installed during boot,
|
| 519 | from the initrd."
|
| 520 | (let ((devices (operating-system-mapped-devices os))
|
| 521 | (file-systems (operating-system-file-systems os)))
|
| 522 | (filter (lambda (md)
|
| 523 | (let ((users (mapped-device-users md file-systems)))
|
| 524 | (any file-system-needed-for-boot? users)))
|
| 525 | devices)))
|
| 526 |
|
| 527 | (define (device-mapping-services os)
|
| 528 | "Return the list of device-mapping services for OS as a list."
|
| 529 | (map device-mapping-service
|
| 530 | (operating-system-user-mapped-devices os)))
|
| 531 |
|
| 532 | (define (swap-services os)
|
| 533 | "Return the list of swap services for OS."
|
| 534 | (map swap-service (operating-system-swap-devices os)))
|
| 535 |
|
| 536 | (define* (system-linux-image-file-name #:optional
|
| 537 | (target (or (%current-target-system)
|
| 538 | (%current-system))))
|
| 539 | "Return the basename of the kernel image file for TARGET."
|
| 540 | (cond
|
| 541 | ((string-prefix? "arm" target) "zImage")
|
| 542 | ((string-prefix? "mips" target) "vmlinuz")
|
| 543 | ((string-prefix? "aarch64" target) "Image")
|
| 544 | (else "bzImage")))
|
| 545 |
|
| 546 | (define (operating-system-kernel-file os)
|
| 547 | "Return an object representing the absolute file name of the kernel image of
|
| 548 | OS."
|
| 549 | (if (operating-system-hurd os)
|
| 550 | (file-append (operating-system-kernel os) "/boot/gnumach")
|
| 551 | (file-append (operating-system-kernel os)
|
| 552 | "/" (system-linux-image-file-name))))
|
| 553 |
|
| 554 | (define (package-for-kernel target-kernel module-package)
|
| 555 | "Return a package like MODULE-PACKAGE, adapted for TARGET-KERNEL, if
|
| 556 | possible (that is if there's a LINUX keyword argument in the build system)."
|
| 557 | (package
|
| 558 | (inherit module-package)
|
| 559 | (arguments
|
| 560 | (substitute-keyword-arguments (package-arguments module-package)
|
| 561 | ((#:linux kernel #f)
|
| 562 | target-kernel)))))
|
| 563 |
|
| 564 | (define %default-modprobe-blacklist
|
| 565 | |
| 566 | '("usbmouse" |
| 567 | "usbkbd")) |
| 568 |
|
| 569 | (define %default-kernel-arguments
|
| 570 | |
| 571 | (list (string-append "modprobe.blacklist="
|
| 572 | (string-join %default-modprobe-blacklist ","))
|
| 573 | "quiet"))
|
| 574 |
|
| 575 | (define* (operating-system-directory-base-entries os)
|
| 576 | "Return the basic entries of the 'system' directory of OS for use as the
|
| 577 | value of the SYSTEM-SERVICE-TYPE service."
|
| 578 | (let* ((locale (operating-system-locale-directory os))
|
| 579 | (kernel (operating-system-kernel os))
|
| 580 | (hurd (operating-system-hurd os))
|
| 581 | (modules (operating-system-kernel-loadable-modules os))
|
| 582 | (kernel (if hurd
|
| 583 | kernel
|
| 584 | (profile
|
| 585 | (content (packages->manifest
|
| 586 | (cons kernel
|
| 587 | (map (lambda (module)
|
| 588 | (if (package? module)
|
| 589 | (package-for-kernel kernel
|
| 590 | module)
|
| 591 | module))
|
| 592 | modules))))
|
| 593 | (hooks (list linux-module-database)))))
|
| 594 | (initrd (and (not hurd) (operating-system-initrd-file os)))
|
| 595 | (params (operating-system-boot-parameters-file os)))
|
| 596 | `(("kernel" ,kernel)
|
| 597 | ,@(if hurd `(("hurd" ,hurd)) '())
|
| 598 | ("parameters" ,params)
|
| 599 | ,@(if initrd `(("initrd" ,initrd)) '())
|
| 600 | ("locale" ,locale)))) |
| 601 |
|
| 602 | (define (operating-system-default-essential-services os)
|
| 603 | "Return the list of essential services for OS. These are special services
|
| 604 | that implement part of what's declared in OS are responsible for low-level
|
| 605 | bookkeeping."
|
| 606 | (define known-fs
|
| 607 | (map file-system-mount-point (operating-system-file-systems os)))
|
| 608 |
|
| 609 | (let* ((mappings (device-mapping-services os))
|
| 610 | (root-fs (root-file-system-service))
|
| 611 | (other-fs (non-boot-file-system-service os))
|
| 612 | (swaps (swap-services os))
|
| 613 | (procs (service user-processes-service-type))
|
| 614 | (host-name (host-name-service (operating-system-host-name os)))
|
| 615 | (entries (operating-system-directory-base-entries os)))
|
| 616 | (cons* (service system-service-type entries)
|
| 617 | %boot-service
|
| 618 |
|
| 619 | |
| 620 | |
| 621 | |
| 622 | |
| 623 | (service cleanup-service-type #f)
|
| 624 | %activation-service
|
| 625 | %shepherd-root-service
|
| 626 |
|
| 627 | (pam-root-service (operating-system-pam-services os))
|
| 628 | (account-service (append (operating-system-accounts os)
|
| 629 | (operating-system-groups os))
|
| 630 | (operating-system-skeletons os))
|
| 631 | (operating-system-etc-service os)
|
| 632 | (service fstab-service-type
|
| 633 | (filter file-system-needed-for-boot?
|
| 634 | (operating-system-file-systems os)))
|
| 635 | (session-environment-service
|
| 636 | (operating-system-environment-variables os))
|
| 637 | host-name procs root-fs
|
| 638 | (service setuid-program-service-type
|
| 639 | (operating-system-setuid-programs os))
|
| 640 | (service profile-service-type
|
| 641 | (operating-system-packages os))
|
| 642 | other-fs
|
| 643 | (append mappings swaps
|
| 644 |
|
| 645 | |
| 646 | (list %linux-bare-metal-service
|
| 647 | (service firmware-service-type
|
| 648 | (operating-system-firmware os)))))))
|
| 649 |
|
| 650 | (define (hurd-default-essential-services os)
|
| 651 | (let ((entries (operating-system-directory-base-entries os)))
|
| 652 | (list (service system-service-type entries)
|
| 653 | %boot-service
|
| 654 | %hurd-startup-service
|
| 655 | %activation-service
|
| 656 | %shepherd-root-service
|
| 657 | (service user-processes-service-type)
|
| 658 | (account-service (append (operating-system-accounts os)
|
| 659 | (operating-system-groups os))
|
| 660 | (operating-system-skeletons os))
|
| 661 | (root-file-system-service)
|
| 662 | (service file-system-service-type '())
|
| 663 | (service fstab-service-type
|
| 664 | (filter file-system-needed-for-boot?
|
| 665 | (operating-system-file-systems os)))
|
| 666 | (pam-root-service (operating-system-pam-services os))
|
| 667 | (operating-system-etc-service os)
|
| 668 | (service setuid-program-service-type
|
| 669 | (operating-system-setuid-programs os))
|
| 670 | (service profile-service-type (operating-system-packages os)))))
|
| 671 |
|
| 672 | (define* (operating-system-services os)
|
| 673 | "Return all the services of OS, including \"essential\" services."
|
| 674 | (instantiate-missing-services
|
| 675 | (append (operating-system-user-services os)
|
| 676 | (operating-system-essential-services os))))
|
| 677 |
|
| 678 | (define (operating-system-with-gc-roots os roots)
|
| 679 | "Return a variant of OS where ROOTS are registered as GC roots."
|
| 680 | (operating-system
|
| 681 | (inherit os)
|
| 682 |
|
| 683 | |
| 684 | |
| 685 | (services (cons (simple-service 'extra-root
|
| 686 | gc-root-service-type roots)
|
| 687 | (operating-system-user-services os)))))
|
| 688 |
|
| 689 | (define (operating-system-configuration-file os)
|
| 690 | "Return the configuration file of OS, based on its 'location' field, or #f
|
| 691 | if it could not be determined."
|
| 692 | (let ((file (and=> (operating-system-location os)
|
| 693 | location-file)))
|
| 694 | (and file
|
| 695 | (or (and (string-prefix? "/" file) file)
|
| 696 | (search-path %load-path file)))))
|
| 697 |
|
| 698 | (define* (operating-system-with-provenance os
|
| 699 | #:optional
|
| 700 | (config-file
|
| 701 | (operating-system-configuration-file
|
| 702 | os)))
|
| 703 | "Return a variant of OS that stores its own provenance information,
|
| 704 | including CONFIG-FILE, if available. This is achieved by adding an instance
|
| 705 | of PROVENANCE-SERVICE-TYPE to its services."
|
| 706 | (operating-system
|
| 707 | (inherit os)
|
| 708 | (services (cons (service provenance-service-type config-file)
|
| 709 | (operating-system-user-services os)))))
|
| 710 |
|
| 711 |
|
| 712 | |
| 713 | |
| 714 | |
| 715 |
|
| 716 | (define %base-firmware
|
| 717 | |
| 718 | (list ath9k-htc-firmware
|
| 719 | openfwwf-firmware))
|
| 720 |
|
| 721 | (define %base-packages-utils
|
| 722 | |
| 723 | (cons* procps psmisc which
|
| 724 | (@ (gnu packages admin) shadow) |
| 725 |
|
| 726 | guile-3.0-latest
|
| 727 |
|
| 728 | |
| 729 | |
| 730 | (list bash coreutils findutils grep sed
|
| 731 | diffutils patch gawk tar gzip bzip2 xz lzip)))
|
| 732 |
|
| 733 | (define %base-packages-linux
|
| 734 | |
| 735 | (list pciutils usbutils
|
| 736 | util-linux+udev
|
| 737 | |
| 738 | |
| 739 | kmod eudev))
|
| 740 |
|
| 741 | (define %base-packages-interactive
|
| 742 | |
| 743 | (list less zile nano
|
| 744 | nvi
|
| 745 | man-db
|
| 746 | info-reader |
| 747 | bash-completion
|
| 748 | kbd
|
| 749 | |
| 750 | |
| 751 | |
| 752 | sudo
|
| 753 | guile-readline guile-colorized))
|
| 754 |
|
| 755 | (define %base-packages-networking
|
| 756 | |
| 757 | (list inetutils isc-dhcp
|
| 758 | iproute
|
| 759 | |
| 760 | |
| 761 | iw wireless-tools))
|
| 762 |
|
| 763 | (define %base-packages-disk-utilities
|
| 764 | |
| 765 | |
| 766 | (list parted gptfdisk ddrescue
|
| 767 | |
| 768 | |
| 769 | |
| 770 | cryptsetup mdadm
|
| 771 | dosfstools
|
| 772 | btrfs-progs
|
| 773 | f2fs-tools
|
| 774 | jfsutils))
|
| 775 |
|
| 776 | (define %base-packages
|
| 777 | |
| 778 | |
| 779 | (append (list e2fsprogs)
|
| 780 | %base-packages-interactive
|
| 781 | %base-packages-linux
|
| 782 | %base-packages-networking
|
| 783 | %base-packages-utils))
|
| 784 |
|
| 785 | (define %default-issue
|
| 786 | |
| 787 | "
|
| 788 | This is the GNU system. Welcome.\n")
|
| 789 |
|
| 790 | (define (local-host-aliases host-name)
|
| 791 | "Return aliases for HOST-NAME, to be used in /etc/hosts."
|
| 792 | (string-append "127.0.0.1 localhost " host-name "\n"
|
| 793 | "::1 localhost " host-name "\n"))
|
| 794 |
|
| 795 | (define (default-/etc/hosts host-name)
|
| 796 | "Return the default /etc/hosts file."
|
| 797 | (plain-file "hosts" (local-host-aliases host-name)))
|
| 798 |
|
| 799 | (define (validated-sudoers-file file)
|
| 800 | "Return a copy of FILE, a sudoers file, after checking that it is
|
| 801 | syntactically correct."
|
| 802 | (computed-file "sudoers"
|
| 803 | (with-imported-modules '((guix build utils))
|
| 804 | #~(begin
|
| 805 | (use-modules (guix build utils))
|
| 806 |
|
| 807 | (invoke #+(file-append sudo "/sbin/visudo")
|
| 808 | "--check" "--file" #$file)
|
| 809 | (copy-file #$file #$output)))))
|
| 810 |
|
| 811 | (define* (operating-system-etc-service os)
|
| 812 | "Return a <service> that builds containing the static part of the /etc
|
| 813 | directory."
|
| 814 | (let* ((login.defs
|
| 815 | (plain-file "login.defs"
|
| 816 | (string-append
|
| 817 | "# Default paths for non-login shells started by su(1).\n"
|
| 818 | "ENV_PATH /run/setuid-programs:"
|
| 819 | "/run/current-system/profile/bin:"
|
| 820 | "/run/current-system/profile/sbin\n"
|
| 821 | "ENV_SUPATH /run/setuid-programs:"
|
| 822 | "/run/current-system/profile/bin:"
|
| 823 | "/run/current-system/profile/sbin\n")))
|
| 824 |
|
| 825 | (hurd (operating-system-hurd os))
|
| 826 | (issue (plain-file "issue" (operating-system-issue os)))
|
| 827 | (nsswitch (operating-system-name-service-switch os))
|
| 828 | (nsswitch (and nsswitch
|
| 829 | (plain-file "nsswitch.conf"
|
| 830 | (name-service-switch->string nsswitch))))
|
| 831 | (sudoers (operating-system-sudoers-file os))
|
| 832 |
|
| 833 | |
| 834 | |
| 835 | (profile (mixed-text-file "profile" "\
|
| 836 | # Crucial variables that could be missing in the profiles' 'etc/profile'
|
| 837 | # because they would require combining both profiles.
|
| 838 | # FIXME: See <http://bugs.gnu.org/20255>.
|
| 839 | export MANPATH=$HOME/.guix-profile/share/man:/run/current-system/profile/share/man
|
| 840 | export INFOPATH=$HOME/.guix-profile/share/info:/run/current-system/profile/share/info
|
| 841 | export XDG_DATA_DIRS=$HOME/.guix-profile/share:/run/current-system/profile/share
|
| 842 | export XDG_CONFIG_DIRS=$HOME/.guix-profile/etc/xdg:/run/current-system/profile/etc/xdg
|
| 843 |
|
| 844 | # Make sure libXcursor finds cursors installed into user or system profiles. See <http://bugs.gnu.org/24445>
|
| 845 | export XCURSOR_PATH=$HOME/.icons:$HOME/.guix-profile/share/icons:/run/current-system/profile/share/icons
|
| 846 |
|
| 847 | # Ignore the default value of 'PATH'.
|
| 848 | unset PATH
|
| 849 |
|
| 850 | # Load the system profile's settings.
|
| 851 | GUIX_PROFILE=/run/current-system/profile ; \\
|
| 852 | . /run/current-system/profile/etc/profile
|
| 853 |
|
| 854 | # Since 'lshd' does not use pam_env, /etc/environment must be explicitly
|
| 855 | # loaded when someone logs in via SSH. See <http://bugs.gnu.org/22175>.
|
| 856 | # We need 'PATH' to be defined here, for 'cat' and 'cut'. Do this before
|
| 857 | # reading the user's 'etc/profile' to allow variables to be overridden.
|
| 858 | if [ -f /etc/environment -a -n \"$SSH_CLIENT\" \\
|
| 859 | -a -z \"$LINUX_MODULE_DIRECTORY\" ]
|
| 860 | then
|
| 861 | . /etc/environment
|
| 862 | export `cat /etc/environment | cut -d= -f1`
|
| 863 | fi
|
| 864 |
|
| 865 | # Arrange so that ~/.config/guix/current comes first.
|
| 866 | for profile in \"$HOME/.guix-profile\" \"$HOME/.config/guix/current\"
|
| 867 | do
|
| 868 | if [ -f \"$profile/etc/profile\" ]
|
| 869 | then
|
| 870 | # Load the user profile's settings.
|
| 871 | GUIX_PROFILE=\"$profile\" ; \\
|
| 872 | . \"$profile/etc/profile\"
|
| 873 | else
|
| 874 | # At least define this one so that basic things just work
|
| 875 | # when the user installs their first package.
|
| 876 | export PATH=\"$profile/bin:$PATH\"
|
| 877 | fi
|
| 878 | done
|
| 879 |
|
| 880 | # Prepend setuid programs.
|
| 881 | export PATH=/run/setuid-programs:$PATH
|
| 882 |
|
| 883 | # Arrange so that ~/.config/guix/current/share/info comes first.
|
| 884 | export INFOPATH=\"$HOME/.config/guix/current/share/info:$INFOPATH\"
|
| 885 |
|
| 886 | # Set the umask, notably for users logging in via 'lsh'.
|
| 887 | # See <http://bugs.gnu.org/22650>.
|
| 888 | umask 022
|
| 889 |
|
| 890 | # Allow Hunspell-based applications (IceCat, LibreOffice, etc.) to
|
| 891 | # find dictionaries.
|
| 892 | export DICPATH=\"$HOME/.guix-profile/share/hunspell:/run/current-system/profile/share/hunspell\"
|
| 893 |
|
| 894 | # Allow GStreamer-based applications to find plugins.
|
| 895 | export GST_PLUGIN_PATH=\"$HOME/.guix-profile/lib/gstreamer-1.0\"
|
| 896 |
|
| 897 | if [ -n \"$BASH_VERSION\" -a -f /etc/bashrc ]
|
| 898 | then
|
| 899 | # Load Bash-specific initialization code.
|
| 900 | . /etc/bashrc
|
| 901 | fi
|
| 902 | "))
|
| 903 |
|
| 904 | (bashrc (plain-file "bashrc" "\
|
| 905 | # Bash-specific initialization.
|
| 906 |
|
| 907 | # The 'bash-completion' package.
|
| 908 | if [ -f /run/current-system/profile/etc/profile.d/bash_completion.sh ]
|
| 909 | then
|
| 910 | # Bash-completion sources ~/.bash_completion. It installs a dynamic
|
| 911 | # completion loader that searches its own completion files as well
|
| 912 | # as those in ~/.guix-profile and /run/current-system/profile.
|
| 913 | source /run/current-system/profile/etc/profile.d/bash_completion.sh
|
| 914 | fi\n")))
|
| 915 | (etc-service
|
| 916 | `(("services" ,(file-append net-base "/etc/services"))
|
| 917 | ("protocols" ,(file-append net-base "/etc/protocols"))
|
| 918 | ("rpc" ,(file-append net-base "/etc/rpc"))
|
| 919 | ("login.defs" ,#~#$login.defs)
|
| 920 | ("issue" ,#~#$issue)
|
| 921 | ,@(if nsswitch `(("nsswitch.conf" ,#~#$nsswitch)) '())
|
| 922 | ("profile" ,#~#$profile)
|
| 923 | ("bashrc" ,#~#$bashrc)
|
| 924 | ("hosts" ,#~#$(or (operating-system-hosts-file os)
|
| 925 | (default-/etc/hosts (operating-system-host-name os))))
|
| 926 | |
| 927 | |
| 928 | |
| 929 | |
| 930 | ("hostname" ,(plain-file "hostname" (operating-system-host-name os)))
|
| 931 | |
| 932 | |
| 933 | |
| 934 | ("timezone" ,(plain-file "timezone" (operating-system-timezone os)))
|
| 935 | ("localtime" ,(file-append tzdata "/share/zoneinfo/"
|
| 936 | (operating-system-timezone os)))
|
| 937 | ,@(if sudoers
|
| 938 | `(("sudoers" ,(validated-sudoers-file sudoers)))
|
| 939 | '())
|
| 940 | ,@(if hurd
|
| 941 | `(("login" ,(file-append hurd "/etc/login"))
|
| 942 | ("motd" ,(file-append hurd "/etc/motd"))
|
| 943 | ("ttys" ,(file-append hurd "/etc/ttys")))
|
| 944 | '())))))
|
| 945 |
|
| 946 | (define %root-account
|
| 947 | |
| 948 | (user-account
|
| 949 | (name "root")
|
| 950 | (password "")
|
| 951 | (uid 0) (group "root")
|
| 952 | (comment "System administrator")
|
| 953 | (home-directory "/root")))
|
| 954 |
|
| 955 | (define (operating-system-accounts os)
|
| 956 | "Return the user accounts for OS, including an obligatory 'root' account,
|
| 957 | and excluding accounts requested by services."
|
| 958 | |
| 959 | (if (find (lambda (user)
|
| 960 | (and=> (user-account-uid user) zero?))
|
| 961 | (operating-system-users os))
|
| 962 | (operating-system-users os)
|
| 963 | (cons %root-account (operating-system-users os))))
|
| 964 |
|
| 965 | (define (maybe-string->file file-name thing)
|
| 966 | "If THING is a string, return a <plain-file> with THING as its content.
|
| 967 | Otherwise just return THING.
|
| 968 |
|
| 969 | This is for backward-compatibility of fields that used to be strings and are
|
| 970 | now file-like objects.."
|
| 971 | (match thing
|
| 972 | ((? string?)
|
| 973 | (warning (G_ "using a string for file '~a' is deprecated; \
|
| 974 | use 'plain-file' instead~%")
|
| 975 | file-name)
|
| 976 | (plain-file file-name thing))
|
| 977 | (x
|
| 978 | x)))
|
| 979 |
|
| 980 | (define (maybe-file->monadic file-name thing)
|
| 981 | "If THING is a value in %STORE-MONAD, return it as is; otherwise return
|
| 982 | THING in the %STORE-MONAD.
|
| 983 |
|
| 984 | This is for backward-compatibility of fields that used to be monadic values
|
| 985 | and are now file-like objects."
|
| 986 | (with-monad %store-monad
|
| 987 | (match thing
|
| 988 | ((? procedure?)
|
| 989 | (warning (G_ "using a monadic value for '~a' is deprecated; \
|
| 990 | use 'plain-file' instead~%")
|
| 991 | file-name)
|
| 992 | thing)
|
| 993 | (x
|
| 994 | (return x)))))
|
| 995 |
|
| 996 | (define (operating-system-etc-directory os)
|
| 997 | "Return that static part of the /etc directory of OS."
|
| 998 | (etc-directory
|
| 999 | (fold-services (operating-system-services os)
|
| 1000 | #:target-type etc-service-type)))
|
| 1001 |
|
| 1002 | (define (operating-system-environment-variables os)
|
| 1003 | "Return the environment variables of OS for
|
| 1004 | @var{session-environment-service-type}, to be used in @file{/etc/environment}."
|
| 1005 | `(("LANG" . ,(operating-system-locale os))
|
| 1006 | |
| 1007 | |
| 1008 | ("TZDIR" . ,(file-append tzdata "/share/zoneinfo"))
|
| 1009 | |
| 1010 | ("LINUX_MODULE_DIRECTORY" . "/run/booted-system/kernel/lib/modules")
|
| 1011 | |
| 1012 | ("SSL_CERT_DIR" . "/etc/ssl/certs")
|
| 1013 | ("SSL_CERT_FILE" . "/etc/ssl/certs/ca-certificates.crt")
|
| 1014 | ("GIT_SSL_CAINFO" . "/etc/ssl/certs/ca-certificates.crt")
|
| 1015 |
|
| 1016 | |
| 1017 | |
| 1018 | ("GTK_DATA_PREFIX" . "/run/current-system/profile")
|
| 1019 |
|
| 1020 | |
| 1021 | |
| 1022 | ("DBUS_FATAL_WARNINGS" . "0")
|
| 1023 |
|
| 1024 | |
| 1025 | |
| 1026 | |
| 1027 | |
| 1028 | |
| 1029 | |
| 1030 | ("GUIX_LOCPATH" . "/run/current-system/locale")))
|
| 1031 |
|
| 1032 | (define %setuid-programs
|
| 1033 | |
| 1034 | (let ((shadow (@ (gnu packages admin) shadow)))
|
| 1035 | (list (file-append shadow "/bin/passwd")
|
| 1036 | (file-append shadow "/bin/sg")
|
| 1037 | (file-append shadow "/bin/su")
|
| 1038 | (file-append shadow "/bin/newgrp")
|
| 1039 | (file-append shadow "/bin/newuidmap")
|
| 1040 | (file-append shadow "/bin/newgidmap")
|
| 1041 | (file-append inetutils "/bin/ping")
|
| 1042 | (file-append inetutils "/bin/ping6")
|
| 1043 | (file-append sudo "/bin/sudo")
|
| 1044 | (file-append sudo "/bin/sudoedit")
|
| 1045 | (file-append fuse "/bin/fusermount")
|
| 1046 |
|
| 1047 | |
| 1048 | |
| 1049 | (file-append util-linux "/bin/mount")
|
| 1050 | (file-append util-linux "/bin/umount"))))
|
| 1051 |
|
| 1052 | (define %sudoers-specification
|
| 1053 | |
| 1054 | |
| 1055 | |
| 1056 | |
| 1057 | (plain-file "sudoers" "\
|
| 1058 | root ALL=(ALL) ALL
|
| 1059 | %wheel ALL=(ALL) ALL\n"))
|
| 1060 |
|
| 1061 | (define* (operating-system-activation-script os)
|
| 1062 | "Return the activation script for OS---i.e., the code that \"activates\" the
|
| 1063 | stateful part of OS, including user accounts and groups, special directories,
|
| 1064 | etc."
|
| 1065 | (let* ((services (operating-system-services os))
|
| 1066 | (activation (fold-services services
|
| 1067 | #:target-type activation-service-type)))
|
| 1068 | (activation-service->script activation)))
|
| 1069 |
|
| 1070 | (define* (operating-system-boot-script os)
|
| 1071 | "Return the boot script for OS---i.e., the code started by the initrd once
|
| 1072 | we're running in the final root."
|
| 1073 | (let* ((services (operating-system-services os))
|
| 1074 | (boot (fold-services services #:target-type boot-service-type)))
|
| 1075 | (service-value boot)))
|
| 1076 |
|
| 1077 | (define (operating-system-user-accounts os)
|
| 1078 | "Return the list of user accounts of OS."
|
| 1079 | (let* ((services (operating-system-services os))
|
| 1080 | (account (fold-services services
|
| 1081 | #:target-type account-service-type)))
|
| 1082 | (filter user-account?
|
| 1083 | (service-value account))))
|
| 1084 |
|
| 1085 | (define (operating-system-shepherd-service-names os)
|
| 1086 | "Return the list of Shepherd service names for OS."
|
| 1087 | (append-map shepherd-service-provision
|
| 1088 | (service-value
|
| 1089 | (fold-services (operating-system-services os)
|
| 1090 | #:target-type
|
| 1091 | shepherd-root-service-type))))
|
| 1092 |
|
| 1093 | (define* (operating-system-derivation os)
|
| 1094 | "Return a derivation that builds OS."
|
| 1095 | (let* ((services (operating-system-services os))
|
| 1096 | (system (fold-services services)))
|
| 1097 | |
| 1098 | (service-value system)))
|
| 1099 |
|
| 1100 | (define* (operating-system-profile os)
|
| 1101 | "Return a derivation that builds the system profile of OS."
|
| 1102 | (mlet* %store-monad
|
| 1103 | ((services -> (operating-system-services os))
|
| 1104 | (profile (fold-services services
|
| 1105 | #:target-type profile-service-type)))
|
| 1106 | (match profile
|
| 1107 | (("profile" profile)
|
| 1108 | (return profile)))))
|
| 1109 |
|
| 1110 | (define (operating-system-root-file-system os)
|
| 1111 | "Return the root file system of OS."
|
| 1112 | (or (find (lambda (fs)
|
| 1113 | (string=? "/" (file-system-mount-point fs)))
|
| 1114 | (operating-system-file-systems os))
|
| 1115 | (raise (condition
|
| 1116 | (&message (message "missing root file system"))
|
| 1117 | (&error-location
|
| 1118 | (location (operating-system-location os)))))))
|
| 1119 |
|
| 1120 | (define (operating-system-initrd-file os)
|
| 1121 | "Return a gexp denoting the initrd file of OS."
|
| 1122 | (define boot-file-systems
|
| 1123 | (filter file-system-needed-for-boot?
|
| 1124 | (operating-system-file-systems os)))
|
| 1125 |
|
| 1126 | (define mapped-devices
|
| 1127 | (operating-system-boot-mapped-devices os))
|
| 1128 |
|
| 1129 | (define make-initrd
|
| 1130 | (operating-system-initrd os))
|
| 1131 |
|
| 1132 | (make-initrd boot-file-systems
|
| 1133 | #:linux (operating-system-kernel os)
|
| 1134 | #:linux-modules
|
| 1135 | (operating-system-initrd-modules os)
|
| 1136 | #:mapped-devices mapped-devices
|
| 1137 | #:keyboard-layout (operating-system-keyboard-layout os)))
|
| 1138 |
|
| 1139 | (define* (operating-system-uuid os #:optional (type 'dce))
|
| 1140 | "Compute UUID object with a deterministic \"UUID\" for OS, of the given
|
| 1141 | TYPE (one of 'iso9660 or 'dce). Return a UUID object."
|
| 1142 | |
| 1143 | |
| 1144 | |
| 1145 |
|
| 1146 | (define service-name
|
| 1147 | (compose service-type-name service-kind))
|
| 1148 |
|
| 1149 | (define (file-system-digest fs)
|
| 1150 | |
| 1151 | |
| 1152 | (let ((device (file-system-device fs)))
|
| 1153 | (list (file-system-mount-point fs)
|
| 1154 | (file-system-type fs)
|
| 1155 | (file-system-device->string device)
|
| 1156 | (file-system-options fs))))
|
| 1157 |
|
| 1158 | (if (eq? type 'iso9660)
|
| 1159 | (let ((pad (compose (cut string-pad <> 2 #\0)
|
| 1160 | number->string))
|
| 1161 | (h (hash (map service-name (operating-system-services os))
|
| 1162 | 3600)))
|
| 1163 | (bytevector->uuid
|
| 1164 | (string->iso9660-uuid
|
| 1165 | (string-append "1970-01-01-"
|
| 1166 | (pad (hash (operating-system-host-name os) 24)) "-"
|
| 1167 | (pad (quotient h 60)) "-"
|
| 1168 | (pad (modulo h 60)) "-"
|
| 1169 | (pad (hash (map file-system-digest
|
| 1170 | (operating-system-file-systems os))
|
| 1171 | 100))))
|
| 1172 | 'iso9660))
|
| 1173 | (bytevector->uuid
|
| 1174 | (uint-list->bytevector
|
| 1175 | (list (hash (map file-system-digest
|
| 1176 | (operating-system-file-systems os))
|
| 1177 | (- (expt 2 32) 1))
|
| 1178 | (hash (operating-system-host-name os)
|
| 1179 | (- (expt 2 32) 1))
|
| 1180 | (hash (map service-name (operating-system-services os))
|
| 1181 | (- (expt 2 32) 1))
|
| 1182 | (hash (map file-system-digest (operating-system-file-systems os))
|
| 1183 | (- (expt 2 32) 1)))
|
| 1184 | (endianness little)
|
| 1185 | 4)
|
| 1186 | type)))
|
| 1187 |
|
| 1188 | (define (locale-name->definition* name)
|
| 1189 | "Variant of 'locale-name->definition' that raises an error upon failure."
|
| 1190 | (match (locale-name->definition name)
|
| 1191 | (#f
|
| 1192 | (raise (formatted-message (G_ "~a: invalid locale name") name)))
|
| 1193 | (def def)))
|
| 1194 |
|
| 1195 | (define (operating-system-locale-directory os)
|
| 1196 | "Return the directory containing the locales compiled for the definitions
|
| 1197 | listed in OS. The C library expects to find it under
|
| 1198 | /run/current-system/locale."
|
| 1199 | (define name
|
| 1200 | (operating-system-locale os))
|
| 1201 |
|
| 1202 | (define definitions
|
| 1203 | |
| 1204 | (if (member name (map locale-definition-name
|
| 1205 | (operating-system-locale-definitions os)))
|
| 1206 | (operating-system-locale-definitions os)
|
| 1207 | (cons (locale-name->definition* name)
|
| 1208 | (operating-system-locale-definitions os))))
|
| 1209 |
|
| 1210 | (locale-directory definitions
|
| 1211 | #:libcs (operating-system-locale-libcs os)))
|
| 1212 |
|
| 1213 | (define* (kernel->boot-label kernel #:key hurd)
|
| 1214 | "Return a label for the bootloader menu entry that boots KERNEL."
|
| 1215 | (cond ((package? hurd)
|
| 1216 | (string-append "GNU with the "
|
| 1217 | (string-titlecase (package-name hurd)) " "
|
| 1218 | (package-version hurd)))
|
| 1219 | ((package? kernel)
|
| 1220 | (string-append "GNU with "
|
| 1221 | (string-titlecase (package-name kernel)) " "
|
| 1222 | (package-version kernel)))
|
| 1223 | ((inferior-package? kernel)
|
| 1224 | (string-append "GNU with "
|
| 1225 | (string-titlecase (inferior-package-name kernel)) " "
|
| 1226 | (inferior-package-version kernel)))
|
| 1227 | (else "GNU")))
|
| 1228 |
|
| 1229 | (define (operating-system-default-label os)
|
| 1230 | "Return the default label for OS, as it will appear in the bootloader menu
|
| 1231 | entry."
|
| 1232 | (kernel->boot-label (operating-system-kernel os)
|
| 1233 | #:hurd (operating-system-hurd os)))
|
| 1234 |
|
| 1235 | (define (store-file-system file-systems)
|
| 1236 | "Return the file system object among FILE-SYSTEMS that contains the store."
|
| 1237 | (match (filter (lambda (fs)
|
| 1238 | (and (file-system-mount? fs)
|
| 1239 | (not (memq 'bind-mount (file-system-flags fs)))
|
| 1240 | (string-prefix? (file-system-mount-point fs)
|
| 1241 | (%store-prefix))))
|
| 1242 | file-systems)
|
| 1243 | ((and candidates (head . tail))
|
| 1244 | (reduce (lambda (fs1 fs2)
|
| 1245 | (if (> (string-length (file-system-mount-point fs1))
|
| 1246 | (string-length (file-system-mount-point fs2)))
|
| 1247 | fs1
|
| 1248 | fs2))
|
| 1249 | head
|
| 1250 | candidates))))
|
| 1251 |
|
| 1252 | (define (operating-system-store-file-system os)
|
| 1253 | "Return the file system that contains the store of OS."
|
| 1254 | (store-file-system (operating-system-file-systems os)))
|
| 1255 |
|
| 1256 | (define* (operating-system-bootcfg os #:optional (old-entries '()))
|
| 1257 | "Return the bootloader configuration file for OS. Use OLD-ENTRIES,
|
| 1258 | a list of <menu-entry>, to populate the \"old entries\" menu."
|
| 1259 | (let* ((file-systems (operating-system-file-systems os))
|
| 1260 | (root-fs (operating-system-root-file-system os))
|
| 1261 | (root-device (file-system-device root-fs))
|
| 1262 | (locale (operating-system-locale os))
|
| 1263 | (params (operating-system-boot-parameters
|
| 1264 | os root-device
|
| 1265 | #:system-kernel-arguments? #t))
|
| 1266 | (entry (boot-parameters->menu-entry params))
|
| 1267 | (bootloader-conf (operating-system-bootloader os)))
|
| 1268 |
|
| 1269 | (define generate-config-file
|
| 1270 | (bootloader-configuration-file-generator
|
| 1271 | (bootloader-configuration-bootloader bootloader-conf)))
|
| 1272 |
|
| 1273 | (generate-config-file bootloader-conf (list entry)
|
| 1274 | #:old-entries old-entries
|
| 1275 | #:locale locale
|
| 1276 | #:store-directory-prefix
|
| 1277 | (btrfs-store-subvolume-file-name file-systems))))
|
| 1278 |
|
| 1279 | (define (operating-system-multiboot-modules os)
|
| 1280 | (if (operating-system-hurd os) (hurd-multiboot-modules os) '()))
|
| 1281 |
|
| 1282 | (define (hurd-multiboot-modules os)
|
| 1283 | (let* ((hurd (operating-system-hurd os))
|
| 1284 | (root-file-system-command
|
| 1285 | (list (file-append hurd "/hurd/ext2fs.static")
|
| 1286 | "ext2fs"
|
| 1287 | "--multiboot-command-line='${kernel-command-line}'"
|
| 1288 | "--host-priv-port='${host-port}'"
|
| 1289 | "--device-master-port='${device-port}'"
|
| 1290 | "--exec-server-task='${exec-task}'"
|
| 1291 | "--store-type=typed"
|
| 1292 | "--x-xattr-translator-records"
|
| 1293 | "'${root}'" "'$(task-create)'" "'$(task-resume)'"))
|
| 1294 | (target (%current-target-system))
|
| 1295 | (libc (if target
|
| 1296 | (with-parameters ((%current-target-system #f))
|
| 1297 | |
| 1298 | |
| 1299 | (cross-libc target))
|
| 1300 | glibc))
|
| 1301 | (exec-server-command
|
| 1302 | (list (file-append libc "/lib/ld.so.1") "exec"
|
| 1303 | (file-append hurd "/hurd/exec") "'$(exec-task=task-create)'")))
|
| 1304 | (list root-file-system-command exec-server-command)))
|
| 1305 |
|
| 1306 | (define* (operating-system-boot-parameters os root-device
|
| 1307 | #:key system-kernel-arguments?)
|
| 1308 | "Return a monadic <boot-parameters> record that describes the boot
|
| 1309 | parameters of OS. When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments
|
| 1310 | such as '--root' and '--load' to <boot-parameters>."
|
| 1311 | (let* ((initrd (and (not (operating-system-hurd os))
|
| 1312 | (operating-system-initrd-file os)))
|
| 1313 | (store (operating-system-store-file-system os))
|
| 1314 | (file-systems (operating-system-file-systems os))
|
| 1315 | (locale (operating-system-locale os))
|
| 1316 | (bootloader (bootloader-configuration-bootloader
|
| 1317 | (operating-system-bootloader os)))
|
| 1318 | (bootloader-name (bootloader-name bootloader))
|
| 1319 | (label (operating-system-label os))
|
| 1320 | (multiboot-modules (operating-system-multiboot-modules os)))
|
| 1321 | (boot-parameters
|
| 1322 | (label label)
|
| 1323 | (root-device root-device)
|
| 1324 | (kernel (operating-system-kernel-file os))
|
| 1325 | (kernel-arguments
|
| 1326 | (if system-kernel-arguments?
|
| 1327 | (operating-system-kernel-arguments os root-device)
|
| 1328 | (operating-system-user-kernel-arguments os)))
|
| 1329 | (initrd initrd)
|
| 1330 | (multiboot-modules multiboot-modules)
|
| 1331 | (bootloader-name bootloader-name)
|
| 1332 | (bootloader-menu-entries
|
| 1333 | (bootloader-configuration-menu-entries (operating-system-bootloader os)))
|
| 1334 | (locale locale)
|
| 1335 | (store-device (ensure-not-/dev (file-system-device store)))
|
| 1336 | (store-directory-prefix (btrfs-store-subvolume-file-name file-systems))
|
| 1337 | (store-mount-point (file-system-mount-point store)))))
|
| 1338 |
|
| 1339 | (define (device->sexp device)
|
| 1340 | "Serialize DEVICE as an sexp (really, as an object with a read syntax.)"
|
| 1341 | (match device
|
| 1342 | ((? uuid? uuid)
|
| 1343 | `(uuid ,(uuid-type uuid) ,(uuid-bytevector uuid)))
|
| 1344 | ((? file-system-label? label)
|
| 1345 | `(file-system-label ,(file-system-label->string label)))
|
| 1346 | (_
|
| 1347 | device)))
|
| 1348 |
|
| 1349 | (define* (operating-system-boot-parameters-file os
|
| 1350 | #:key system-kernel-arguments?)
|
| 1351 | "Return a file that describes the boot parameters of OS. The primary use of
|
| 1352 | this file is the reconstruction of GRUB menu entries for old configurations.
|
| 1353 |
|
| 1354 | When SYSTEM-KERNEL-ARGUMENTS? is true, add kernel arguments such as '--root'
|
| 1355 | and '--load' to the returned file (since the returned file is then usually
|
| 1356 | stored into the content-addressed \"system\" directory, it's usually not a
|
| 1357 | good idea to give it because the content hash would change by the content hash
|
| 1358 | being stored into the \"parameters\" file)."
|
| 1359 | (let* ((root (operating-system-root-file-system os))
|
| 1360 | (device (file-system-device root))
|
| 1361 | (params (operating-system-boot-parameters
|
| 1362 | os device
|
| 1363 | #:system-kernel-arguments?
|
| 1364 | system-kernel-arguments?)))
|
| 1365 | (scheme-file "parameters"
|
| 1366 | #~(boot-parameters
|
| 1367 | (version 0)
|
| 1368 | (label #$(boot-parameters-label params))
|
| 1369 | (root-device
|
| 1370 | #$(device->sexp
|
| 1371 | (boot-parameters-root-device params)))
|
| 1372 | (kernel #$(boot-parameters-kernel params))
|
| 1373 | (kernel-arguments
|
| 1374 | #$(boot-parameters-kernel-arguments params))
|
| 1375 | #$@(if (boot-parameters-initrd params)
|
| 1376 | #~((initrd #$(boot-parameters-initrd params)))
|
| 1377 | #~())
|
| 1378 | #$@(if (pair? (boot-parameters-multiboot-modules params))
|
| 1379 | #~((multiboot-modules
|
| 1380 | #$(boot-parameters-multiboot-modules params)))
|
| 1381 | #~())
|
| 1382 | (bootloader-name #$(boot-parameters-bootloader-name params))
|
| 1383 | (bootloader-menu-entries
|
| 1384 | #$(map menu-entry->sexp
|
| 1385 | (or (and=> (operating-system-bootloader os)
|
| 1386 | bootloader-configuration-menu-entries)
|
| 1387 | '())))
|
| 1388 | (locale #$(boot-parameters-locale params))
|
| 1389 | (store
|
| 1390 | (device
|
| 1391 | #$(device->sexp (boot-parameters-store-device params)))
|
| 1392 | (mount-point #$(boot-parameters-store-mount-point
|
| 1393 | params))
|
| 1394 | (directory-prefix
|
| 1395 | #$(boot-parameters-store-directory-prefix params))))
|
| 1396 | #:set-load-path? #f)))
|
| 1397 |
|
| 1398 | (define-gexp-compiler (operating-system-compiler (os <operating-system>)
|
| 1399 | system target)
|
| 1400 | ((store-lift
|
| 1401 | (lambda (store)
|
| 1402 | |
| 1403 | |
| 1404 | (run-with-store store (operating-system-derivation os)
|
| 1405 | #:system system
|
| 1406 | #:target target)))))
|
| 1407 |
|
| 1408 | |