system.scm 66 KB

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