base.scm 78 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2013, 2014, 2015, 2016, 2017 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2015, 2016 Alex Kost <alezost@gmail.com>
  4. ;;; Copyright © 2015, 2016 Mark H Weaver <mhw@netris.org>
  5. ;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
  6. ;;; Copyright © 2016, 2017 Leo Famulari <leo@famulari.name>
  7. ;;; Copyright © 2016 David Craven <david@craven.ch>
  8. ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
  9. ;;;
  10. ;;; This file is part of GNU Guix.
  11. ;;;
  12. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  13. ;;; under the terms of the GNU General Public License as published by
  14. ;;; the Free Software Foundation; either version 3 of the License, or (at
  15. ;;; your option) any later version.
  16. ;;;
  17. ;;; GNU Guix is distributed in the hope that it will be useful, but
  18. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. ;;; GNU General Public License for more details.
  21. ;;;
  22. ;;; You should have received a copy of the GNU General Public License
  23. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  24. (define-module (gnu services base)
  25. #:use-module (guix store)
  26. #:use-module (gnu services)
  27. #:use-module (gnu services shepherd)
  28. #:use-module (gnu services networking)
  29. #:use-module (gnu system pam)
  30. #:use-module (gnu system shadow) ; 'user-account', etc.
  31. #:use-module (gnu system uuid)
  32. #:use-module (gnu system file-systems) ; 'file-system', etc.
  33. #:use-module (gnu system mapped-devices)
  34. #:use-module ((gnu system linux-initrd)
  35. #:select (file-system-packages))
  36. #:use-module (gnu packages admin)
  37. #:use-module ((gnu packages linux)
  38. #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools))
  39. #:use-module ((gnu packages base)
  40. #:select (canonical-package glibc glibc-utf8-locales))
  41. #:use-module (gnu packages bash)
  42. #:use-module (gnu packages package-management)
  43. #:use-module (gnu packages linux)
  44. #:use-module (gnu packages lsof)
  45. #:use-module (gnu packages terminals)
  46. #:use-module ((gnu build file-systems)
  47. #:select (mount-flags->bit-mask))
  48. #:use-module (guix gexp)
  49. #:use-module (guix records)
  50. #:use-module (guix modules)
  51. #:use-module (srfi srfi-1)
  52. #:use-module (srfi srfi-26)
  53. #:use-module (ice-9 match)
  54. #:use-module (ice-9 format)
  55. #:export (fstab-service-type
  56. root-file-system-service
  57. file-system-service-type
  58. user-unmount-service
  59. swap-service
  60. user-processes-service
  61. host-name-service
  62. console-keymap-service
  63. %default-console-font
  64. console-font-service-type
  65. console-font-service
  66. udev-configuration
  67. udev-configuration?
  68. udev-configuration-rules
  69. udev-service-type
  70. udev-service
  71. udev-rule
  72. login-configuration
  73. login-configuration?
  74. login-service-type
  75. login-service
  76. agetty-configuration
  77. agetty-configuration?
  78. agetty-service
  79. agetty-service-type
  80. mingetty-configuration
  81. mingetty-configuration?
  82. mingetty-service
  83. mingetty-service-type
  84. %nscd-default-caches
  85. %nscd-default-configuration
  86. nscd-configuration
  87. nscd-configuration?
  88. nscd-cache
  89. nscd-cache?
  90. nscd-service-type
  91. nscd-service
  92. syslog-configuration
  93. syslog-configuration?
  94. syslog-service
  95. syslog-service-type
  96. %default-syslog.conf
  97. %default-authorized-guix-keys
  98. guix-configuration
  99. guix-configuration?
  100. guix-configuration-guix
  101. guix-configuration-build-group
  102. guix-configuration-build-accounts
  103. guix-configuration-authorize-key?
  104. guix-configuration-authorized-keys
  105. guix-configuration-use-substitutes?
  106. guix-configuration-substitute-urls
  107. guix-configuration-extra-options
  108. guix-configuration-log-file
  109. guix-configuration-lsof
  110. guix-service
  111. guix-service-type
  112. guix-publish-configuration
  113. guix-publish-configuration?
  114. guix-publish-configuration-guix
  115. guix-publish-configuration-port
  116. guix-publish-configuration-host
  117. guix-publish-configuration-compression-level
  118. guix-publish-configuration-nar-path
  119. guix-publish-configuration-cache
  120. guix-publish-configuration-ttl
  121. guix-publish-service
  122. guix-publish-service-type
  123. gpm-configuration
  124. gpm-configuration?
  125. gpm-service-type
  126. gpm-service
  127. urandom-seed-service-type
  128. urandom-seed-service
  129. rngd-configuration
  130. rngd-configuration?
  131. rngd-service-type
  132. rngd-service
  133. kmscon-configuration
  134. kmscon-configuration?
  135. kmscon-service-type
  136. pam-limits-service-type
  137. pam-limits-service
  138. %base-services))
  139. ;;; Commentary:
  140. ;;;
  141. ;;; Base system services---i.e., services that 99% of the users will want to
  142. ;;; use.
  143. ;;;
  144. ;;; Code:
  145. ;;;
  146. ;;; File systems.
  147. ;;;
  148. (define (file-system->fstab-entry file-system)
  149. "Return a @file{/etc/fstab} entry for @var{file-system}."
  150. (string-append (case (file-system-title file-system)
  151. ((label)
  152. (string-append "LABEL=" (file-system-device file-system)))
  153. ((uuid)
  154. (string-append
  155. "UUID="
  156. (uuid->string (file-system-device file-system))))
  157. (else
  158. (file-system-device file-system)))
  159. "\t"
  160. (file-system-mount-point file-system) "\t"
  161. (file-system-type file-system) "\t"
  162. (or (file-system-options file-system) "defaults") "\t"
  163. ;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
  164. ;; don't have anything sensible to put in there.
  165. ))
  166. (define (file-systems->fstab file-systems)
  167. "Return a @file{/etc} entry for an @file{fstab} describing
  168. @var{file-systems}."
  169. `(("fstab" ,(plain-file "fstab"
  170. (string-append
  171. "\
  172. # This file was generated from your GuixSD configuration. Any changes
  173. # will be lost upon reboot or reconfiguration.\n\n"
  174. (string-join (map file-system->fstab-entry
  175. file-systems)
  176. "\n")
  177. "\n")))))
  178. (define fstab-service-type
  179. ;; The /etc/fstab service.
  180. (service-type (name 'fstab)
  181. (extensions
  182. (list (service-extension etc-service-type
  183. file-systems->fstab)))
  184. (compose concatenate)
  185. (extend append)
  186. (description
  187. "Populate the @file{/etc/fstab} based on the given file
  188. system objects.")))
  189. (define %root-file-system-shepherd-service
  190. (shepherd-service
  191. (documentation "Take care of the root file system.")
  192. (provision '(root-file-system))
  193. (start #~(const #t))
  194. (stop #~(lambda _
  195. ;; Return #f if successfully stopped.
  196. (sync)
  197. (call-with-blocked-asyncs
  198. (lambda ()
  199. (let ((null (%make-void-port "w")))
  200. ;; Close 'shepherd.log'.
  201. (display "closing log\n")
  202. ((@ (shepherd comm) stop-logging))
  203. ;; Redirect the default output ports..
  204. (set-current-output-port null)
  205. (set-current-error-port null)
  206. ;; Close /dev/console.
  207. (for-each close-fdes '(0 1 2))
  208. ;; At this point, there are no open files left, so the
  209. ;; root file system can be re-mounted read-only.
  210. (mount #f "/" #f
  211. (logior MS_REMOUNT MS_RDONLY)
  212. #:update-mtab? #f)
  213. #f)))))
  214. (respawn? #f)))
  215. (define root-file-system-service-type
  216. (shepherd-service-type 'root-file-system
  217. (const %root-file-system-shepherd-service)))
  218. (define (root-file-system-service)
  219. "Return a service whose sole purpose is to re-mount read-only the root file
  220. system upon shutdown (aka. cleanly \"umounting\" root.)
  221. This service must be the root of the service dependency graph so that its
  222. 'stop' action is invoked when shepherd is the only process left."
  223. (service root-file-system-service-type #f))
  224. (define (file-system->shepherd-service-name file-system)
  225. "Return the symbol that denotes the service mounting and unmounting
  226. FILE-SYSTEM."
  227. (symbol-append 'file-system-
  228. (string->symbol (file-system-mount-point file-system))))
  229. (define (mapped-device->shepherd-service-name md)
  230. "Return the symbol that denotes the shepherd service of MD, a <mapped-device>."
  231. (symbol-append 'device-mapping-
  232. (string->symbol (mapped-device-target md))))
  233. (define dependency->shepherd-service-name
  234. (match-lambda
  235. ((? mapped-device? md)
  236. (mapped-device->shepherd-service-name md))
  237. ((? file-system? fs)
  238. (file-system->shepherd-service-name fs))))
  239. (define (file-system-shepherd-service file-system)
  240. "Return the shepherd service for @var{file-system}, or @code{#f} if
  241. @var{file-system} is not auto-mounted upon boot."
  242. (let ((target (file-system-mount-point file-system))
  243. (create? (file-system-create-mount-point? file-system))
  244. (dependencies (file-system-dependencies file-system))
  245. (packages (file-system-packages (list file-system))))
  246. (and (file-system-mount? file-system)
  247. (with-imported-modules (source-module-closure
  248. '((gnu build file-systems)))
  249. (shepherd-service
  250. (provision (list (file-system->shepherd-service-name file-system)))
  251. (requirement `(root-file-system
  252. ,@(map dependency->shepherd-service-name dependencies)))
  253. (documentation "Check, mount, and unmount the given file system.")
  254. (start #~(lambda args
  255. #$(if create?
  256. #~(mkdir-p #$target)
  257. #t)
  258. (let (($PATH (getenv "PATH")))
  259. ;; Make sure fsck.ext2 & co. can be found.
  260. (dynamic-wind
  261. (lambda ()
  262. ;; Don’t display the PATH settings.
  263. (with-output-to-port (%make-void-port "w")
  264. (lambda ()
  265. (set-path-environment-variable "PATH"
  266. '("bin" "sbin")
  267. '#$packages))))
  268. (lambda ()
  269. (mount-file-system
  270. '#$(file-system->spec file-system)
  271. #:root "/"))
  272. (lambda ()
  273. (setenv "PATH" $PATH)))
  274. #t)))
  275. (stop #~(lambda args
  276. ;; Normally there are no processes left at this point, so
  277. ;; TARGET can be safely unmounted.
  278. ;; Make sure PID 1 doesn't keep TARGET busy.
  279. (chdir "/")
  280. (umount #$target)
  281. #f))
  282. ;; We need an additional module.
  283. (modules `(((gnu build file-systems)
  284. #:select (mount-file-system))
  285. ,@%default-modules)))))))
  286. (define (file-system-shepherd-services file-systems)
  287. "Return the list of Shepherd services for FILE-SYSTEMS."
  288. (let* ((file-systems (filter file-system-mount? file-systems)))
  289. (define sink
  290. (shepherd-service
  291. (provision '(file-systems))
  292. (requirement (cons* 'root-file-system 'user-file-systems
  293. (map file-system->shepherd-service-name
  294. file-systems)))
  295. (documentation "Target for all the initially-mounted file systems")
  296. (start #~(const #t))
  297. (stop #~(const #f))))
  298. (cons sink (map file-system-shepherd-service file-systems))))
  299. (define file-system-service-type
  300. (service-type (name 'file-systems)
  301. (extensions
  302. (list (service-extension shepherd-root-service-type
  303. file-system-shepherd-services)
  304. (service-extension fstab-service-type
  305. identity)))
  306. (compose concatenate)
  307. (extend append)
  308. (description
  309. "Provide Shepherd services to mount and unmount the given
  310. file systems, as well as corresponding @file{/etc/fstab} entries.")))
  311. (define user-unmount-service-type
  312. (shepherd-service-type
  313. 'user-file-systems
  314. (lambda (known-mount-points)
  315. (shepherd-service
  316. (documentation "Unmount manually-mounted file systems.")
  317. (provision '(user-file-systems))
  318. (start #~(const #t))
  319. (stop #~(lambda args
  320. (define (known? mount-point)
  321. (member mount-point
  322. (cons* "/proc" "/sys" '#$known-mount-points)))
  323. ;; Make sure we don't keep the user's mount points busy.
  324. (chdir "/")
  325. (for-each (lambda (mount-point)
  326. (format #t "unmounting '~a'...~%" mount-point)
  327. (catch 'system-error
  328. (lambda ()
  329. (umount mount-point))
  330. (lambda args
  331. (let ((errno (system-error-errno args)))
  332. (format #t "failed to unmount '~a': ~a~%"
  333. mount-point (strerror errno))))))
  334. (filter (negate known?) (mount-points)))
  335. #f))))))
  336. (define (user-unmount-service known-mount-points)
  337. "Return a service whose sole purpose is to unmount file systems not listed
  338. in KNOWN-MOUNT-POINTS when it is stopped."
  339. (service user-unmount-service-type known-mount-points))
  340. (define %do-not-kill-file
  341. ;; Name of the file listing PIDs of processes that must survive when halting
  342. ;; the system. Typical example is user-space file systems.
  343. "/etc/shepherd/do-not-kill")
  344. (define user-processes-service-type
  345. (shepherd-service-type
  346. 'user-processes
  347. (lambda (grace-delay)
  348. (shepherd-service
  349. (documentation "When stopped, terminate all user processes.")
  350. (provision '(user-processes))
  351. (requirement '(file-systems))
  352. (start #~(const #t))
  353. (stop #~(lambda _
  354. (define (kill-except omit signal)
  355. ;; Kill all the processes with SIGNAL except those listed
  356. ;; in OMIT and the current process.
  357. (let ((omit (cons (getpid) omit)))
  358. (for-each (lambda (pid)
  359. (unless (memv pid omit)
  360. (false-if-exception
  361. (kill pid signal))))
  362. (processes))))
  363. (define omitted-pids
  364. ;; List of PIDs that must not be killed.
  365. (if (file-exists? #$%do-not-kill-file)
  366. (map string->number
  367. (call-with-input-file #$%do-not-kill-file
  368. (compose string-tokenize
  369. (@ (ice-9 rdelim) read-string))))
  370. '()))
  371. (define (now)
  372. (car (gettimeofday)))
  373. (define (sleep* n)
  374. ;; Really sleep N seconds.
  375. ;; Work around <http://bugs.gnu.org/19581>.
  376. (define start (now))
  377. (let loop ((elapsed 0))
  378. (when (> n elapsed)
  379. (sleep (- n elapsed))
  380. (loop (- (now) start)))))
  381. (define lset= (@ (srfi srfi-1) lset=))
  382. (display "sending all processes the TERM signal\n")
  383. (if (null? omitted-pids)
  384. (begin
  385. ;; Easy: terminate all of them.
  386. (kill -1 SIGTERM)
  387. (sleep* #$grace-delay)
  388. (kill -1 SIGKILL))
  389. (begin
  390. ;; Kill them all except OMITTED-PIDS. XXX: We would
  391. ;; like to (kill -1 SIGSTOP) to get a fixed list of
  392. ;; processes, like 'killall5' does, but that seems
  393. ;; unreliable.
  394. (kill-except omitted-pids SIGTERM)
  395. (sleep* #$grace-delay)
  396. (kill-except omitted-pids SIGKILL)
  397. (delete-file #$%do-not-kill-file)))
  398. (let wait ()
  399. ;; Reap children, if any, so that we don't end up with
  400. ;; zombies and enter an infinite loop.
  401. (let reap-children ()
  402. (define result
  403. (false-if-exception
  404. (waitpid WAIT_ANY (if (null? omitted-pids)
  405. 0
  406. WNOHANG))))
  407. (when (and (pair? result)
  408. (not (zero? (car result))))
  409. (reap-children)))
  410. (let ((pids (processes)))
  411. (unless (lset= = pids (cons 1 omitted-pids))
  412. (format #t "waiting for process termination\
  413. (processes left: ~s)~%"
  414. pids)
  415. (sleep* 2)
  416. (wait))))
  417. (display "all processes have been terminated\n")
  418. #f))
  419. (respawn? #f)))))
  420. (define* (user-processes-service #:key (grace-delay 4))
  421. "Return the service that is responsible for terminating all the processes so
  422. that the root file system can be re-mounted read-only, just before
  423. rebooting/halting. Processes still running GRACE-DELAY seconds after SIGTERM
  424. has been sent are terminated with SIGKILL.
  425. The returned service will depend on 'file-systems', meaning that it is
  426. considered started after all the auto-mount file systems have been mounted.
  427. All the services that spawn processes must depend on this one so that they are
  428. stopped before 'kill' is called."
  429. (service user-processes-service-type grace-delay))
  430. ;;;
  431. ;;; Preserve entropy to seed /dev/urandom on boot.
  432. ;;;
  433. (define %random-seed-file
  434. "/var/lib/random-seed")
  435. (define (urandom-seed-shepherd-service _)
  436. "Return a shepherd service for the /dev/urandom seed."
  437. (list (shepherd-service
  438. (documentation "Preserve entropy across reboots for /dev/urandom.")
  439. (provision '(urandom-seed))
  440. (requirement '(user-processes))
  441. (start #~(lambda _
  442. ;; On boot, write random seed into /dev/urandom.
  443. (when (file-exists? #$%random-seed-file)
  444. (call-with-input-file #$%random-seed-file
  445. (lambda (seed)
  446. (call-with-output-file "/dev/urandom"
  447. (lambda (urandom)
  448. (dump-port seed urandom))))))
  449. ;; Immediately refresh the seed in case the system doesn't
  450. ;; shut down cleanly.
  451. (call-with-input-file "/dev/urandom"
  452. (lambda (urandom)
  453. (let ((previous-umask (umask #o077))
  454. (buf (make-bytevector 512)))
  455. (mkdir-p (dirname #$%random-seed-file))
  456. (get-bytevector-n! urandom buf 0 512)
  457. (call-with-output-file #$%random-seed-file
  458. (lambda (seed)
  459. (put-bytevector seed buf)))
  460. (umask previous-umask))))
  461. #t))
  462. (stop #~(lambda _
  463. ;; During shutdown, write from /dev/urandom into random seed.
  464. (let ((buf (make-bytevector 512)))
  465. (call-with-input-file "/dev/urandom"
  466. (lambda (urandom)
  467. (let ((previous-umask (umask #o077)))
  468. (get-bytevector-n! urandom buf 0 512)
  469. (mkdir-p (dirname #$%random-seed-file))
  470. (call-with-output-file #$%random-seed-file
  471. (lambda (seed)
  472. (put-bytevector seed buf)))
  473. (umask previous-umask))
  474. #t)))))
  475. (modules `((rnrs bytevectors)
  476. (rnrs io ports)
  477. ,@%default-modules)))))
  478. (define urandom-seed-service-type
  479. (service-type (name 'urandom-seed)
  480. (extensions
  481. (list (service-extension shepherd-root-service-type
  482. urandom-seed-shepherd-service)))
  483. (description
  484. "Seed the @file{/dev/urandom} pseudo-random number
  485. generator (RNG) with the value recorded when the system was last shut
  486. down.")))
  487. (define (urandom-seed-service)
  488. (service urandom-seed-service-type #f))
  489. ;;;
  490. ;;; Add hardware random number generator to entropy pool.
  491. ;;;
  492. (define-record-type* <rngd-configuration>
  493. rngd-configuration make-rngd-configuration
  494. rngd-configuration?
  495. (rng-tools rngd-configuration-rng-tools) ;package
  496. (device rngd-configuration-device)) ;string
  497. (define rngd-service-type
  498. (shepherd-service-type
  499. 'rngd
  500. (lambda (config)
  501. (define rng-tools (rngd-configuration-rng-tools config))
  502. (define device (rngd-configuration-device config))
  503. (define rngd-command
  504. (list (file-append rng-tools "/sbin/rngd")
  505. "-f" "-r" device))
  506. (shepherd-service
  507. (documentation "Add TRNG to entropy pool.")
  508. (requirement '(udev))
  509. (provision '(trng))
  510. (start #~(make-forkexec-constructor #$@rngd-command))
  511. (stop #~(make-kill-destructor))))))
  512. (define* (rngd-service #:key
  513. (rng-tools rng-tools)
  514. (device "/dev/hwrng"))
  515. "Return a service that runs the @command{rngd} program from @var{rng-tools}
  516. to add @var{device} to the kernel's entropy pool. The service will fail if
  517. @var{device} does not exist."
  518. (service rngd-service-type
  519. (rngd-configuration
  520. (rng-tools rng-tools)
  521. (device device))))
  522. ;;;
  523. ;;; Console & co.
  524. ;;;
  525. (define host-name-service-type
  526. (shepherd-service-type
  527. 'host-name
  528. (lambda (name)
  529. (shepherd-service
  530. (documentation "Initialize the machine's host name.")
  531. (provision '(host-name))
  532. (start #~(lambda _
  533. (sethostname #$name)))
  534. (respawn? #f)))))
  535. (define (host-name-service name)
  536. "Return a service that sets the host name to @var{name}."
  537. (service host-name-service-type name))
  538. (define (unicode-start tty)
  539. "Return a gexp to start Unicode support on @var{tty}."
  540. ;; We have to run 'unicode_start' in a pipe so that when it invokes the
  541. ;; 'tty' command, that command returns TTY.
  542. #~(begin
  543. (let ((pid (primitive-fork)))
  544. (case pid
  545. ((0)
  546. (close-fdes 0)
  547. (dup2 (open-fdes #$tty O_RDONLY) 0)
  548. (close-fdes 1)
  549. (dup2 (open-fdes #$tty O_WRONLY) 1)
  550. (execl #$(file-append kbd "/bin/unicode_start")
  551. "unicode_start"))
  552. (else
  553. (zero? (cdr (waitpid pid))))))))
  554. (define console-keymap-service-type
  555. (shepherd-service-type
  556. 'console-keymap
  557. (lambda (files)
  558. (shepherd-service
  559. (documentation (string-append "Load console keymap (loadkeys)."))
  560. (provision '(console-keymap))
  561. (start #~(lambda _
  562. (zero? (system* #$(file-append kbd "/bin/loadkeys")
  563. #$@files))))
  564. (respawn? #f)))))
  565. (define (console-keymap-service . files)
  566. "Return a service to load console keymaps from @var{files}."
  567. (service console-keymap-service-type files))
  568. (define %default-console-font
  569. ;; Note: 'LatGrkCyr-8x16' has the advantage of providing three common
  570. ;; scripts as well as glyphs for em dash, quotation marks, and other Unicode
  571. ;; codepoints notably found in the UTF-8 manual.
  572. "LatGrkCyr-8x16")
  573. (define (console-font-shepherd-services tty+font)
  574. "Return a list of Shepherd services for each pair in TTY+FONT."
  575. (map (match-lambda
  576. ((tty . font)
  577. (let ((device (string-append "/dev/" tty)))
  578. (shepherd-service
  579. (documentation "Load a Unicode console font.")
  580. (provision (list (symbol-append 'console-font-
  581. (string->symbol tty))))
  582. ;; Start after mingetty has been started on TTY, otherwise the settings
  583. ;; are ignored.
  584. (requirement (list (symbol-append 'term-
  585. (string->symbol tty))))
  586. (start #~(lambda _
  587. (and #$(unicode-start device)
  588. (zero?
  589. (system* #$(file-append kbd "/bin/setfont")
  590. "-C" #$device #$font)))))
  591. (stop #~(const #t))
  592. (respawn? #f)))))
  593. tty+font))
  594. (define console-font-service-type
  595. (service-type (name 'console-fonts)
  596. (extensions
  597. (list (service-extension shepherd-root-service-type
  598. console-font-shepherd-services)))
  599. (compose concatenate)
  600. (extend append)
  601. (description
  602. "Install the given fonts on the specified ttys (fonts are per
  603. virtual console on GNU/Linux). The value of this service is a list of
  604. tty/font pairs like:
  605. @example
  606. '((\"tty1\" . \"LatGrkCyr-8x16\"))
  607. @end example\n")))
  608. (define* (console-font-service tty #:optional (font "LatGrkCyr-8x16"))
  609. "This procedure is deprecated in favor of @code{console-font-service-type}.
  610. Return a service that sets up Unicode support in @var{tty} and loads
  611. @var{font} for that tty (fonts are per virtual console in Linux.)"
  612. (simple-service (symbol-append 'console-font- (string->symbol tty))
  613. console-font-service-type `((,tty . ,font))))
  614. (define %default-motd
  615. (plain-file "motd" "This is the GNU operating system, welcome!\n\n"))
  616. (define-record-type* <login-configuration>
  617. login-configuration make-login-configuration
  618. login-configuration?
  619. (motd login-configuration-motd ;file-like
  620. (default %default-motd))
  621. ;; Allow empty passwords by default so that first-time users can log in when
  622. ;; the 'root' account has just been created.
  623. (allow-empty-passwords? login-configuration-allow-empty-passwords?
  624. (default #t))) ;Boolean
  625. (define (login-pam-service config)
  626. "Return the list of PAM service needed for CONF."
  627. ;; Let 'login' be known to PAM.
  628. (list (unix-pam-service "login"
  629. #:allow-empty-passwords?
  630. (login-configuration-allow-empty-passwords? config)
  631. #:motd
  632. (login-configuration-motd config))))
  633. (define login-service-type
  634. (service-type (name 'login)
  635. (extensions (list (service-extension pam-root-service-type
  636. login-pam-service)))
  637. (description
  638. "Provide a console log-in service as specified by its
  639. configuration value, a @code{login-configuration} object.")))
  640. (define* (login-service #:optional (config (login-configuration)))
  641. "Return a service configure login according to @var{config}, which specifies
  642. the message of the day, among other things."
  643. (service login-service-type config))
  644. (define-record-type* <agetty-configuration>
  645. agetty-configuration make-agetty-configuration
  646. agetty-configuration?
  647. (agetty agetty-configuration-agetty ;<package>
  648. (default util-linux))
  649. (tty agetty-configuration-tty) ;string
  650. (term agetty-term ;string | #f
  651. (default #f))
  652. (baud-rate agetty-baud-rate ;string | #f
  653. (default #f))
  654. (auto-login agetty-auto-login ;list of strings | #f
  655. (default #f))
  656. (login-program agetty-login-program ;gexp
  657. (default (file-append shadow "/bin/login")))
  658. (login-pause? agetty-login-pause? ;Boolean
  659. (default #f))
  660. (eight-bits? agetty-eight-bits? ;Boolean
  661. (default #f))
  662. (no-reset? agetty-no-reset? ;Boolean
  663. (default #f))
  664. (remote? agetty-remote? ;Boolean
  665. (default #f))
  666. (flow-control? agetty-flow-control? ;Boolean
  667. (default #f))
  668. (host agetty-host ;string | #f
  669. (default #f))
  670. (no-issue? agetty-no-issue? ;Boolean
  671. (default #f))
  672. (init-string agetty-init-string ;string | #f
  673. (default #f))
  674. (no-clear? agetty-no-clear? ;Boolean
  675. (default #f))
  676. (local-line agetty-local-line ;always | never | auto
  677. (default #f))
  678. (extract-baud? agetty-extract-baud? ;Boolean
  679. (default #f))
  680. (skip-login? agetty-skip-login? ;Boolean
  681. (default #f))
  682. (no-newline? agetty-no-newline? ;Boolean
  683. (default #f))
  684. (login-options agetty-login-options ;string | #f
  685. (default #f))
  686. (chroot agetty-chroot ;string | #f
  687. (default #f))
  688. (hangup? agetty-hangup? ;Boolean
  689. (default #f))
  690. (keep-baud? agetty-keep-baud? ;Boolean
  691. (default #f))
  692. (timeout agetty-timeout ;integer | #f
  693. (default #f))
  694. (detect-case? agetty-detect-case? ;Boolean
  695. (default #f))
  696. (wait-cr? agetty-wait-cr? ;Boolean
  697. (default #f))
  698. (no-hints? agetty-no-hints? ;Boolean
  699. (default #f))
  700. (no-hostname? agetty-no hostname? ;Boolean
  701. (default #f))
  702. (long-hostname? agetty-long-hostname? ;Boolean
  703. (default #f))
  704. (erase-characters agetty-erase-characters ;string | #f
  705. (default #f))
  706. (kill-characters agetty-kill-characters ;string | #f
  707. (default #f))
  708. (chdir agetty-chdir ;string | #f
  709. (default #f))
  710. (delay agetty-delay ;integer | #f
  711. (default #f))
  712. (nice agetty-nice ;integer | #f
  713. (default #f))
  714. ;; "Escape hatch" for passing arbitrary command-line arguments.
  715. (extra-options agetty-extra-options ;list of strings
  716. (default '()))
  717. ;;; XXX Unimplemented for now!
  718. ;;; (issue-file agetty-issue-file ;file-like
  719. ;;; (default #f))
  720. )
  721. (define agetty-shepherd-service
  722. (match-lambda
  723. (($ <agetty-configuration> agetty tty term baud-rate auto-login
  724. login-program login-pause? eight-bits? no-reset? remote? flow-control?
  725. host no-issue? init-string no-clear? local-line extract-baud?
  726. skip-login? no-newline? login-options chroot hangup? keep-baud? timeout
  727. detect-case? wait-cr? no-hints? no-hostname? long-hostname?
  728. erase-characters kill-characters chdir delay nice extra-options)
  729. (list
  730. (shepherd-service
  731. (documentation "Run agetty on a tty.")
  732. (provision (list (symbol-append 'term- (string->symbol tty))))
  733. ;; Since the login prompt shows the host name, wait for the 'host-name'
  734. ;; service to be done. Also wait for udev essentially so that the tty
  735. ;; text is not lost in the middle of kernel messages (see also
  736. ;; mingetty-shepherd-service).
  737. (requirement '(user-processes host-name udev))
  738. (start #~(make-forkexec-constructor
  739. (list #$(file-append util-linux "/sbin/agetty")
  740. #$@extra-options
  741. #$@(if eight-bits?
  742. #~("--8bits")
  743. #~())
  744. #$@(if no-reset?
  745. #~("--noreset")
  746. #~())
  747. #$@(if remote?
  748. #~("--remote")
  749. #~())
  750. #$@(if flow-control?
  751. #~("--flow-control")
  752. #~())
  753. #$@(if host
  754. #~("--host" #$host)
  755. #~())
  756. #$@(if no-issue?
  757. #~("--noissue")
  758. #~())
  759. #$@(if init-string
  760. #~("--init-string" #$init-string)
  761. #~())
  762. #$@(if no-clear?
  763. #~("--noclear")
  764. #~())
  765. ;;; FIXME This doesn't work as expected. According to agetty(8), if this option
  766. ;;; is not passed, then the default is 'auto'. However, in my tests, when that
  767. ;;; option is selected, agetty never presents the login prompt, and the
  768. ;;; term-ttyS0 service respawns every few seconds.
  769. #$@(if local-line
  770. #~(#$(match local-line
  771. ('auto "--local-line=auto")
  772. ('always "--local-line=always")
  773. ('never "-local-line=never")))
  774. #~())
  775. #$@(if extract-baud?
  776. #~("--extract-baud")
  777. #~())
  778. #$@(if skip-login?
  779. #~("--skip-login")
  780. #~())
  781. #$@(if no-newline?
  782. #~("--nonewline")
  783. #~())
  784. #$@(if login-options
  785. #~("--login-options" #$login-options)
  786. #~())
  787. #$@(if chroot
  788. #~("--chroot" #$chroot)
  789. #~())
  790. #$@(if hangup?
  791. #~("--hangup")
  792. #~())
  793. #$@(if keep-baud?
  794. #~("--keep-baud")
  795. #~())
  796. #$@(if timeout
  797. #~("--timeout" #$(number->string timeout))
  798. #~())
  799. #$@(if detect-case?
  800. #~("--detect-case")
  801. #~())
  802. #$@(if wait-cr?
  803. #~("--wait-cr")
  804. #~())
  805. #$@(if no-hints?
  806. #~("--nohints?")
  807. #~())
  808. #$@(if no-hostname?
  809. #~("--nohostname")
  810. #~())
  811. #$@(if long-hostname?
  812. #~("--long-hostname")
  813. #~())
  814. #$@(if erase-characters
  815. #~("--erase-chars" #$erase-characters)
  816. #~())
  817. #$@(if kill-characters
  818. #~("--kill-chars" #$kill-characters)
  819. #~())
  820. #$@(if chdir
  821. #~("--chdir" #$chdir)
  822. #~())
  823. #$@(if delay
  824. #~("--delay" #$(number->string delay))
  825. #~())
  826. #$@(if nice
  827. #~("--nice" #$(number->string nice))
  828. #~())
  829. #$@(if auto-login
  830. (list "--autologin" auto-login)
  831. '())
  832. #$@(if login-program
  833. #~("--login-program" #$login-program)
  834. #~())
  835. #$@(if login-pause?
  836. #~("--login-pause")
  837. #~())
  838. #$tty
  839. #$@(if baud-rate
  840. #~(#$baud-rate)
  841. #~())
  842. #$@(if term
  843. #~(#$term)
  844. #~()))))
  845. (stop #~(make-kill-destructor)))))))
  846. (define agetty-service-type
  847. (service-type (name 'agetty)
  848. (extensions (list (service-extension shepherd-root-service-type
  849. agetty-shepherd-service)))
  850. (description
  851. "Provide console login using the @command{agetty}
  852. program.")))
  853. (define* (agetty-service config)
  854. "Return a service to run agetty according to @var{config}, which specifies
  855. the tty to run, among other things."
  856. (service agetty-service-type config))
  857. (define-record-type* <mingetty-configuration>
  858. mingetty-configuration make-mingetty-configuration
  859. mingetty-configuration?
  860. (mingetty mingetty-configuration-mingetty ;<package>
  861. (default mingetty))
  862. (tty mingetty-configuration-tty) ;string
  863. (auto-login mingetty-auto-login ;string | #f
  864. (default #f))
  865. (login-program mingetty-login-program ;gexp
  866. (default #f))
  867. (login-pause? mingetty-login-pause? ;Boolean
  868. (default #f)))
  869. (define mingetty-shepherd-service
  870. (match-lambda
  871. (($ <mingetty-configuration> mingetty tty auto-login login-program
  872. login-pause?)
  873. (list
  874. (shepherd-service
  875. (documentation "Run mingetty on an tty.")
  876. (provision (list (symbol-append 'term- (string->symbol tty))))
  877. ;; Since the login prompt shows the host name, wait for the 'host-name'
  878. ;; service to be done. Also wait for udev essentially so that the tty
  879. ;; text is not lost in the middle of kernel messages (XXX).
  880. (requirement '(user-processes host-name udev))
  881. (start #~(make-forkexec-constructor
  882. (list #$(file-append mingetty "/sbin/mingetty")
  883. "--noclear" #$tty
  884. #$@(if auto-login
  885. #~("--autologin" #$auto-login)
  886. #~())
  887. #$@(if login-program
  888. #~("--loginprog" #$login-program)
  889. #~())
  890. #$@(if login-pause?
  891. #~("--loginpause")
  892. #~()))))
  893. (stop #~(make-kill-destructor)))))))
  894. (define mingetty-service-type
  895. (service-type (name 'mingetty)
  896. (extensions (list (service-extension shepherd-root-service-type
  897. mingetty-shepherd-service)))
  898. (description
  899. "Provide console login using the @command{mingetty}
  900. program.")))
  901. (define* (mingetty-service config)
  902. "Return a service to run mingetty according to @var{config}, which specifies
  903. the tty to run, among other things."
  904. (service mingetty-service-type config))
  905. (define-record-type* <nscd-configuration> nscd-configuration
  906. make-nscd-configuration
  907. nscd-configuration?
  908. (log-file nscd-configuration-log-file ;string
  909. (default "/var/log/nscd.log"))
  910. (debug-level nscd-debug-level ;integer
  911. (default 0))
  912. ;; TODO: See nscd.conf in glibc for other options to add.
  913. (caches nscd-configuration-caches ;list of <nscd-cache>
  914. (default %nscd-default-caches))
  915. (name-services nscd-configuration-name-services ;list of <packages>
  916. (default '()))
  917. (glibc nscd-configuration-glibc ;<package>
  918. (default (canonical-package glibc))))
  919. (define-record-type* <nscd-cache> nscd-cache make-nscd-cache
  920. nscd-cache?
  921. (database nscd-cache-database) ;symbol
  922. (positive-time-to-live nscd-cache-positive-time-to-live) ;integer
  923. (negative-time-to-live nscd-cache-negative-time-to-live
  924. (default 20)) ;integer
  925. (suggested-size nscd-cache-suggested-size ;integer ("default module
  926. ;of hash table")
  927. (default 211))
  928. (check-files? nscd-cache-check-files? ;Boolean
  929. (default #t))
  930. (persistent? nscd-cache-persistent? ;Boolean
  931. (default #t))
  932. (shared? nscd-cache-shared? ;Boolean
  933. (default #t))
  934. (max-database-size nscd-cache-max-database-size ;integer
  935. (default (* 32 (expt 2 20))))
  936. (auto-propagate? nscd-cache-auto-propagate? ;Boolean
  937. (default #t)))
  938. (define %nscd-default-caches
  939. ;; Caches that we want to enable by default. Note that when providing an
  940. ;; empty nscd.conf, all caches are disabled.
  941. (list (nscd-cache (database 'hosts)
  942. ;; Aggressively cache the host name cache to improve
  943. ;; privacy and resilience.
  944. (positive-time-to-live (* 3600 12))
  945. (negative-time-to-live 20)
  946. (persistent? #t))
  947. (nscd-cache (database 'services)
  948. ;; Services are unlikely to change, so we can be even more
  949. ;; aggressive.
  950. (positive-time-to-live (* 3600 24))
  951. (negative-time-to-live 3600)
  952. (check-files? #t) ;check /etc/services changes
  953. (persistent? #t))))
  954. (define %nscd-default-configuration
  955. ;; Default nscd configuration.
  956. (nscd-configuration))
  957. (define (nscd.conf-file config)
  958. "Return the @file{nscd.conf} configuration file for @var{config}, an
  959. @code{<nscd-configuration>} object."
  960. (define cache->config
  961. (match-lambda
  962. (($ <nscd-cache> (= symbol->string database)
  963. positive-ttl negative-ttl size check-files?
  964. persistent? shared? max-size propagate?)
  965. (string-append "\nenable-cache\t" database "\tyes\n"
  966. "positive-time-to-live\t" database "\t"
  967. (number->string positive-ttl) "\n"
  968. "negative-time-to-live\t" database "\t"
  969. (number->string negative-ttl) "\n"
  970. "suggested-size\t" database "\t"
  971. (number->string size) "\n"
  972. "check-files\t" database "\t"
  973. (if check-files? "yes\n" "no\n")
  974. "persistent\t" database "\t"
  975. (if persistent? "yes\n" "no\n")
  976. "shared\t" database "\t"
  977. (if shared? "yes\n" "no\n")
  978. "max-db-size\t" database "\t"
  979. (number->string max-size) "\n"
  980. "auto-propagate\t" database "\t"
  981. (if propagate? "yes\n" "no\n")))))
  982. (match config
  983. (($ <nscd-configuration> log-file debug-level caches)
  984. (plain-file "nscd.conf"
  985. (string-append "\
  986. # Configuration of libc's name service cache daemon (nscd).\n\n"
  987. (if log-file
  988. (string-append "logfile\t" log-file)
  989. "")
  990. "\n"
  991. (if debug-level
  992. (string-append "debug-level\t"
  993. (number->string debug-level))
  994. "")
  995. "\n"
  996. (string-concatenate
  997. (map cache->config caches)))))))
  998. (define (nscd-shepherd-service config)
  999. "Return a shepherd service for CONFIG, an <nscd-configuration> object."
  1000. (let ((nscd.conf (nscd.conf-file config))
  1001. (name-services (nscd-configuration-name-services config)))
  1002. (list (shepherd-service
  1003. (documentation "Run libc's name service cache daemon (nscd).")
  1004. (provision '(nscd))
  1005. (requirement '(user-processes))
  1006. (start #~(make-forkexec-constructor
  1007. (list #$(file-append (nscd-configuration-glibc config)
  1008. "/sbin/nscd")
  1009. "-f" #$nscd.conf "--foreground")
  1010. ;; Wait for the PID file. However, the PID file is
  1011. ;; written before nscd is actually listening on its
  1012. ;; socket (XXX).
  1013. #:pid-file "/var/run/nscd/nscd.pid"
  1014. #:environment-variables
  1015. (list (string-append "LD_LIBRARY_PATH="
  1016. (string-join
  1017. (map (lambda (dir)
  1018. (string-append dir "/lib"))
  1019. (list #$@name-services))
  1020. ":")))))
  1021. (stop #~(make-kill-destructor))))))
  1022. (define nscd-activation
  1023. ;; Actions to take before starting nscd.
  1024. #~(begin
  1025. (use-modules (guix build utils))
  1026. (mkdir-p "/var/run/nscd")
  1027. (mkdir-p "/var/db/nscd") ;for the persistent cache
  1028. ;; In libc 2.25 nscd uses inotify to watch /etc/resolv.conf, but only if
  1029. ;; that file exists when it is started. Thus create it here. Note: on
  1030. ;; some systems, such as when NetworkManager is used, /etc/resolv.conf
  1031. ;; is a symlink, hence 'lstat'.
  1032. (unless (false-if-exception (lstat "/etc/resolv.conf"))
  1033. (call-with-output-file "/etc/resolv.conf"
  1034. (lambda (port)
  1035. (display "# This is a placeholder.\n" port))))))
  1036. (define nscd-service-type
  1037. (service-type (name 'nscd)
  1038. (extensions
  1039. (list (service-extension activation-service-type
  1040. (const nscd-activation))
  1041. (service-extension shepherd-root-service-type
  1042. nscd-shepherd-service)))
  1043. ;; This can be extended by providing additional name services
  1044. ;; such as nss-mdns.
  1045. (compose concatenate)
  1046. (extend (lambda (config name-services)
  1047. (nscd-configuration
  1048. (inherit config)
  1049. (name-services (append
  1050. (nscd-configuration-name-services config)
  1051. name-services)))))
  1052. (description
  1053. "Runs libc's @dfn{name service cache daemon} (nscd) with the
  1054. given configuration---an @code{<nscd-configuration>} object. @xref{Name
  1055. Service Switch}, for an example.")))
  1056. (define* (nscd-service #:optional (config %nscd-default-configuration))
  1057. "Return a service that runs libc's name service cache daemon (nscd) with the
  1058. given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
  1059. Service Switch}, for an example."
  1060. (service nscd-service-type config))
  1061. (define-record-type* <syslog-configuration>
  1062. syslog-configuration make-syslog-configuration
  1063. syslog-configuration?
  1064. (syslogd syslog-configuration-syslogd
  1065. (default (file-append inetutils "/libexec/syslogd")))
  1066. (config-file syslog-configuration-config-file
  1067. (default %default-syslog.conf)))
  1068. (define syslog-service-type
  1069. (shepherd-service-type
  1070. 'syslog
  1071. (lambda (config)
  1072. (shepherd-service
  1073. (documentation "Run the syslog daemon (syslogd).")
  1074. (provision '(syslogd))
  1075. (requirement '(user-processes))
  1076. (start #~(make-forkexec-constructor
  1077. (list #$(syslog-configuration-syslogd config)
  1078. "--rcfile" #$(syslog-configuration-config-file config))
  1079. #:pid-file "/var/run/syslog.pid"))
  1080. (stop #~(make-kill-destructor))))))
  1081. ;; Snippet adapted from the GNU inetutils manual.
  1082. (define %default-syslog.conf
  1083. (plain-file "syslog.conf" "
  1084. # Log all error messages, authentication messages of
  1085. # level notice or higher and anything of level err or
  1086. # higher to the console.
  1087. # Don't log private authentication messages!
  1088. *.alert;auth.notice;authpriv.none /dev/console
  1089. # Log anything (except mail) of level info or higher.
  1090. # Don't log private authentication messages!
  1091. *.info;mail.none;authpriv.none /var/log/messages
  1092. # Like /var/log/messages, but also including \"debug\"-level logs.
  1093. *.debug;mail.none;authpriv.none /var/log/debug
  1094. # Same, in a different place.
  1095. *.info;mail.none;authpriv.none /dev/tty12
  1096. # The authpriv file has restricted access.
  1097. authpriv.* /var/log/secure
  1098. # Log all the mail messages in one place.
  1099. mail.* /var/log/maillog
  1100. "))
  1101. (define* (syslog-service #:optional (config (syslog-configuration)))
  1102. "Return a service that runs @command{syslogd} and takes
  1103. @var{<syslog-configuration>} as a parameter.
  1104. @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
  1105. information on the configuration file syntax."
  1106. (service syslog-service-type config))
  1107. (define pam-limits-service-type
  1108. (let ((security-limits
  1109. ;; Create /etc/security containing the provided "limits.conf" file.
  1110. (lambda (limits-file)
  1111. `(("security"
  1112. ,(computed-file
  1113. "security"
  1114. #~(begin
  1115. (mkdir #$output)
  1116. (stat #$limits-file)
  1117. (symlink #$limits-file
  1118. (string-append #$output "/limits.conf"))))))))
  1119. (pam-extension
  1120. (lambda (pam)
  1121. (let ((pam-limits (pam-entry
  1122. (control "required")
  1123. (module "pam_limits.so")
  1124. (arguments '("conf=/etc/security/limits.conf")))))
  1125. (if (member (pam-service-name pam)
  1126. '("login" "su" "slim"))
  1127. (pam-service
  1128. (inherit pam)
  1129. (session (cons pam-limits
  1130. (pam-service-session pam))))
  1131. pam)))))
  1132. (service-type
  1133. (name 'limits)
  1134. (extensions
  1135. (list (service-extension etc-service-type security-limits)
  1136. (service-extension pam-root-service-type
  1137. (lambda _ (list pam-extension)))))
  1138. (description
  1139. "Install the specified resource usage limits by populating
  1140. @file{/etc/security/limits.conf} and using the @code{pam_limits}
  1141. authentication module."))))
  1142. (define* (pam-limits-service #:optional (limits '()))
  1143. "Return a service that makes selected programs respect the list of
  1144. pam-limits-entry specified in LIMITS via pam_limits.so."
  1145. (service pam-limits-service-type
  1146. (plain-file "limits.conf"
  1147. (string-join (map pam-limits-entry->string limits)
  1148. "\n"))))
  1149. ;;;
  1150. ;;; Guix services.
  1151. ;;;
  1152. (define* (guix-build-accounts count #:key
  1153. (group "guixbuild")
  1154. (first-uid 30001)
  1155. (shadow shadow))
  1156. "Return a list of COUNT user accounts for Guix build users, with UIDs
  1157. starting at FIRST-UID, and under GID."
  1158. (unfold (cut > <> count)
  1159. (lambda (n)
  1160. (user-account
  1161. (name (format #f "guixbuilder~2,'0d" n))
  1162. (system? #t)
  1163. (uid (+ first-uid n -1))
  1164. (group group)
  1165. ;; guix-daemon expects GROUP to be listed as a
  1166. ;; supplementary group too:
  1167. ;; <http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html>.
  1168. (supplementary-groups (list group "kvm"))
  1169. (comment (format #f "Guix Build User ~2d" n))
  1170. (home-directory "/var/empty")
  1171. (shell (file-append shadow "/sbin/nologin"))))
  1172. 1+
  1173. 1))
  1174. (define (hydra-key-authorization key guix)
  1175. "Return a gexp with code to register KEY, a file containing a 'guix archive'
  1176. public key, with GUIX."
  1177. #~(unless (file-exists? "/etc/guix/acl")
  1178. (let ((pid (primitive-fork)))
  1179. (case pid
  1180. ((0)
  1181. (let* ((key #$key)
  1182. (port (open-file key "r0b")))
  1183. (format #t "registering public key '~a'...~%" key)
  1184. (close-port (current-input-port))
  1185. (dup port 0)
  1186. (execl #$(file-append guix "/bin/guix")
  1187. "guix" "archive" "--authorize")
  1188. (exit 1)))
  1189. (else
  1190. (let ((status (cdr (waitpid pid))))
  1191. (unless (zero? status)
  1192. (format (current-error-port) "warning: \
  1193. failed to register hydra.gnu.org public key: ~a~%" status))))))))
  1194. (define %default-authorized-guix-keys
  1195. ;; List of authorized substitute keys.
  1196. (list (file-append guix "/share/guix/hydra.gnu.org.pub")
  1197. (file-append guix "/share/guix/bayfront.guixsd.org.pub")))
  1198. (define-record-type* <guix-configuration>
  1199. guix-configuration make-guix-configuration
  1200. guix-configuration?
  1201. (guix guix-configuration-guix ;<package>
  1202. (default guix))
  1203. (build-group guix-configuration-build-group ;string
  1204. (default "guixbuild"))
  1205. (build-accounts guix-configuration-build-accounts ;integer
  1206. (default 10))
  1207. (authorize-key? guix-configuration-authorize-key? ;Boolean
  1208. (default #t))
  1209. (authorized-keys guix-configuration-authorized-keys ;list of gexps
  1210. (default %default-authorized-guix-keys))
  1211. (use-substitutes? guix-configuration-use-substitutes? ;Boolean
  1212. (default #t))
  1213. (substitute-urls guix-configuration-substitute-urls ;list of strings
  1214. (default %default-substitute-urls))
  1215. (max-silent-time guix-configuration-max-silent-time ;integer
  1216. (default 0))
  1217. (timeout guix-configuration-timeout ;integer
  1218. (default 0))
  1219. (extra-options guix-configuration-extra-options ;list of strings
  1220. (default '()))
  1221. (log-file guix-configuration-log-file ;string
  1222. (default "/var/log/guix-daemon.log"))
  1223. (lsof guix-configuration-lsof ;<package>
  1224. (default lsof))
  1225. (http-proxy guix-http-proxy ;string | #f
  1226. (default #f))
  1227. (tmpdir guix-tmpdir ;string | #f
  1228. (default #f)))
  1229. (define %default-guix-configuration
  1230. (guix-configuration))
  1231. (define (guix-shepherd-service config)
  1232. "Return a <shepherd-service> for the Guix daemon service with CONFIG."
  1233. (match config
  1234. (($ <guix-configuration> guix build-group build-accounts
  1235. authorize-key? keys
  1236. use-substitutes? substitute-urls
  1237. max-silent-time timeout
  1238. extra-options
  1239. log-file lsof http-proxy tmpdir)
  1240. (list (shepherd-service
  1241. (documentation "Run the Guix daemon.")
  1242. (provision '(guix-daemon))
  1243. (requirement '(user-processes))
  1244. (start
  1245. #~(make-forkexec-constructor
  1246. (list #$(file-append guix "/bin/guix-daemon")
  1247. "--build-users-group" #$build-group
  1248. "--max-silent-time" #$(number->string max-silent-time)
  1249. "--timeout" #$(number->string timeout)
  1250. #$@(if use-substitutes?
  1251. '()
  1252. '("--no-substitutes"))
  1253. "--substitute-urls" #$(string-join substitute-urls)
  1254. #$@extra-options)
  1255. ;; Add 'lsof' (for the GC) to the daemon's $PATH.
  1256. #:environment-variables
  1257. (list (string-append "PATH=" #$lsof "/bin")
  1258. #$@(if http-proxy
  1259. (list (string-append "http_proxy=" http-proxy))
  1260. '())
  1261. #$@(if tmpdir
  1262. (list (string-append "TMPDIR=" tmpdir))
  1263. '()))
  1264. #:log-file #$log-file))
  1265. (stop #~(make-kill-destructor)))))))
  1266. (define (guix-accounts config)
  1267. "Return the user accounts and user groups for CONFIG."
  1268. (match config
  1269. (($ <guix-configuration> _ build-group build-accounts)
  1270. (cons (user-group
  1271. (name build-group)
  1272. (system? #t)
  1273. ;; Use a fixed GID so that we can create the store with the right
  1274. ;; owner.
  1275. (id 30000))
  1276. (guix-build-accounts build-accounts
  1277. #:group build-group)))))
  1278. (define (guix-activation config)
  1279. "Return the activation gexp for CONFIG."
  1280. (match config
  1281. (($ <guix-configuration> guix build-group build-accounts authorize-key? keys)
  1282. ;; Assume that the store has BUILD-GROUP as its group. We could
  1283. ;; otherwise call 'chown' here, but the problem is that on a COW unionfs,
  1284. ;; chown leads to an entire copy of the tree, which is a bad idea.
  1285. ;; Optionally authorize hydra.gnu.org's key.
  1286. (if authorize-key?
  1287. #~(begin
  1288. #$@(map (cut hydra-key-authorization <> guix) keys))
  1289. #~#f))))
  1290. (define guix-service-type
  1291. (service-type
  1292. (name 'guix)
  1293. (extensions
  1294. (list (service-extension shepherd-root-service-type guix-shepherd-service)
  1295. (service-extension account-service-type guix-accounts)
  1296. (service-extension activation-service-type guix-activation)
  1297. (service-extension profile-service-type
  1298. (compose list guix-configuration-guix))))
  1299. (default-value (guix-configuration))
  1300. (description
  1301. "Run the build daemon of GNU@tie{}Guix, aka. @command{guix-daemon}.")))
  1302. (define* (guix-service #:optional (config %default-guix-configuration))
  1303. "Return a service that runs the Guix build daemon according to
  1304. @var{config}."
  1305. (service guix-service-type config))
  1306. (define-record-type* <guix-publish-configuration>
  1307. guix-publish-configuration make-guix-publish-configuration
  1308. guix-publish-configuration?
  1309. (guix guix-publish-configuration-guix ;package
  1310. (default guix))
  1311. (port guix-publish-configuration-port ;number
  1312. (default 80))
  1313. (host guix-publish-configuration-host ;string
  1314. (default "localhost"))
  1315. (compression-level guix-publish-configuration-compression-level ;integer
  1316. (default 3))
  1317. (nar-path guix-publish-configuration-nar-path ;string
  1318. (default "nar"))
  1319. (cache guix-publish-configuration-cache ;#f | string
  1320. (default #f))
  1321. (workers guix-publish-configuration-workers ;#f | integer
  1322. (default #f))
  1323. (ttl guix-publish-configuration-ttl ;#f | integer
  1324. (default #f)))
  1325. (define guix-publish-shepherd-service
  1326. (match-lambda
  1327. (($ <guix-publish-configuration> guix port host compression
  1328. nar-path cache workers ttl)
  1329. (list (shepherd-service
  1330. (provision '(guix-publish))
  1331. (requirement '(guix-daemon))
  1332. (start #~(make-forkexec-constructor
  1333. (list #$(file-append guix "/bin/guix")
  1334. "publish" "-u" "guix-publish"
  1335. "-p" #$(number->string port)
  1336. "-C" #$(number->string compression)
  1337. (string-append "--nar-path=" #$nar-path)
  1338. (string-append "--listen=" #$host)
  1339. #$@(if workers
  1340. #~((string-append "--workers="
  1341. #$(number->string
  1342. workers)))
  1343. #~())
  1344. #$@(if ttl
  1345. #~((string-append "--ttl="
  1346. #$(number->string ttl)
  1347. "s"))
  1348. #~())
  1349. #$@(if cache
  1350. #~((string-append "--cache=" #$cache))
  1351. #~()))
  1352. ;; Make sure we run in a UTF-8 locale so we can produce
  1353. ;; nars for packages that contain UTF-8 file names such
  1354. ;; as 'nss-certs'. See <https://bugs.gnu.org/26948>.
  1355. #:environment-variables
  1356. (list (string-append "GUIX_LOCPATH="
  1357. #$glibc-utf8-locales "/lib/locale")
  1358. "LC_ALL=en_US.utf8")))
  1359. (stop #~(make-kill-destructor)))))))
  1360. (define %guix-publish-accounts
  1361. (list (user-group (name "guix-publish") (system? #t))
  1362. (user-account
  1363. (name "guix-publish")
  1364. (group "guix-publish")
  1365. (system? #t)
  1366. (comment "guix publish user")
  1367. (home-directory "/var/empty")
  1368. (shell (file-append shadow "/sbin/nologin")))))
  1369. (define (guix-publish-activation config)
  1370. (let ((cache (guix-publish-configuration-cache config)))
  1371. (if cache
  1372. (with-imported-modules '((guix build utils))
  1373. #~(begin
  1374. (use-modules (guix build utils))
  1375. (mkdir-p #$cache)
  1376. (let* ((pw (getpw "guix-publish"))
  1377. (uid (passwd:uid pw))
  1378. (gid (passwd:gid pw)))
  1379. (chown #$cache uid gid))))
  1380. #t)))
  1381. (define guix-publish-service-type
  1382. (service-type (name 'guix-publish)
  1383. (extensions
  1384. (list (service-extension shepherd-root-service-type
  1385. guix-publish-shepherd-service)
  1386. (service-extension account-service-type
  1387. (const %guix-publish-accounts))
  1388. (service-extension activation-service-type
  1389. guix-publish-activation)))
  1390. (default-value (guix-publish-configuration))
  1391. (description
  1392. "Add a Shepherd service running @command{guix publish}, a
  1393. command that allows you to share pre-built binaries with others over HTTP.")))
  1394. (define* (guix-publish-service #:key (guix guix) (port 80) (host "localhost"))
  1395. "Return a service that runs @command{guix publish} listening on @var{host}
  1396. and @var{port} (@pxref{Invoking guix publish}).
  1397. This assumes that @file{/etc/guix} already contains a signing key pair as
  1398. created by @command{guix archive --generate-key} (@pxref{Invoking guix
  1399. archive}). If that is not the case, the service will fail to start."
  1400. ;; Deprecated.
  1401. (service guix-publish-service-type
  1402. (guix-publish-configuration (guix guix) (port port) (host host))))
  1403. ;;;
  1404. ;;; Udev.
  1405. ;;;
  1406. (define-record-type* <udev-configuration>
  1407. udev-configuration make-udev-configuration
  1408. udev-configuration?
  1409. (udev udev-configuration-udev ;<package>
  1410. (default udev))
  1411. (rules udev-configuration-rules ;list of <package>
  1412. (default '())))
  1413. (define (udev-rules-union packages)
  1414. "Return the union of the @code{lib/udev/rules.d} directories found in each
  1415. item of @var{packages}."
  1416. (define build
  1417. (with-imported-modules '((guix build union)
  1418. (guix build utils))
  1419. #~(begin
  1420. (use-modules (guix build union)
  1421. (guix build utils)
  1422. (srfi srfi-1)
  1423. (srfi srfi-26))
  1424. (define %standard-locations
  1425. '("/lib/udev/rules.d" "/libexec/udev/rules.d"))
  1426. (define (rules-sub-directory directory)
  1427. ;; Return the sub-directory of DIRECTORY containing udev rules, or
  1428. ;; #f if none was found.
  1429. (find directory-exists?
  1430. (map (cut string-append directory <>) %standard-locations)))
  1431. (mkdir-p (string-append #$output "/lib/udev"))
  1432. (union-build (string-append #$output "/lib/udev/rules.d")
  1433. (filter-map rules-sub-directory '#$packages)))))
  1434. (computed-file "udev-rules" build))
  1435. (define (udev-rule file-name contents)
  1436. "Return a directory with a udev rule file FILE-NAME containing CONTENTS."
  1437. (computed-file file-name
  1438. (with-imported-modules '((guix build utils))
  1439. #~(begin
  1440. (use-modules (guix build utils))
  1441. (define rules.d
  1442. (string-append #$output "/lib/udev/rules.d"))
  1443. (mkdir-p rules.d)
  1444. (call-with-output-file
  1445. (string-append rules.d "/" #$file-name)
  1446. (lambda (port)
  1447. (display #$contents port)))))))
  1448. (define kvm-udev-rule
  1449. ;; Return a directory with a udev rule that changes the group of /dev/kvm to
  1450. ;; "kvm" and makes it #o660. Apparently QEMU-KVM used to ship this rule,
  1451. ;; but now we have to add it by ourselves.
  1452. ;; Build users are part of the "kvm" group, so we can fearlessly make
  1453. ;; /dev/kvm 660 (see <http://bugs.gnu.org/18994>, for background.)
  1454. (udev-rule "90-kvm.rules"
  1455. "KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0660\"\n"))
  1456. (define udev-shepherd-service
  1457. ;; Return a <shepherd-service> for UDEV with RULES.
  1458. (match-lambda
  1459. (($ <udev-configuration> udev rules)
  1460. (let* ((rules (udev-rules-union (cons* udev kvm-udev-rule rules)))
  1461. (udev.conf (computed-file "udev.conf"
  1462. #~(call-with-output-file #$output
  1463. (lambda (port)
  1464. (format port
  1465. "udev_rules=\"~a/lib/udev/rules.d\"\n"
  1466. #$rules))))))
  1467. (list
  1468. (shepherd-service
  1469. (provision '(udev))
  1470. ;; Udev needs /dev to be a 'devtmpfs' mount so that new device nodes can
  1471. ;; be added: see
  1472. ;; <http://www.linuxfromscratch.org/lfs/view/development/chapter07/udev.html>.
  1473. (requirement '(root-file-system))
  1474. (documentation "Populate the /dev directory, dynamically.")
  1475. (start #~(lambda ()
  1476. (define find
  1477. (@ (srfi srfi-1) find))
  1478. (define udevd
  1479. ;; Choose the right 'udevd'.
  1480. (find file-exists?
  1481. (map (lambda (suffix)
  1482. (string-append #$udev suffix))
  1483. '("/libexec/udev/udevd" ;udev
  1484. "/sbin/udevd")))) ;eudev
  1485. (define (wait-for-udevd)
  1486. ;; Wait until someone's listening on udevd's control
  1487. ;; socket.
  1488. (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
  1489. (let try ()
  1490. (catch 'system-error
  1491. (lambda ()
  1492. (connect sock PF_UNIX "/run/udev/control")
  1493. (close-port sock))
  1494. (lambda args
  1495. (format #t "waiting for udevd...~%")
  1496. (usleep 500000)
  1497. (try))))))
  1498. ;; Allow udev to find the modules.
  1499. (setenv "LINUX_MODULE_DIRECTORY"
  1500. "/run/booted-system/kernel/lib/modules")
  1501. ;; The first one is for udev, the second one for eudev.
  1502. (setenv "UDEV_CONFIG_FILE" #$udev.conf)
  1503. (setenv "EUDEV_RULES_DIRECTORY"
  1504. #$(file-append rules "/lib/udev/rules.d"))
  1505. (let ((pid (primitive-fork)))
  1506. (case pid
  1507. ((0)
  1508. (exec-command (list udevd)))
  1509. (else
  1510. ;; Wait until udevd is up and running. This
  1511. ;; appears to be needed so that the events
  1512. ;; triggered below are actually handled.
  1513. (wait-for-udevd)
  1514. ;; Trigger device node creation.
  1515. (system* #$(file-append udev "/bin/udevadm")
  1516. "trigger" "--action=add")
  1517. ;; Wait for things to settle down.
  1518. (system* #$(file-append udev "/bin/udevadm")
  1519. "settle")
  1520. pid)))))
  1521. (stop #~(make-kill-destructor))
  1522. ;; When halting the system, 'udev' is actually killed by
  1523. ;; 'user-processes', i.e., before its own 'stop' method was called.
  1524. ;; Thus, make sure it is not respawned.
  1525. (respawn? #f)))))))
  1526. (define udev-service-type
  1527. (service-type (name 'udev)
  1528. (extensions
  1529. (list (service-extension shepherd-root-service-type
  1530. udev-shepherd-service)))
  1531. (compose concatenate) ;concatenate the list of rules
  1532. (extend (lambda (config rules)
  1533. (match config
  1534. (($ <udev-configuration> udev initial-rules)
  1535. (udev-configuration
  1536. (udev udev)
  1537. (rules (append initial-rules rules)))))))
  1538. (description
  1539. "Run @command{udev}, which populates the @file{/dev}
  1540. directory dynamically. Get extra rules from the packages listed in the
  1541. @code{rules} field of its value, @code{udev-configuration} object.")))
  1542. (define* (udev-service #:key (udev eudev) (rules '()))
  1543. "Run @var{udev}, which populates the @file{/dev} directory dynamically. Get
  1544. extra rules from the packages listed in @var{rules}."
  1545. (service udev-service-type
  1546. (udev-configuration (udev udev) (rules rules))))
  1547. (define swap-service-type
  1548. (shepherd-service-type
  1549. 'swap
  1550. (lambda (device)
  1551. (define requirement
  1552. (if (string-prefix? "/dev/mapper/" device)
  1553. (list (symbol-append 'device-mapping-
  1554. (string->symbol (basename device))))
  1555. '()))
  1556. (shepherd-service
  1557. (provision (list (symbol-append 'swap- (string->symbol device))))
  1558. (requirement `(udev ,@requirement))
  1559. (documentation "Enable the given swap device.")
  1560. (start #~(lambda ()
  1561. (restart-on-EINTR (swapon #$device))
  1562. #t))
  1563. (stop #~(lambda _
  1564. (restart-on-EINTR (swapoff #$device))
  1565. #f))
  1566. (respawn? #f)))))
  1567. (define (swap-service device)
  1568. "Return a service that uses @var{device} as a swap device."
  1569. (service swap-service-type device))
  1570. (define-record-type* <gpm-configuration>
  1571. gpm-configuration make-gpm-configuration gpm-configuration?
  1572. (gpm gpm-configuration-gpm) ;package
  1573. (options gpm-configuration-options)) ;list of strings
  1574. (define gpm-shepherd-service
  1575. (match-lambda
  1576. (($ <gpm-configuration> gpm options)
  1577. (list (shepherd-service
  1578. (requirement '(udev))
  1579. (provision '(gpm))
  1580. (start #~(lambda ()
  1581. ;; 'gpm' runs in the background and sets a PID file.
  1582. ;; Note that it requires running as "root".
  1583. (false-if-exception (delete-file "/var/run/gpm.pid"))
  1584. (fork+exec-command (list #$(file-append gpm "/sbin/gpm")
  1585. #$@options))
  1586. ;; Wait for the PID file to appear; declare failure if
  1587. ;; it doesn't show up.
  1588. (let loop ((i 3))
  1589. (or (file-exists? "/var/run/gpm.pid")
  1590. (if (zero? i)
  1591. #f
  1592. (begin
  1593. (sleep 1)
  1594. (loop (1- i))))))))
  1595. (stop #~(lambda (_)
  1596. ;; Return #f if successfully stopped.
  1597. (not (zero? (system* #$(file-append gpm "/sbin/gpm")
  1598. "-k"))))))))))
  1599. (define gpm-service-type
  1600. (service-type (name 'gpm)
  1601. (extensions
  1602. (list (service-extension shepherd-root-service-type
  1603. gpm-shepherd-service)))
  1604. (description
  1605. "Run GPM, the general-purpose mouse daemon, with the given
  1606. command-line options. GPM allows users to use the mouse in the console,
  1607. notably to select, copy, and paste text. The default options use the
  1608. @code{ps2} protocol, which works for both USB and PS/2 mice.")))
  1609. (define* (gpm-service #:key (gpm gpm)
  1610. (options '("-m" "/dev/input/mice" "-t" "ps2")))
  1611. "Run @var{gpm}, the general-purpose mouse daemon, with the given
  1612. command-line @var{options}. GPM allows users to use the mouse in the console,
  1613. notably to select, copy, and paste text. The default value of @var{options}
  1614. uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
  1615. This service is not part of @var{%base-services}."
  1616. ;; To test in QEMU, use "-usbdevice mouse" and then, in the monitor, use
  1617. ;; "info mice" and "mouse_set X" to use the right mouse.
  1618. (service gpm-service-type
  1619. (gpm-configuration (gpm gpm) (options options))))
  1620. (define-record-type* <kmscon-configuration>
  1621. kmscon-configuration make-kmscon-configuration
  1622. kmscon-configuration?
  1623. (kmscon kmscon-configuration-kmscon
  1624. (default kmscon))
  1625. (virtual-terminal kmscon-configuration-virtual-terminal)
  1626. (login-program kmscon-configuration-login-program
  1627. (default (file-append shadow "/bin/login")))
  1628. (login-arguments kmscon-configuration-login-arguments
  1629. (default '("-p")))
  1630. (hardware-acceleration? kmscon-configuration-hardware-acceleration?
  1631. (default #f))) ; #t causes failure
  1632. (define kmscon-service-type
  1633. (shepherd-service-type
  1634. 'kmscon
  1635. (lambda (config)
  1636. (let ((kmscon (kmscon-configuration-kmscon config))
  1637. (virtual-terminal (kmscon-configuration-virtual-terminal config))
  1638. (login-program (kmscon-configuration-login-program config))
  1639. (login-arguments (kmscon-configuration-login-arguments config))
  1640. (hardware-acceleration? (kmscon-configuration-hardware-acceleration? config)))
  1641. (define kmscon-command
  1642. #~(list
  1643. #$(file-append kmscon "/bin/kmscon") "--login"
  1644. "--vt" #$virtual-terminal
  1645. #$@(if hardware-acceleration? '("--hwaccel") '())
  1646. "--" #$login-program #$@login-arguments))
  1647. (shepherd-service
  1648. (documentation "kmscon virtual terminal")
  1649. (requirement '(user-processes udev dbus-system))
  1650. (provision (list (symbol-append 'term- (string->symbol virtual-terminal))))
  1651. (start #~(make-forkexec-constructor #$kmscon-command))
  1652. (stop #~(make-kill-destructor)))))))
  1653. (define %base-services
  1654. ;; Convenience variable holding the basic services.
  1655. (list (login-service)
  1656. (service console-font-service-type
  1657. (map (lambda (tty)
  1658. (cons tty %default-console-font))
  1659. '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
  1660. (mingetty-service (mingetty-configuration
  1661. (tty "tty1")))
  1662. (mingetty-service (mingetty-configuration
  1663. (tty "tty2")))
  1664. (mingetty-service (mingetty-configuration
  1665. (tty "tty3")))
  1666. (mingetty-service (mingetty-configuration
  1667. (tty "tty4")))
  1668. (mingetty-service (mingetty-configuration
  1669. (tty "tty5")))
  1670. (mingetty-service (mingetty-configuration
  1671. (tty "tty6")))
  1672. (service static-networking-service-type
  1673. (list (static-networking (interface "lo")
  1674. (ip "127.0.0.1")
  1675. (provision '(loopback)))))
  1676. (syslog-service)
  1677. (urandom-seed-service)
  1678. (guix-service)
  1679. (nscd-service)
  1680. ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is
  1681. ;; used, so enable them by default. The FUSE and ALSA rules are
  1682. ;; less critical, but handy.
  1683. (udev-service #:rules (list lvm2 fuse alsa-utils crda))
  1684. (service special-files-service-type
  1685. `(("/bin/sh" ,(file-append (canonical-package bash)
  1686. "/bin/sh"))))))
  1687. ;;; base.scm ends here