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