system.scm 64 KB

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