system.scm 55 KB

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