base.scm 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430
  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, 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. ;;; Copyright © 2018 Mathieu Othacehe <m.othacehe@gmail.com>
  10. ;;; Copyright © 2019 Efraim Flashner <efraim@flashner.co.il>
  11. ;;; Copyright © 2019 Tobias Geerinckx-Rice <me@tobias.gr>
  12. ;;; Copyright © 2019 John Soo <jsoo1@asu.edu>
  13. ;;; Copyright © 2019 Jan (janneke) Nieuwenhuizen <janneke@gnu.org>
  14. ;;; Copyright © 2020 Florian Pelz <pelzflorian@pelzflorian.de>
  15. ;;; Copyright © 2020 Brice Waegeneire <brice@waegenei.re>
  16. ;;;
  17. ;;; This file is part of GNU Guix.
  18. ;;;
  19. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  20. ;;; under the terms of the GNU General Public License as published by
  21. ;;; the Free Software Foundation; either version 3 of the License, or (at
  22. ;;; your option) any later version.
  23. ;;;
  24. ;;; GNU Guix is distributed in the hope that it will be useful, but
  25. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  26. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  27. ;;; GNU General Public License for more details.
  28. ;;;
  29. ;;; You should have received a copy of the GNU General Public License
  30. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  31. (define-module (gnu services base)
  32. #:use-module (guix store)
  33. #:use-module (guix deprecation)
  34. #:use-module (gnu services)
  35. #:use-module (gnu services admin)
  36. #:use-module (gnu services shepherd)
  37. #:use-module (gnu system pam)
  38. #:use-module (gnu system shadow) ; 'user-account', etc.
  39. #:use-module (gnu system uuid)
  40. #:use-module (gnu system file-systems) ; 'file-system', etc.
  41. #:use-module (gnu system mapped-devices)
  42. #:use-module ((gnu system linux-initrd)
  43. #:select (file-system-packages))
  44. #:use-module (gnu packages admin)
  45. #:use-module ((gnu packages linux)
  46. #:select (alsa-utils crda eudev e2fsprogs fuse gpm kbd lvm2 rng-tools))
  47. #:use-module (gnu packages bash)
  48. #:use-module ((gnu packages base)
  49. #:select (coreutils glibc glibc-utf8-locales))
  50. #:use-module (gnu packages package-management)
  51. #:use-module ((gnu packages gnupg) #:select (guile-gcrypt))
  52. #:use-module (gnu packages linux)
  53. #:use-module (gnu packages terminals)
  54. #:use-module ((gnu build file-systems)
  55. #:select (mount-flags->bit-mask))
  56. #:use-module (guix gexp)
  57. #:use-module (guix records)
  58. #:use-module (guix modules)
  59. #:use-module ((guix self) #:select (make-config.scm))
  60. #:use-module (srfi srfi-1)
  61. #:use-module (srfi srfi-26)
  62. #:use-module (ice-9 match)
  63. #:use-module (ice-9 format)
  64. #:re-export (user-processes-service-type) ;backwards compatibility
  65. #:export (fstab-service-type
  66. root-file-system-service
  67. file-system-service-type
  68. swap-service
  69. host-name-service
  70. console-keymap-service
  71. %default-console-font
  72. console-font-service-type
  73. console-font-service
  74. virtual-terminal-service-type
  75. static-networking
  76. static-networking?
  77. static-networking-interface
  78. static-networking-ip
  79. static-networking-netmask
  80. static-networking-gateway
  81. static-networking-requirement
  82. static-networking-service
  83. static-networking-service-type
  84. udev-configuration
  85. udev-configuration?
  86. udev-configuration-rules
  87. udev-service-type
  88. udev-service
  89. udev-rule
  90. file->udev-rule
  91. udev-rules-service
  92. login-configuration
  93. login-configuration?
  94. login-service-type
  95. login-service
  96. agetty-configuration
  97. agetty-configuration?
  98. agetty-service
  99. agetty-service-type
  100. mingetty-configuration
  101. mingetty-configuration?
  102. mingetty-service
  103. mingetty-service-type
  104. %nscd-default-caches
  105. %nscd-default-configuration
  106. nscd-configuration
  107. nscd-configuration?
  108. nscd-cache
  109. nscd-cache?
  110. nscd-service-type
  111. nscd-service
  112. syslog-configuration
  113. syslog-configuration?
  114. syslog-service
  115. syslog-service-type
  116. %default-syslog.conf
  117. %default-authorized-guix-keys
  118. guix-configuration
  119. guix-configuration?
  120. guix-configuration-guix
  121. guix-configuration-build-group
  122. guix-configuration-build-accounts
  123. guix-configuration-authorize-key?
  124. guix-configuration-authorized-keys
  125. guix-configuration-use-substitutes?
  126. guix-configuration-substitute-urls
  127. guix-configuration-extra-options
  128. guix-configuration-log-file
  129. guix-service
  130. guix-service-type
  131. guix-publish-configuration
  132. guix-publish-configuration?
  133. guix-publish-configuration-guix
  134. guix-publish-configuration-port
  135. guix-publish-configuration-host
  136. guix-publish-configuration-compression
  137. guix-publish-configuration-compression-level ;deprecated
  138. guix-publish-configuration-nar-path
  139. guix-publish-configuration-cache
  140. guix-publish-configuration-ttl
  141. guix-publish-service
  142. guix-publish-service-type
  143. gpm-configuration
  144. gpm-configuration?
  145. gpm-service-type
  146. gpm-service
  147. urandom-seed-service-type
  148. urandom-seed-service
  149. rngd-configuration
  150. rngd-configuration?
  151. rngd-service-type
  152. rngd-service
  153. kmscon-configuration
  154. kmscon-configuration?
  155. kmscon-service-type
  156. pam-limits-service-type
  157. pam-limits-service
  158. references-file
  159. %base-services))
  160. ;;; Commentary:
  161. ;;;
  162. ;;; Base system services---i.e., services that 99% of the users will want to
  163. ;;; use.
  164. ;;;
  165. ;;; Code:
  166. ;;;
  167. ;;; File systems.
  168. ;;;
  169. (define (file-system->fstab-entry file-system)
  170. "Return a @file{/etc/fstab} entry for @var{file-system}."
  171. (string-append (match (file-system-device file-system)
  172. ((? file-system-label? label)
  173. (string-append "LABEL="
  174. (file-system-label->string label)))
  175. ((? uuid? uuid)
  176. (string-append "UUID=" (uuid->string uuid)))
  177. ((? string? device)
  178. device))
  179. "\t"
  180. (file-system-mount-point file-system) "\t"
  181. (file-system-type file-system) "\t"
  182. (or (file-system-options file-system) "defaults") "\t"
  183. ;; XXX: Omit the 'fs_freq' and 'fs_passno' fields because we
  184. ;; don't have anything sensible to put in there.
  185. ))
  186. (define (file-systems->fstab file-systems)
  187. "Return a @file{/etc} entry for an @file{fstab} describing
  188. @var{file-systems}."
  189. `(("fstab" ,(plain-file "fstab"
  190. (string-append
  191. "\
  192. # This file was generated from your Guix configuration. Any changes
  193. # will be lost upon reboot or reconfiguration.\n\n"
  194. (string-join (map file-system->fstab-entry
  195. file-systems)
  196. "\n")
  197. "\n")))))
  198. (define fstab-service-type
  199. ;; The /etc/fstab service.
  200. (service-type (name 'fstab)
  201. (extensions
  202. (list (service-extension etc-service-type
  203. file-systems->fstab)))
  204. (compose concatenate)
  205. (extend append)
  206. (description
  207. "Populate the @file{/etc/fstab} based on the given file
  208. system objects.")))
  209. (define %root-file-system-shepherd-service
  210. (shepherd-service
  211. (documentation "Take care of the root file system.")
  212. (provision '(root-file-system))
  213. (start #~(const #t))
  214. (stop #~(lambda _
  215. ;; Return #f if successfully stopped.
  216. (sync)
  217. (call-with-blocked-asyncs
  218. (lambda ()
  219. (let ((null (%make-void-port "w")))
  220. ;; Close 'shepherd.log'.
  221. (display "closing log\n")
  222. ((@ (shepherd comm) stop-logging))
  223. ;; Redirect the default output ports..
  224. (set-current-output-port null)
  225. (set-current-error-port null)
  226. ;; Close /dev/console.
  227. (for-each close-fdes '(0 1 2))
  228. ;; At this point, there are no open files left, so the
  229. ;; root file system can be re-mounted read-only.
  230. (mount #f "/" #f
  231. (logior MS_REMOUNT MS_RDONLY)
  232. #:update-mtab? #f)
  233. #f)))))
  234. (respawn? #f)))
  235. (define root-file-system-service-type
  236. (shepherd-service-type 'root-file-system
  237. (const %root-file-system-shepherd-service)))
  238. (define (root-file-system-service)
  239. "Return a service whose sole purpose is to re-mount read-only the root file
  240. system upon shutdown (aka. cleanly \"umounting\" root.)
  241. This service must be the root of the service dependency graph so that its
  242. 'stop' action is invoked when shepherd is the only process left."
  243. (service root-file-system-service-type #f))
  244. (define (file-system->shepherd-service-name file-system)
  245. "Return the symbol that denotes the service mounting and unmounting
  246. FILE-SYSTEM."
  247. (symbol-append 'file-system-
  248. (string->symbol (file-system-mount-point file-system))))
  249. (define (mapped-device->shepherd-service-name md)
  250. "Return the symbol that denotes the shepherd service of MD, a <mapped-device>."
  251. (symbol-append 'device-mapping-
  252. (string->symbol (mapped-device-target md))))
  253. (define dependency->shepherd-service-name
  254. (match-lambda
  255. ((? mapped-device? md)
  256. (mapped-device->shepherd-service-name md))
  257. ((? file-system? fs)
  258. (file-system->shepherd-service-name fs))))
  259. (define (file-system-shepherd-service file-system)
  260. "Return the shepherd service for @var{file-system}, or @code{#f} if
  261. @var{file-system} is not auto-mounted upon boot."
  262. (let ((target (file-system-mount-point file-system))
  263. (create? (file-system-create-mount-point? file-system))
  264. (dependencies (file-system-dependencies file-system))
  265. (packages (file-system-packages (list file-system))))
  266. (and (file-system-mount? file-system)
  267. (with-imported-modules (source-module-closure
  268. '((gnu build file-systems)))
  269. (shepherd-service
  270. (provision (list (file-system->shepherd-service-name file-system)))
  271. (requirement `(root-file-system udev
  272. ,@(map dependency->shepherd-service-name dependencies)))
  273. (documentation "Check, mount, and unmount the given file system.")
  274. (start #~(lambda args
  275. #$(if create?
  276. #~(mkdir-p #$target)
  277. #t)
  278. (let (($PATH (getenv "PATH")))
  279. ;; Make sure fsck.ext2 & co. can be found.
  280. (dynamic-wind
  281. (lambda ()
  282. ;; Don’t display the PATH settings.
  283. (with-output-to-port (%make-void-port "w")
  284. (lambda ()
  285. (set-path-environment-variable "PATH"
  286. '("bin" "sbin")
  287. '#$packages))))
  288. (lambda ()
  289. (mount-file-system
  290. (spec->file-system
  291. '#$(file-system->spec file-system))
  292. #:root "/"))
  293. (lambda ()
  294. (setenv "PATH" $PATH)))
  295. #t)))
  296. (stop #~(lambda args
  297. ;; Normally there are no processes left at this point, so
  298. ;; TARGET can be safely unmounted.
  299. ;; Make sure PID 1 doesn't keep TARGET busy.
  300. (chdir "/")
  301. (umount #$target)
  302. #f))
  303. ;; We need additional modules.
  304. (modules `(((gnu build file-systems)
  305. #:select (mount-file-system))
  306. (gnu system file-systems)
  307. ,@%default-modules)))))))
  308. (define (file-system-shepherd-services file-systems)
  309. "Return the list of Shepherd services for FILE-SYSTEMS."
  310. (let* ((file-systems (filter file-system-mount? file-systems)))
  311. (define sink
  312. (shepherd-service
  313. (provision '(file-systems))
  314. (requirement (cons* 'root-file-system 'user-file-systems
  315. (map file-system->shepherd-service-name
  316. file-systems)))
  317. (documentation "Target for all the initially-mounted file systems")
  318. (start #~(const #t))
  319. (stop #~(const #f))))
  320. (define known-mount-points
  321. (map file-system-mount-point file-systems))
  322. (define user-unmount
  323. (shepherd-service
  324. (documentation "Unmount manually-mounted file systems.")
  325. (provision '(user-file-systems))
  326. (start #~(const #t))
  327. (stop #~(lambda args
  328. (define (known? mount-point)
  329. (member mount-point
  330. (cons* "/proc" "/sys" '#$known-mount-points)))
  331. ;; Make sure we don't keep the user's mount points busy.
  332. (chdir "/")
  333. (for-each (lambda (mount-point)
  334. (format #t "unmounting '~a'...~%" mount-point)
  335. (catch 'system-error
  336. (lambda ()
  337. (umount mount-point))
  338. (lambda args
  339. (let ((errno (system-error-errno args)))
  340. (format #t "failed to unmount '~a': ~a~%"
  341. mount-point (strerror errno))))))
  342. (filter (negate known?) (mount-points)))
  343. #f))))
  344. (cons* sink user-unmount
  345. (map file-system-shepherd-service file-systems))))
  346. (define (file-system-fstab-entries file-systems)
  347. "Return the subset of @var{file-systems} that should have an entry in
  348. @file{/etc/fstab}."
  349. ;; /etc/fstab is about telling fsck(8), mount(8), and umount(8) about
  350. ;; relevant file systems they'll have to deal with. That excludes "pseudo"
  351. ;; file systems.
  352. ;;
  353. ;; In particular, things like GIO (part of GLib) use it to determine the set
  354. ;; of mounts, which is then used by graphical file managers and desktop
  355. ;; environments to display "volume" icons. Thus, we really need to exclude
  356. ;; those pseudo file systems from the list.
  357. (remove (lambda (file-system)
  358. (or (member (file-system-type file-system)
  359. %pseudo-file-system-types)
  360. (memq 'bind-mount (file-system-flags file-system))))
  361. file-systems))
  362. (define file-system-service-type
  363. (service-type (name 'file-systems)
  364. (extensions
  365. (list (service-extension shepherd-root-service-type
  366. file-system-shepherd-services)
  367. (service-extension fstab-service-type
  368. file-system-fstab-entries)
  369. ;; Have 'user-processes' depend on 'file-systems'.
  370. (service-extension user-processes-service-type
  371. (const '(file-systems)))))
  372. (compose concatenate)
  373. (extend append)
  374. (description
  375. "Provide Shepherd services to mount and unmount the given
  376. file systems, as well as corresponding @file{/etc/fstab} entries.")))
  377. ;;;
  378. ;;; Preserve entropy to seed /dev/urandom on boot.
  379. ;;;
  380. (define %random-seed-file
  381. "/var/lib/random-seed")
  382. (define (urandom-seed-shepherd-service _)
  383. "Return a shepherd service for the /dev/urandom seed."
  384. (list (shepherd-service
  385. (documentation "Preserve entropy across reboots for /dev/urandom.")
  386. (provision '(urandom-seed))
  387. ;; Depend on udev so that /dev/hwrng is available.
  388. (requirement '(file-systems udev))
  389. (start #~(lambda _
  390. ;; On boot, write random seed into /dev/urandom.
  391. (when (file-exists? #$%random-seed-file)
  392. (call-with-input-file #$%random-seed-file
  393. (lambda (seed)
  394. (call-with-output-file "/dev/urandom"
  395. (lambda (urandom)
  396. (dump-port seed urandom)
  397. ;; Writing SEED to URANDOM isn't enough: we must
  398. ;; also tell the kernel to account for these
  399. ;; extra bits of entropy.
  400. (let ((bits (* 8 (stat:size (stat seed)))))
  401. (add-to-entropy-count urandom bits)))))))
  402. ;; Try writing from /dev/hwrng into /dev/urandom.
  403. ;; It seems that the file /dev/hwrng always exists, even
  404. ;; when there is no hardware random number generator
  405. ;; available. So, we handle a failed read or any other error
  406. ;; reported by the operating system.
  407. (let ((buf (catch 'system-error
  408. (lambda ()
  409. (call-with-input-file "/dev/hwrng"
  410. (lambda (hwrng)
  411. (get-bytevector-n hwrng 512))))
  412. ;; Silence is golden...
  413. (const #f))))
  414. (when buf
  415. (call-with-output-file "/dev/urandom"
  416. (lambda (urandom)
  417. (put-bytevector urandom buf)
  418. (let ((bits (* 8 (bytevector-length buf))))
  419. (add-to-entropy-count urandom bits))))))
  420. ;; Immediately refresh the seed in case the system doesn't
  421. ;; shut down cleanly.
  422. (call-with-input-file "/dev/urandom"
  423. (lambda (urandom)
  424. (let ((previous-umask (umask #o077))
  425. (buf (make-bytevector 512)))
  426. (mkdir-p (dirname #$%random-seed-file))
  427. (get-bytevector-n! urandom buf 0 512)
  428. (call-with-output-file #$%random-seed-file
  429. (lambda (seed)
  430. (put-bytevector seed buf)))
  431. (umask previous-umask))))
  432. #t))
  433. (stop #~(lambda _
  434. ;; During shutdown, write from /dev/urandom into random seed.
  435. (let ((buf (make-bytevector 512)))
  436. (call-with-input-file "/dev/urandom"
  437. (lambda (urandom)
  438. (let ((previous-umask (umask #o077)))
  439. (get-bytevector-n! urandom buf 0 512)
  440. (mkdir-p (dirname #$%random-seed-file))
  441. (call-with-output-file #$%random-seed-file
  442. (lambda (seed)
  443. (put-bytevector seed buf)))
  444. (umask previous-umask))
  445. #t)))))
  446. (modules `((rnrs bytevectors)
  447. (rnrs io ports)
  448. ,@%default-modules)))))
  449. (define urandom-seed-service-type
  450. (service-type (name 'urandom-seed)
  451. (extensions
  452. (list (service-extension shepherd-root-service-type
  453. urandom-seed-shepherd-service)
  454. ;; Have 'user-processes' depend on 'urandom-seed'.
  455. ;; This ensures that user processes and daemons don't
  456. ;; start until we have seeded the PRNG.
  457. (service-extension user-processes-service-type
  458. (const '(urandom-seed)))))
  459. (default-value #f)
  460. (description
  461. "Seed the @file{/dev/urandom} pseudo-random number
  462. generator (RNG) with the value recorded when the system was last shut
  463. down.")))
  464. (define-deprecated (urandom-seed-service)
  465. urandom-seed-service-type
  466. (service urandom-seed-service-type))
  467. ;;;
  468. ;;; Add hardware random number generator to entropy pool.
  469. ;;;
  470. (define-record-type* <rngd-configuration>
  471. rngd-configuration make-rngd-configuration
  472. rngd-configuration?
  473. (rng-tools rngd-configuration-rng-tools) ;package
  474. (device rngd-configuration-device)) ;string
  475. (define rngd-service-type
  476. (shepherd-service-type
  477. 'rngd
  478. (lambda (config)
  479. (define rng-tools (rngd-configuration-rng-tools config))
  480. (define device (rngd-configuration-device config))
  481. (define rngd-command
  482. (list (file-append rng-tools "/sbin/rngd")
  483. "-f" "-r" device))
  484. (shepherd-service
  485. (documentation "Add TRNG to entropy pool.")
  486. (requirement '(udev))
  487. (provision '(trng))
  488. (start #~(make-forkexec-constructor '#$rngd-command))
  489. (stop #~(make-kill-destructor))))))
  490. (define* (rngd-service #:key
  491. (rng-tools rng-tools)
  492. (device "/dev/hwrng"))
  493. "Return a service that runs the @command{rngd} program from @var{rng-tools}
  494. to add @var{device} to the kernel's entropy pool. The service will fail if
  495. @var{device} does not exist."
  496. (service rngd-service-type
  497. (rngd-configuration
  498. (rng-tools rng-tools)
  499. (device device))))
  500. ;;;
  501. ;;; Console & co.
  502. ;;;
  503. (define host-name-service-type
  504. (shepherd-service-type
  505. 'host-name
  506. (lambda (name)
  507. (shepherd-service
  508. (documentation "Initialize the machine's host name.")
  509. (provision '(host-name))
  510. (start #~(lambda _
  511. (sethostname #$name)))
  512. (one-shot? #t)))))
  513. (define (host-name-service name)
  514. "Return a service that sets the host name to @var{name}."
  515. (service host-name-service-type name))
  516. (define virtual-terminal-service-type
  517. ;; Ensure that virtual terminals run in UTF-8 mode. This is the case by
  518. ;; default with recent Linux kernels, but this service allows us to ensure
  519. ;; this. This service must start before any 'term-' service so that newly
  520. ;; created terminals inherit this property. See
  521. ;; <https://bugs.gnu.org/30505> for a discussion.
  522. (shepherd-service-type
  523. 'virtual-terminal
  524. (lambda (utf8?)
  525. (let ((knob "/sys/module/vt/parameters/default_utf8"))
  526. (shepherd-service
  527. (documentation "Set virtual terminals in UTF-8 module.")
  528. (provision '(virtual-terminal))
  529. (requirement '(root-file-system))
  530. (start #~(lambda _
  531. ;; In containers /sys is read-only so don't insist on
  532. ;; writing to this file.
  533. (unless (= 1 (call-with-input-file #$knob read))
  534. (call-with-output-file #$knob
  535. (lambda (port)
  536. (display 1 port))))
  537. #t))
  538. (stop #~(const #f)))))
  539. #t)) ;default to UTF-8
  540. (define console-keymap-service-type
  541. (shepherd-service-type
  542. 'console-keymap
  543. (lambda (files)
  544. (shepherd-service
  545. (documentation (string-append "Load console keymap (loadkeys)."))
  546. (provision '(console-keymap))
  547. (start #~(lambda _
  548. (zero? (system* #$(file-append kbd "/bin/loadkeys")
  549. #$@files))))
  550. (respawn? #f)))))
  551. (define-deprecated (console-keymap-service #:rest files)
  552. #f
  553. "Return a service to load console keymaps from @var{files}."
  554. (service console-keymap-service-type files))
  555. (define %default-console-font
  556. ;; Note: 'LatGrkCyr-8x16' has the advantage of providing three common
  557. ;; scripts as well as glyphs for em dash, quotation marks, and other Unicode
  558. ;; codepoints notably found in the UTF-8 manual.
  559. "LatGrkCyr-8x16")
  560. (define (console-font-shepherd-services tty+font)
  561. "Return a list of Shepherd services for each pair in TTY+FONT."
  562. (map (match-lambda
  563. ((tty . font)
  564. (let ((device (string-append "/dev/" tty)))
  565. (shepherd-service
  566. (documentation "Load a Unicode console font.")
  567. (provision (list (symbol-append 'console-font-
  568. (string->symbol tty))))
  569. ;; Start after mingetty has been started on TTY, otherwise the settings
  570. ;; are ignored.
  571. (requirement (list (symbol-append 'term-
  572. (string->symbol tty))))
  573. (start #~(lambda _
  574. ;; It could be that mingetty is not fully ready yet,
  575. ;; which we check by calling 'ttyname'.
  576. (let loop ((i 10))
  577. (unless (or (zero? i)
  578. (call-with-input-file #$device
  579. (lambda (port)
  580. (false-if-exception (ttyname port)))))
  581. (usleep 500)
  582. (loop (- i 1))))
  583. ;; Assume the VT is already in UTF-8 mode, thanks to
  584. ;; the 'virtual-terminal' service.
  585. ;;
  586. ;; 'setfont' returns EX_OSERR (71) when an
  587. ;; KDFONTOP ioctl fails, for example. Like
  588. ;; systemd's vconsole support, let's not treat
  589. ;; this as an error.
  590. (case (status:exit-val
  591. (system* #$(file-append kbd "/bin/setfont")
  592. "-C" #$device #$font))
  593. ((0 71) #t)
  594. (else #f))))
  595. (stop #~(const #t))
  596. (respawn? #f)))))
  597. tty+font))
  598. (define console-font-service-type
  599. (service-type (name 'console-fonts)
  600. (extensions
  601. (list (service-extension shepherd-root-service-type
  602. console-font-shepherd-services)))
  603. (compose concatenate)
  604. (extend append)
  605. (description
  606. "Install the given fonts on the specified ttys (fonts are per
  607. virtual console on GNU/Linux). The value of this service is a list of
  608. tty/font pairs. The font can be the name of a font provided by the @code{kbd}
  609. package or any valid argument to @command{setfont}, as in this example:
  610. @example
  611. `((\"tty1\" . \"LatGrkCyr-8x16\")
  612. (\"tty2\" . ,(file-append
  613. font-tamzen
  614. \"/share/kbd/consolefonts/TamzenForPowerline10x20.psf\"))
  615. (\"tty3\" . ,(file-append
  616. font-terminus
  617. \"/share/consolefonts/ter-132n\"))) ; for HDPI
  618. @end example\n")))
  619. (define* (console-font-service tty #:optional (font "LatGrkCyr-8x16"))
  620. "This procedure is deprecated in favor of @code{console-font-service-type}.
  621. Return a service that sets up Unicode support in @var{tty} and loads
  622. @var{font} for that tty (fonts are per virtual console in Linux.)"
  623. (simple-service (symbol-append 'console-font- (string->symbol tty))
  624. console-font-service-type `((,tty . ,font))))
  625. (define %default-motd
  626. (plain-file "motd" "This is the GNU operating system, welcome!\n\n"))
  627. (define-record-type* <login-configuration>
  628. login-configuration make-login-configuration
  629. login-configuration?
  630. (motd login-configuration-motd ;file-like
  631. (default %default-motd))
  632. ;; Allow empty passwords by default so that first-time users can log in when
  633. ;; the 'root' account has just been created.
  634. (allow-empty-passwords? login-configuration-allow-empty-passwords?
  635. (default #t))) ;Boolean
  636. (define (login-pam-service config)
  637. "Return the list of PAM service needed for CONF."
  638. ;; Let 'login' be known to PAM.
  639. (list (unix-pam-service "login"
  640. #:login-uid? #t
  641. #:allow-empty-passwords?
  642. (login-configuration-allow-empty-passwords? config)
  643. #:motd
  644. (login-configuration-motd config))))
  645. (define login-service-type
  646. (service-type (name 'login)
  647. (extensions (list (service-extension pam-root-service-type
  648. login-pam-service)))
  649. (default-value (login-configuration))
  650. (description
  651. "Provide a console log-in service as specified by its
  652. configuration value, a @code{login-configuration} object.")))
  653. (define* (login-service #:optional (config (login-configuration)))
  654. "Return a service configure login according to @var{config}, which specifies
  655. the message of the day, among other things."
  656. (service login-service-type config))
  657. (define-record-type* <agetty-configuration>
  658. agetty-configuration make-agetty-configuration
  659. agetty-configuration?
  660. (agetty agetty-configuration-agetty ;<package>
  661. (default util-linux))
  662. (tty agetty-configuration-tty) ;string | #f
  663. (term agetty-term ;string | #f
  664. (default #f))
  665. (baud-rate agetty-baud-rate ;string | #f
  666. (default #f))
  667. (auto-login agetty-auto-login ;list of strings | #f
  668. (default #f))
  669. (login-program agetty-login-program ;gexp
  670. (default (file-append shadow "/bin/login")))
  671. (login-pause? agetty-login-pause? ;Boolean
  672. (default #f))
  673. (eight-bits? agetty-eight-bits? ;Boolean
  674. (default #f))
  675. (no-reset? agetty-no-reset? ;Boolean
  676. (default #f))
  677. (remote? agetty-remote? ;Boolean
  678. (default #f))
  679. (flow-control? agetty-flow-control? ;Boolean
  680. (default #f))
  681. (host agetty-host ;string | #f
  682. (default #f))
  683. (no-issue? agetty-no-issue? ;Boolean
  684. (default #f))
  685. (init-string agetty-init-string ;string | #f
  686. (default #f))
  687. (no-clear? agetty-no-clear? ;Boolean
  688. (default #f))
  689. (local-line agetty-local-line ;always | never | auto
  690. (default #f))
  691. (extract-baud? agetty-extract-baud? ;Boolean
  692. (default #f))
  693. (skip-login? agetty-skip-login? ;Boolean
  694. (default #f))
  695. (no-newline? agetty-no-newline? ;Boolean
  696. (default #f))
  697. (login-options agetty-login-options ;string | #f
  698. (default #f))
  699. (chroot agetty-chroot ;string | #f
  700. (default #f))
  701. (hangup? agetty-hangup? ;Boolean
  702. (default #f))
  703. (keep-baud? agetty-keep-baud? ;Boolean
  704. (default #f))
  705. (timeout agetty-timeout ;integer | #f
  706. (default #f))
  707. (detect-case? agetty-detect-case? ;Boolean
  708. (default #f))
  709. (wait-cr? agetty-wait-cr? ;Boolean
  710. (default #f))
  711. (no-hints? agetty-no-hints? ;Boolean
  712. (default #f))
  713. (no-hostname? agetty-no hostname? ;Boolean
  714. (default #f))
  715. (long-hostname? agetty-long-hostname? ;Boolean
  716. (default #f))
  717. (erase-characters agetty-erase-characters ;string | #f
  718. (default #f))
  719. (kill-characters agetty-kill-characters ;string | #f
  720. (default #f))
  721. (chdir agetty-chdir ;string | #f
  722. (default #f))
  723. (delay agetty-delay ;integer | #f
  724. (default #f))
  725. (nice agetty-nice ;integer | #f
  726. (default #f))
  727. ;; "Escape hatch" for passing arbitrary command-line arguments.
  728. (extra-options agetty-extra-options ;list of strings
  729. (default '()))
  730. ;;; XXX Unimplemented for now!
  731. ;;; (issue-file agetty-issue-file ;file-like
  732. ;;; (default #f))
  733. )
  734. (define (default-serial-port)
  735. "Return a gexp that determines a reasonable default serial port
  736. to use as the tty. This is primarily useful for headless systems."
  737. (with-imported-modules (source-module-closure
  738. '((gnu build linux-boot))) ;for 'find-long-options'
  739. #~(begin
  740. ;; console=device,options
  741. ;; device: can be tty0, ttyS0, lp0, ttyUSB0 (serial).
  742. ;; options: BBBBPNF. P n|o|e, N number of bits,
  743. ;; F flow control (r RTS)
  744. (let* ((not-comma (char-set-complement (char-set #\,)))
  745. (command (linux-command-line))
  746. (agetty-specs (find-long-options "agetty.tty" command))
  747. (console-specs (filter (lambda (spec)
  748. (and (string-prefix? "tty" spec)
  749. (not (or
  750. (string-prefix? "tty0" spec)
  751. (string-prefix? "tty1" spec)
  752. (string-prefix? "tty2" spec)
  753. (string-prefix? "tty3" spec)
  754. (string-prefix? "tty4" spec)
  755. (string-prefix? "tty5" spec)
  756. (string-prefix? "tty6" spec)
  757. (string-prefix? "tty7" spec)
  758. (string-prefix? "tty8" spec)
  759. (string-prefix? "tty9" spec)))))
  760. (find-long-options "console" command)))
  761. (specs (append agetty-specs console-specs)))
  762. (match specs
  763. (() #f)
  764. ((spec _ ...)
  765. ;; Extract device name from first spec.
  766. (match (string-tokenize spec not-comma)
  767. ((device-name _ ...)
  768. device-name))))))))
  769. (define agetty-shepherd-service
  770. (match-lambda
  771. (($ <agetty-configuration> agetty tty term baud-rate auto-login
  772. login-program login-pause? eight-bits? no-reset? remote? flow-control?
  773. host no-issue? init-string no-clear? local-line extract-baud?
  774. skip-login? no-newline? login-options chroot hangup? keep-baud? timeout
  775. detect-case? wait-cr? no-hints? no-hostname? long-hostname?
  776. erase-characters kill-characters chdir delay nice extra-options)
  777. (list
  778. (shepherd-service
  779. (documentation "Run agetty on a tty.")
  780. (provision (list (symbol-append 'term- (string->symbol (or tty "auto")))))
  781. ;; Since the login prompt shows the host name, wait for the 'host-name'
  782. ;; service to be done. Also wait for udev essentially so that the tty
  783. ;; text is not lost in the middle of kernel messages (see also
  784. ;; mingetty-shepherd-service).
  785. (requirement '(user-processes host-name udev))
  786. (modules '((ice-9 match) (gnu build linux-boot)))
  787. (start
  788. (with-imported-modules (source-module-closure
  789. '((gnu build linux-boot)))
  790. #~(lambda args
  791. (let ((defaulted-tty #$(or tty (default-serial-port))))
  792. (apply
  793. (if defaulted-tty
  794. (make-forkexec-constructor
  795. (list #$(file-append util-linux "/sbin/agetty")
  796. #$@extra-options
  797. #$@(if eight-bits?
  798. #~("--8bits")
  799. #~())
  800. #$@(if no-reset?
  801. #~("--noreset")
  802. #~())
  803. #$@(if remote?
  804. #~("--remote")
  805. #~())
  806. #$@(if flow-control?
  807. #~("--flow-control")
  808. #~())
  809. #$@(if host
  810. #~("--host" #$host)
  811. #~())
  812. #$@(if no-issue?
  813. #~("--noissue")
  814. #~())
  815. #$@(if init-string
  816. #~("--init-string" #$init-string)
  817. #~())
  818. #$@(if no-clear?
  819. #~("--noclear")
  820. #~())
  821. ;;; FIXME This doesn't work as expected. According to agetty(8), if this option
  822. ;;; is not passed, then the default is 'auto'. However, in my tests, when that
  823. ;;; option is selected, agetty never presents the login prompt, and the
  824. ;;; term-ttyS0 service respawns every few seconds.
  825. #$@(if local-line
  826. #~(#$(match local-line
  827. ('auto "--local-line=auto")
  828. ('always "--local-line=always")
  829. ('never "-local-line=never")))
  830. #~())
  831. #$@(if tty
  832. #~()
  833. #~("--keep-baud"))
  834. #$@(if extract-baud?
  835. #~("--extract-baud")
  836. #~())
  837. #$@(if skip-login?
  838. #~("--skip-login")
  839. #~())
  840. #$@(if no-newline?
  841. #~("--nonewline")
  842. #~())
  843. #$@(if login-options
  844. #~("--login-options" #$login-options)
  845. #~())
  846. #$@(if chroot
  847. #~("--chroot" #$chroot)
  848. #~())
  849. #$@(if hangup?
  850. #~("--hangup")
  851. #~())
  852. #$@(if keep-baud?
  853. #~("--keep-baud")
  854. #~())
  855. #$@(if timeout
  856. #~("--timeout" #$(number->string timeout))
  857. #~())
  858. #$@(if detect-case?
  859. #~("--detect-case")
  860. #~())
  861. #$@(if wait-cr?
  862. #~("--wait-cr")
  863. #~())
  864. #$@(if no-hints?
  865. #~("--nohints?")
  866. #~())
  867. #$@(if no-hostname?
  868. #~("--nohostname")
  869. #~())
  870. #$@(if long-hostname?
  871. #~("--long-hostname")
  872. #~())
  873. #$@(if erase-characters
  874. #~("--erase-chars" #$erase-characters)
  875. #~())
  876. #$@(if kill-characters
  877. #~("--kill-chars" #$kill-characters)
  878. #~())
  879. #$@(if chdir
  880. #~("--chdir" #$chdir)
  881. #~())
  882. #$@(if delay
  883. #~("--delay" #$(number->string delay))
  884. #~())
  885. #$@(if nice
  886. #~("--nice" #$(number->string nice))
  887. #~())
  888. #$@(if auto-login
  889. (list "--autologin" auto-login)
  890. '())
  891. #$@(if login-program
  892. #~("--login-program" #$login-program)
  893. #~())
  894. #$@(if login-pause?
  895. #~("--login-pause")
  896. #~())
  897. defaulted-tty
  898. #$@(if baud-rate
  899. #~(#$baud-rate)
  900. #~())
  901. #$@(if term
  902. #~(#$term)
  903. #~())))
  904. (const #f)) ; never start.
  905. args)))))
  906. (stop #~(make-kill-destructor)))))))
  907. (define agetty-service-type
  908. (service-type (name 'agetty)
  909. (extensions (list (service-extension shepherd-root-service-type
  910. agetty-shepherd-service)))
  911. (description
  912. "Provide console login using the @command{agetty}
  913. program.")))
  914. (define* (agetty-service config)
  915. "Return a service to run agetty according to @var{config}, which specifies
  916. the tty to run, among other things."
  917. (service agetty-service-type config))
  918. (define-record-type* <mingetty-configuration>
  919. mingetty-configuration make-mingetty-configuration
  920. mingetty-configuration?
  921. (mingetty mingetty-configuration-mingetty ;<package>
  922. (default mingetty))
  923. (tty mingetty-configuration-tty) ;string
  924. (auto-login mingetty-auto-login ;string | #f
  925. (default #f))
  926. (login-program mingetty-login-program ;gexp
  927. (default #f))
  928. (login-pause? mingetty-login-pause? ;Boolean
  929. (default #f)))
  930. (define mingetty-shepherd-service
  931. (match-lambda
  932. (($ <mingetty-configuration> mingetty tty auto-login login-program
  933. login-pause?)
  934. (list
  935. (shepherd-service
  936. (documentation "Run mingetty on an tty.")
  937. (provision (list (symbol-append 'term- (string->symbol tty))))
  938. ;; Since the login prompt shows the host name, wait for the 'host-name'
  939. ;; service to be done. Also wait for udev essentially so that the tty
  940. ;; text is not lost in the middle of kernel messages (XXX).
  941. (requirement '(user-processes host-name udev virtual-terminal))
  942. (start #~(make-forkexec-constructor
  943. (list #$(file-append mingetty "/sbin/mingetty")
  944. "--noclear"
  945. ;; Avoiding 'vhangup' allows us to avoid 'setfont'
  946. ;; errors down the path where various ioctls get
  947. ;; EIO--see 'hung_up_tty_ioctl' in driver/tty/tty_io.c
  948. ;; in Linux.
  949. "--nohangup" #$tty
  950. #$@(if auto-login
  951. #~("--autologin" #$auto-login)
  952. #~())
  953. #$@(if login-program
  954. #~("--loginprog" #$login-program)
  955. #~())
  956. #$@(if login-pause?
  957. #~("--loginpause")
  958. #~()))))
  959. (stop #~(make-kill-destructor)))))))
  960. (define mingetty-service-type
  961. (service-type (name 'mingetty)
  962. (extensions (list (service-extension shepherd-root-service-type
  963. mingetty-shepherd-service)))
  964. (description
  965. "Provide console login using the @command{mingetty}
  966. program.")))
  967. (define* (mingetty-service config)
  968. "Return a service to run mingetty according to @var{config}, which specifies
  969. the tty to run, among other things."
  970. (service mingetty-service-type config))
  971. (define-record-type* <nscd-configuration> nscd-configuration
  972. make-nscd-configuration
  973. nscd-configuration?
  974. (log-file nscd-configuration-log-file ;string
  975. (default "/var/log/nscd.log"))
  976. (debug-level nscd-debug-level ;integer
  977. (default 0))
  978. ;; TODO: See nscd.conf in glibc for other options to add.
  979. (caches nscd-configuration-caches ;list of <nscd-cache>
  980. (default %nscd-default-caches))
  981. (name-services nscd-configuration-name-services ;list of <packages>
  982. (default '()))
  983. (glibc nscd-configuration-glibc ;<package>
  984. (default glibc)))
  985. (define-record-type* <nscd-cache> nscd-cache make-nscd-cache
  986. nscd-cache?
  987. (database nscd-cache-database) ;symbol
  988. (positive-time-to-live nscd-cache-positive-time-to-live) ;integer
  989. (negative-time-to-live nscd-cache-negative-time-to-live
  990. (default 20)) ;integer
  991. (suggested-size nscd-cache-suggested-size ;integer ("default module
  992. ;of hash table")
  993. (default 211))
  994. (check-files? nscd-cache-check-files? ;Boolean
  995. (default #t))
  996. (persistent? nscd-cache-persistent? ;Boolean
  997. (default #t))
  998. (shared? nscd-cache-shared? ;Boolean
  999. (default #t))
  1000. (max-database-size nscd-cache-max-database-size ;integer
  1001. (default (* 32 (expt 2 20))))
  1002. (auto-propagate? nscd-cache-auto-propagate? ;Boolean
  1003. (default #t)))
  1004. (define %nscd-default-caches
  1005. ;; Caches that we want to enable by default. Note that when providing an
  1006. ;; empty nscd.conf, all caches are disabled.
  1007. (list (nscd-cache (database 'hosts)
  1008. ;; Aggressively cache the host name cache to improve
  1009. ;; privacy and resilience.
  1010. (positive-time-to-live (* 3600 12))
  1011. (negative-time-to-live 20)
  1012. (persistent? #t))
  1013. (nscd-cache (database 'services)
  1014. ;; Services are unlikely to change, so we can be even more
  1015. ;; aggressive.
  1016. (positive-time-to-live (* 3600 24))
  1017. (negative-time-to-live 3600)
  1018. (check-files? #t) ;check /etc/services changes
  1019. (persistent? #t))))
  1020. (define %nscd-default-configuration
  1021. ;; Default nscd configuration.
  1022. (nscd-configuration))
  1023. (define (nscd.conf-file config)
  1024. "Return the @file{nscd.conf} configuration file for @var{config}, an
  1025. @code{<nscd-configuration>} object."
  1026. (define cache->config
  1027. (match-lambda
  1028. (($ <nscd-cache> (= symbol->string database)
  1029. positive-ttl negative-ttl size check-files?
  1030. persistent? shared? max-size propagate?)
  1031. (string-append "\nenable-cache\t" database "\tyes\n"
  1032. "positive-time-to-live\t" database "\t"
  1033. (number->string positive-ttl) "\n"
  1034. "negative-time-to-live\t" database "\t"
  1035. (number->string negative-ttl) "\n"
  1036. "suggested-size\t" database "\t"
  1037. (number->string size) "\n"
  1038. "check-files\t" database "\t"
  1039. (if check-files? "yes\n" "no\n")
  1040. "persistent\t" database "\t"
  1041. (if persistent? "yes\n" "no\n")
  1042. "shared\t" database "\t"
  1043. (if shared? "yes\n" "no\n")
  1044. "max-db-size\t" database "\t"
  1045. (number->string max-size) "\n"
  1046. "auto-propagate\t" database "\t"
  1047. (if propagate? "yes\n" "no\n")))))
  1048. (match config
  1049. (($ <nscd-configuration> log-file debug-level caches)
  1050. (plain-file "nscd.conf"
  1051. (string-append "\
  1052. # Configuration of libc's name service cache daemon (nscd).\n\n"
  1053. (if log-file
  1054. (string-append "logfile\t" log-file)
  1055. "")
  1056. "\n"
  1057. (if debug-level
  1058. (string-append "debug-level\t"
  1059. (number->string debug-level))
  1060. "")
  1061. "\n"
  1062. (string-concatenate
  1063. (map cache->config caches)))))))
  1064. (define (nscd-action-procedure nscd config option)
  1065. ;; XXX: This is duplicated from mcron; factorize.
  1066. #~(lambda (_ . args)
  1067. ;; Run 'nscd' in a pipe so we can explicitly redirect its output to
  1068. ;; 'current-output-port', which at this stage is bound to the client
  1069. ;; connection.
  1070. (let ((pipe (apply open-pipe* OPEN_READ #$nscd
  1071. "-f" #$config #$option args)))
  1072. (let loop ()
  1073. (match (read-line pipe 'concat)
  1074. ((? eof-object?)
  1075. (catch 'system-error
  1076. (lambda ()
  1077. (zero? (close-pipe pipe)))
  1078. (lambda args
  1079. ;; There's a race with the SIGCHLD handler, which could
  1080. ;; call 'waitpid' before 'close-pipe' above does. If we
  1081. ;; get ECHILD, that means we lost the race; in that case, we
  1082. ;; cannot tell what the exit code was (FIXME).
  1083. (or (= ECHILD (system-error-errno args))
  1084. (apply throw args)))))
  1085. (line
  1086. (display line)
  1087. (loop)))))))
  1088. (define (nscd-actions nscd config)
  1089. "Return Shepherd actions for NSCD."
  1090. ;; Make this functionality available as actions because that's a simple way
  1091. ;; to run the right 'nscd' binary with the right config file.
  1092. (list (shepherd-action
  1093. (name 'statistics)
  1094. (documentation "Display statistics about nscd usage.")
  1095. (procedure (nscd-action-procedure nscd config "--statistics")))
  1096. (shepherd-action
  1097. (name 'invalidate)
  1098. (documentation
  1099. "Invalidate the given cache--e.g., 'hosts' for host name lookups.")
  1100. (procedure (nscd-action-procedure nscd config "--invalidate")))))
  1101. (define (nscd-shepherd-service config)
  1102. "Return a shepherd service for CONFIG, an <nscd-configuration> object."
  1103. (let ((nscd (file-append (nscd-configuration-glibc config)
  1104. "/sbin/nscd"))
  1105. (nscd.conf (nscd.conf-file config))
  1106. (name-services (nscd-configuration-name-services config)))
  1107. (list (shepherd-service
  1108. (documentation "Run libc's name service cache daemon (nscd).")
  1109. (provision '(nscd))
  1110. (requirement '(user-processes))
  1111. (start #~(make-forkexec-constructor
  1112. (list #$nscd "-f" #$nscd.conf "--foreground")
  1113. ;; Wait for the PID file. However, the PID file is
  1114. ;; written before nscd is actually listening on its
  1115. ;; socket (XXX).
  1116. #:pid-file "/var/run/nscd/nscd.pid"
  1117. #:environment-variables
  1118. (list (string-append "LD_LIBRARY_PATH="
  1119. (string-join
  1120. (map (lambda (dir)
  1121. (string-append dir "/lib"))
  1122. (list #$@name-services))
  1123. ":")))))
  1124. (stop #~(make-kill-destructor))
  1125. (modules `((ice-9 popen) ;for the actions
  1126. (ice-9 rdelim)
  1127. (ice-9 match)
  1128. ,@%default-modules))
  1129. (actions (nscd-actions nscd nscd.conf))))))
  1130. (define nscd-activation
  1131. ;; Actions to take before starting nscd.
  1132. #~(begin
  1133. (use-modules (guix build utils))
  1134. (mkdir-p "/var/run/nscd")
  1135. (mkdir-p "/var/db/nscd") ;for the persistent cache
  1136. ;; In libc 2.25 nscd uses inotify to watch /etc/resolv.conf, but only if
  1137. ;; that file exists when it is started. Thus create it here. Note: on
  1138. ;; some systems, such as when NetworkManager is used, /etc/resolv.conf
  1139. ;; is a symlink, hence 'lstat'.
  1140. (unless (false-if-exception (lstat "/etc/resolv.conf"))
  1141. (call-with-output-file "/etc/resolv.conf"
  1142. (lambda (port)
  1143. (display "# This is a placeholder.\n" port))))))
  1144. (define nscd-service-type
  1145. (service-type (name 'nscd)
  1146. (extensions
  1147. (list (service-extension activation-service-type
  1148. (const nscd-activation))
  1149. (service-extension shepherd-root-service-type
  1150. nscd-shepherd-service)))
  1151. ;; This can be extended by providing additional name services
  1152. ;; such as nss-mdns.
  1153. (compose concatenate)
  1154. (extend (lambda (config name-services)
  1155. (nscd-configuration
  1156. (inherit config)
  1157. (name-services (append
  1158. (nscd-configuration-name-services config)
  1159. name-services)))))
  1160. (default-value %nscd-default-configuration)
  1161. (description
  1162. "Runs libc's @dfn{name service cache daemon} (nscd) with the
  1163. given configuration---an @code{<nscd-configuration>} object. @xref{Name
  1164. Service Switch}, for an example.")))
  1165. (define* (nscd-service #:optional (config %nscd-default-configuration))
  1166. "Return a service that runs libc's name service cache daemon (nscd) with the
  1167. given @var{config}---an @code{<nscd-configuration>} object. @xref{Name
  1168. Service Switch}, for an example."
  1169. (service nscd-service-type config))
  1170. (define-record-type* <syslog-configuration>
  1171. syslog-configuration make-syslog-configuration
  1172. syslog-configuration?
  1173. (syslogd syslog-configuration-syslogd
  1174. (default (file-append inetutils "/libexec/syslogd")))
  1175. (config-file syslog-configuration-config-file
  1176. (default %default-syslog.conf)))
  1177. (define syslog-service-type
  1178. (shepherd-service-type
  1179. 'syslog
  1180. (lambda (config)
  1181. (shepherd-service
  1182. (documentation "Run the syslog daemon (syslogd).")
  1183. (provision '(syslogd))
  1184. (requirement '(user-processes))
  1185. (start #~(let ((spawn (make-forkexec-constructor
  1186. (list #$(syslog-configuration-syslogd config)
  1187. "--rcfile"
  1188. #$(syslog-configuration-config-file config))
  1189. #:pid-file "/var/run/syslog.pid")))
  1190. (lambda ()
  1191. ;; Set the umask such that file permissions are #o640.
  1192. (let ((mask (umask #o137))
  1193. (pid (spawn)))
  1194. (umask mask)
  1195. pid))))
  1196. (stop #~(make-kill-destructor))))))
  1197. ;; Snippet adapted from the GNU inetutils manual.
  1198. (define %default-syslog.conf
  1199. (plain-file "syslog.conf" "
  1200. # Log all error messages, authentication messages of
  1201. # level notice or higher and anything of level err or
  1202. # higher to the console.
  1203. # Don't log private authentication messages!
  1204. *.alert;auth.notice;authpriv.none /dev/console
  1205. # Log anything (except mail) of level info or higher.
  1206. # Don't log private authentication messages!
  1207. *.info;mail.none;authpriv.none /var/log/messages
  1208. # Like /var/log/messages, but also including \"debug\"-level logs.
  1209. *.debug;mail.none;authpriv.none /var/log/debug
  1210. # Same, in a different place.
  1211. *.info;mail.none;authpriv.none /dev/tty12
  1212. # The authpriv file has restricted access.
  1213. authpriv.* /var/log/secure
  1214. # Log all the mail messages in one place.
  1215. mail.* /var/log/maillog
  1216. "))
  1217. (define* (syslog-service #:optional (config (syslog-configuration)))
  1218. "Return a service that runs @command{syslogd} and takes
  1219. @var{<syslog-configuration>} as a parameter.
  1220. @xref{syslogd invocation,,, inetutils, GNU Inetutils}, for more
  1221. information on the configuration file syntax."
  1222. (service syslog-service-type config))
  1223. (define pam-limits-service-type
  1224. (let ((security-limits
  1225. ;; Create /etc/security containing the provided "limits.conf" file.
  1226. (lambda (limits-file)
  1227. `(("security"
  1228. ,(computed-file
  1229. "security"
  1230. #~(begin
  1231. (mkdir #$output)
  1232. (stat #$limits-file)
  1233. (symlink #$limits-file
  1234. (string-append #$output "/limits.conf"))))))))
  1235. (pam-extension
  1236. (lambda (pam)
  1237. (let ((pam-limits (pam-entry
  1238. (control "required")
  1239. (module "pam_limits.so")
  1240. (arguments '("conf=/etc/security/limits.conf")))))
  1241. (if (member (pam-service-name pam)
  1242. '("login" "su" "slim" "gdm-password" "sddm"))
  1243. (pam-service
  1244. (inherit pam)
  1245. (session (cons pam-limits
  1246. (pam-service-session pam))))
  1247. pam)))))
  1248. (service-type
  1249. (name 'limits)
  1250. (extensions
  1251. (list (service-extension etc-service-type security-limits)
  1252. (service-extension pam-root-service-type
  1253. (lambda _ (list pam-extension)))))
  1254. (description
  1255. "Install the specified resource usage limits by populating
  1256. @file{/etc/security/limits.conf} and using the @code{pam_limits}
  1257. authentication module."))))
  1258. (define* (pam-limits-service #:optional (limits '()))
  1259. "Return a service that makes selected programs respect the list of
  1260. pam-limits-entry specified in LIMITS via pam_limits.so."
  1261. (service pam-limits-service-type
  1262. (plain-file "limits.conf"
  1263. (string-join (map pam-limits-entry->string limits)
  1264. "\n"))))
  1265. ;;;
  1266. ;;; Guix services.
  1267. ;;;
  1268. (define* (guix-build-accounts count #:key
  1269. (group "guixbuild")
  1270. (shadow shadow))
  1271. "Return a list of COUNT user accounts for Guix build users with the given
  1272. GID."
  1273. (unfold (cut > <> count)
  1274. (lambda (n)
  1275. (user-account
  1276. (name (format #f "guixbuilder~2,'0d" n))
  1277. (system? #t)
  1278. (group group)
  1279. ;; guix-daemon expects GROUP to be listed as a
  1280. ;; supplementary group too:
  1281. ;; <http://lists.gnu.org/archive/html/bug-guix/2013-01/msg00239.html>.
  1282. (supplementary-groups (list group "kvm"))
  1283. (comment (format #f "Guix Build User ~2d" n))
  1284. (home-directory "/var/empty")
  1285. (shell (file-append shadow "/sbin/nologin"))))
  1286. 1+
  1287. 1))
  1288. (define not-config?
  1289. ;; Select (guix …) and (gnu …) modules, except (guix config).
  1290. (match-lambda
  1291. (('guix 'config) #f)
  1292. (('guix rest ...) #t)
  1293. (('gnu rest ...) #t)
  1294. (rest #f)))
  1295. (define (substitute-key-authorization keys guix)
  1296. "Return a gexp with code to register KEYS, a list of files containing 'guix
  1297. archive' public keys, with GUIX."
  1298. (define default-acl
  1299. (with-extensions (list guile-gcrypt)
  1300. (with-imported-modules `(((guix config) => ,(make-config.scm))
  1301. ,@(source-module-closure '((guix pki))
  1302. #:select? not-config?))
  1303. (computed-file "acl"
  1304. #~(begin
  1305. (use-modules (guix pki)
  1306. (gcrypt pk-crypto)
  1307. (ice-9 rdelim))
  1308. (define keys
  1309. (map (lambda (file)
  1310. (call-with-input-file file
  1311. (compose string->canonical-sexp
  1312. read-string)))
  1313. '(#$@keys)))
  1314. (call-with-output-file #$output
  1315. (lambda (port)
  1316. (write-acl (public-keys->acl keys)
  1317. port))))))))
  1318. (with-imported-modules '((guix build utils))
  1319. #~(begin
  1320. (use-modules (guix build utils))
  1321. (unless (file-exists? "/etc/guix/acl")
  1322. (mkdir-p "/etc/guix")
  1323. (copy-file #+default-acl "/etc/guix/acl")
  1324. (chmod "/etc/guix/acl" #o600)))))
  1325. (define %default-authorized-guix-keys
  1326. ;; List of authorized substitute keys.
  1327. (list (file-append guix "/share/guix/berlin.guix.gnu.org.pub")))
  1328. (define-record-type* <guix-configuration>
  1329. guix-configuration make-guix-configuration
  1330. guix-configuration?
  1331. (guix guix-configuration-guix ;<package>
  1332. (default guix))
  1333. (build-group guix-configuration-build-group ;string
  1334. (default "guixbuild"))
  1335. (build-accounts guix-configuration-build-accounts ;integer
  1336. (default 10))
  1337. (authorize-key? guix-configuration-authorize-key? ;Boolean
  1338. (default #t))
  1339. (authorized-keys guix-configuration-authorized-keys ;list of gexps
  1340. (default %default-authorized-guix-keys))
  1341. (use-substitutes? guix-configuration-use-substitutes? ;Boolean
  1342. (default #t))
  1343. (substitute-urls guix-configuration-substitute-urls ;list of strings
  1344. (default %default-substitute-urls))
  1345. (chroot-directories guix-configuration-chroot-directories ;list of file-like/strings
  1346. (default '()))
  1347. (max-silent-time guix-configuration-max-silent-time ;integer
  1348. (default 0))
  1349. (timeout guix-configuration-timeout ;integer
  1350. (default 0))
  1351. (log-compression guix-configuration-log-compression
  1352. (default 'bzip2))
  1353. (extra-options guix-configuration-extra-options ;list of strings
  1354. (default '()))
  1355. (log-file guix-configuration-log-file ;string
  1356. (default "/var/log/guix-daemon.log"))
  1357. (http-proxy guix-http-proxy ;string | #f
  1358. (default #f))
  1359. (tmpdir guix-tmpdir ;string | #f
  1360. (default #f)))
  1361. (define %default-guix-configuration
  1362. (guix-configuration))
  1363. (define shepherd-set-http-proxy-action
  1364. ;; Shepherd action to change the HTTP(S) proxy.
  1365. (shepherd-action
  1366. (name 'set-http-proxy)
  1367. (documentation
  1368. "Change the HTTP(S) proxy used by 'guix-daemon' and restart it.")
  1369. (procedure #~(lambda* (_ #:optional proxy)
  1370. (let ((environment (environ)))
  1371. ;; A bit of a hack: communicate PROXY to the 'start'
  1372. ;; method via environment variables.
  1373. (if proxy
  1374. (begin
  1375. (format #t "changing HTTP/HTTPS \
  1376. proxy of 'guix-daemon' to ~s...~%"
  1377. proxy)
  1378. (setenv "http_proxy" proxy))
  1379. (begin
  1380. (format #t "clearing HTTP/HTTPS \
  1381. proxy of 'guix-daemon'...~%")
  1382. (unsetenv "http_proxy")))
  1383. (action 'guix-daemon 'restart)
  1384. (environ environment)
  1385. #t)))))
  1386. (define (guix-shepherd-service config)
  1387. "Return a <shepherd-service> for the Guix daemon service with CONFIG."
  1388. (match-record config <guix-configuration>
  1389. (guix build-group build-accounts authorize-key? authorized-keys
  1390. use-substitutes? substitute-urls max-silent-time timeout
  1391. log-compression extra-options log-file http-proxy tmpdir
  1392. chroot-directories)
  1393. (list (shepherd-service
  1394. (documentation "Run the Guix daemon.")
  1395. (provision '(guix-daemon))
  1396. (requirement '(user-processes))
  1397. (actions (list shepherd-set-http-proxy-action))
  1398. (modules '((srfi srfi-1)
  1399. (ice-9 match)
  1400. (gnu build shepherd)))
  1401. (start
  1402. (with-imported-modules (source-module-closure
  1403. '((gnu build shepherd)))
  1404. #~(lambda args
  1405. (define proxy
  1406. ;; HTTP/HTTPS proxy. The 'http_proxy' variable is set by
  1407. ;; the 'set-http-proxy' action.
  1408. (or (getenv "http_proxy") #$http-proxy))
  1409. ;; Start the guix-daemon from a container, when supported,
  1410. ;; to solve an installation issue. See the comment below for
  1411. ;; more details.
  1412. (fork+exec-command/container
  1413. (cons* #$(file-append guix "/bin/guix-daemon")
  1414. "--build-users-group" #$build-group
  1415. "--max-silent-time"
  1416. #$(number->string max-silent-time)
  1417. "--timeout" #$(number->string timeout)
  1418. "--log-compression"
  1419. #$(symbol->string log-compression)
  1420. #$@(if use-substitutes?
  1421. '()
  1422. '("--no-substitutes"))
  1423. "--substitute-urls" #$(string-join substitute-urls)
  1424. #$@extra-options
  1425. ;; Add CHROOT-DIRECTORIES and all their dependencies
  1426. ;; (if these are store items) to the chroot.
  1427. (append-map
  1428. (lambda (file)
  1429. (append-map (lambda (directory)
  1430. (list "--chroot-directory"
  1431. directory))
  1432. (call-with-input-file file
  1433. read)))
  1434. '#$(map references-file
  1435. chroot-directories)))
  1436. ;; When running the installer, we need guix-daemon to
  1437. ;; operate from within the same MNT namespace as the
  1438. ;; installation container. In that case only, enter the
  1439. ;; namespace of the process PID passed as start argument.
  1440. ;; Otherwise, for symmetry purposes enter the caller
  1441. ;; namespaces which is a no-op.
  1442. #:pid (match args
  1443. ((pid) (string->number pid))
  1444. (else (getpid)))
  1445. #:environment-variables
  1446. (append (list #$@(if tmpdir
  1447. (list (string-append "TMPDIR=" tmpdir))
  1448. '())
  1449. ;; Make sure we run in a UTF-8 locale so that
  1450. ;; 'guix offload' correctly restores nars
  1451. ;; that contain UTF-8 file names such as
  1452. ;; 'nss-certs'. See
  1453. ;; <https://bugs.gnu.org/32942>.
  1454. (string-append "GUIX_LOCPATH="
  1455. #$glibc-utf8-locales
  1456. "/lib/locale")
  1457. "LC_ALL=en_US.utf8")
  1458. (if proxy
  1459. (list (string-append "http_proxy=" proxy)
  1460. (string-append "https_proxy=" proxy))
  1461. '()))
  1462. #:log-file #$log-file))))
  1463. (stop #~(make-kill-destructor))))))
  1464. (define (guix-accounts config)
  1465. "Return the user accounts and user groups for CONFIG."
  1466. (match config
  1467. (($ <guix-configuration> _ build-group build-accounts)
  1468. (cons (user-group
  1469. (name build-group)
  1470. (system? #t)
  1471. ;; Use a fixed GID so that we can create the store with the right
  1472. ;; owner.
  1473. (id 30000))
  1474. (guix-build-accounts build-accounts
  1475. #:group build-group)))))
  1476. (define (guix-activation config)
  1477. "Return the activation gexp for CONFIG."
  1478. (match config
  1479. (($ <guix-configuration> guix build-group build-accounts authorize-key? keys)
  1480. ;; Assume that the store has BUILD-GROUP as its group. We could
  1481. ;; otherwise call 'chown' here, but the problem is that on a COW overlayfs,
  1482. ;; chown leads to an entire copy of the tree, which is a bad idea.
  1483. ;; Generate a key pair and optionally authorize substitute server keys.
  1484. #~(begin
  1485. (unless (file-exists? "/etc/guix/signing-key.pub")
  1486. (system* #$(file-append guix "/bin/guix") "archive"
  1487. "--generate-key"))
  1488. #$(if authorize-key?
  1489. (substitute-key-authorization keys guix)
  1490. #~#f)))))
  1491. (define* (references-file item #:optional (name "references"))
  1492. "Return a file that contains the list of references of ITEM."
  1493. (if (struct? item) ;lowerable object
  1494. (computed-file name
  1495. (with-imported-modules (source-module-closure
  1496. '((guix build store-copy)))
  1497. #~(begin
  1498. (use-modules (guix build store-copy))
  1499. (call-with-output-file #$output
  1500. (lambda (port)
  1501. (write (map store-info-item
  1502. (call-with-input-file "graph"
  1503. read-reference-graph))
  1504. port)))))
  1505. #:options `(#:local-build? #f
  1506. #:references-graphs (("graph" ,item))))
  1507. (plain-file name "()")))
  1508. (define guix-service-type
  1509. (service-type
  1510. (name 'guix)
  1511. (extensions
  1512. (list (service-extension shepherd-root-service-type guix-shepherd-service)
  1513. (service-extension account-service-type guix-accounts)
  1514. (service-extension activation-service-type guix-activation)
  1515. (service-extension profile-service-type
  1516. (compose list guix-configuration-guix))))
  1517. ;; Extensions can specify extra directories to add to the build chroot.
  1518. (compose concatenate)
  1519. (extend (lambda (config directories)
  1520. (guix-configuration
  1521. (inherit config)
  1522. (chroot-directories
  1523. (append (guix-configuration-chroot-directories config)
  1524. directories)))))
  1525. (default-value (guix-configuration))
  1526. (description
  1527. "Run the build daemon of GNU@tie{}Guix, aka. @command{guix-daemon}.")))
  1528. (define-deprecated (guix-service #:optional
  1529. (config %default-guix-configuration))
  1530. guix-service-type
  1531. "Return a service that runs the Guix build daemon according to
  1532. @var{config}."
  1533. (service guix-service-type config))
  1534. (define-record-type* <guix-publish-configuration>
  1535. guix-publish-configuration make-guix-publish-configuration
  1536. guix-publish-configuration?
  1537. (guix guix-publish-configuration-guix ;package
  1538. (default guix))
  1539. (port guix-publish-configuration-port ;number
  1540. (default 80))
  1541. (host guix-publish-configuration-host ;string
  1542. (default "localhost"))
  1543. (compression guix-publish-configuration-compression
  1544. (thunked)
  1545. (default (default-compression this-record
  1546. (current-source-location))))
  1547. (compression-level %guix-publish-configuration-compression-level ;deprecated
  1548. (default #f))
  1549. (nar-path guix-publish-configuration-nar-path ;string
  1550. (default "nar"))
  1551. (cache guix-publish-configuration-cache ;#f | string
  1552. (default #f))
  1553. (workers guix-publish-configuration-workers ;#f | integer
  1554. (default #f))
  1555. (ttl guix-publish-configuration-ttl ;#f | integer
  1556. (default #f)))
  1557. (define-deprecated (guix-publish-configuration-compression-level config)
  1558. "Return a compression level, the old way."
  1559. (match (guix-publish-configuration-compression config)
  1560. (((_ level) _ ...) level)))
  1561. (define (default-compression config properties)
  1562. "Return the default 'guix publish' compression according to CONFIG, and
  1563. raise a deprecation warning if the 'compression-level' field was used."
  1564. (match (%guix-publish-configuration-compression-level config)
  1565. (#f
  1566. '(("gzip" 3)))
  1567. (level
  1568. (warn-about-deprecation 'compression-level properties
  1569. #:replacement 'compression)
  1570. `(("gzip" ,level)))))
  1571. (define (guix-publish-shepherd-service config)
  1572. (define (config->compression-options config)
  1573. (match (guix-publish-configuration-compression config)
  1574. (() ;empty list means "no compression"
  1575. '("-C0"))
  1576. (lst
  1577. (append-map (match-lambda
  1578. ((type level)
  1579. `("-C" ,(string-append type ":"
  1580. (number->string level)))))
  1581. lst))))
  1582. (match-record config <guix-publish-configuration>
  1583. (guix port host nar-path cache workers ttl)
  1584. (list (shepherd-service
  1585. (provision '(guix-publish))
  1586. (requirement '(guix-daemon))
  1587. (start #~(make-forkexec-constructor
  1588. (list #$(file-append guix "/bin/guix")
  1589. "publish" "-u" "guix-publish"
  1590. "-p" #$(number->string port)
  1591. #$@(config->compression-options config)
  1592. (string-append "--nar-path=" #$nar-path)
  1593. (string-append "--listen=" #$host)
  1594. #$@(if workers
  1595. #~((string-append "--workers="
  1596. #$(number->string
  1597. workers)))
  1598. #~())
  1599. #$@(if ttl
  1600. #~((string-append "--ttl="
  1601. #$(number->string ttl)
  1602. "s"))
  1603. #~())
  1604. #$@(if cache
  1605. #~((string-append "--cache=" #$cache))
  1606. #~()))
  1607. ;; Make sure we run in a UTF-8 locale so we can produce
  1608. ;; nars for packages that contain UTF-8 file names such
  1609. ;; as 'nss-certs'. See <https://bugs.gnu.org/26948>.
  1610. #:environment-variables
  1611. (list (string-append "GUIX_LOCPATH="
  1612. #$glibc-utf8-locales "/lib/locale")
  1613. "LC_ALL=en_US.utf8")
  1614. #:log-file "/var/log/guix-publish.log"))
  1615. (stop #~(make-kill-destructor))))))
  1616. (define %guix-publish-accounts
  1617. (list (user-group (name "guix-publish") (system? #t))
  1618. (user-account
  1619. (name "guix-publish")
  1620. (group "guix-publish")
  1621. (system? #t)
  1622. (comment "guix publish user")
  1623. (home-directory "/var/empty")
  1624. (shell (file-append shadow "/sbin/nologin")))))
  1625. (define %guix-publish-log-rotations
  1626. (list (log-rotation
  1627. (files (list "/var/log/guix-publish.log")))))
  1628. (define (guix-publish-activation config)
  1629. (let ((cache (guix-publish-configuration-cache config)))
  1630. (if cache
  1631. (with-imported-modules '((guix build utils))
  1632. #~(begin
  1633. (use-modules (guix build utils))
  1634. (mkdir-p #$cache)
  1635. (let* ((pw (getpw "guix-publish"))
  1636. (uid (passwd:uid pw))
  1637. (gid (passwd:gid pw)))
  1638. (chown #$cache uid gid))))
  1639. #t)))
  1640. (define guix-publish-service-type
  1641. (service-type (name 'guix-publish)
  1642. (extensions
  1643. (list (service-extension shepherd-root-service-type
  1644. guix-publish-shepherd-service)
  1645. (service-extension account-service-type
  1646. (const %guix-publish-accounts))
  1647. (service-extension rottlog-service-type
  1648. (const %guix-publish-log-rotations))
  1649. (service-extension activation-service-type
  1650. guix-publish-activation)))
  1651. (default-value (guix-publish-configuration))
  1652. (description
  1653. "Add a Shepherd service running @command{guix publish}, a
  1654. command that allows you to share pre-built binaries with others over HTTP.")))
  1655. (define-deprecated (guix-publish-service #:key (guix guix)
  1656. (port 80) (host "localhost"))
  1657. guix-publish-service-type
  1658. "Return a service that runs @command{guix publish} listening on @var{host}
  1659. and @var{port} (@pxref{Invoking guix publish}).
  1660. This assumes that @file{/etc/guix} already contains a signing key pair as
  1661. created by @command{guix archive --generate-key} (@pxref{Invoking guix
  1662. archive}). If that is not the case, the service will fail to start."
  1663. ;; Deprecated.
  1664. (service guix-publish-service-type
  1665. (guix-publish-configuration (guix guix) (port port) (host host))))
  1666. ;;;
  1667. ;;; Udev.
  1668. ;;;
  1669. (define-record-type* <udev-configuration>
  1670. udev-configuration make-udev-configuration
  1671. udev-configuration?
  1672. (udev udev-configuration-udev ;<package>
  1673. (default eudev))
  1674. (rules udev-configuration-rules ;list of <package>
  1675. (default '())))
  1676. (define (udev-rules-union packages)
  1677. "Return the union of the @code{lib/udev/rules.d} directories found in each
  1678. item of @var{packages}."
  1679. (define build
  1680. (with-imported-modules '((guix build union)
  1681. (guix build utils))
  1682. #~(begin
  1683. (use-modules (guix build union)
  1684. (guix build utils)
  1685. (srfi srfi-1)
  1686. (srfi srfi-26))
  1687. (define %standard-locations
  1688. '("/lib/udev/rules.d" "/libexec/udev/rules.d"))
  1689. (define (rules-sub-directory directory)
  1690. ;; Return the sub-directory of DIRECTORY containing udev rules, or
  1691. ;; #f if none was found.
  1692. (find directory-exists?
  1693. (map (cut string-append directory <>) %standard-locations)))
  1694. (mkdir-p (string-append #$output "/lib/udev"))
  1695. (union-build (string-append #$output "/lib/udev/rules.d")
  1696. (filter-map rules-sub-directory '#$packages)))))
  1697. (computed-file "udev-rules" build))
  1698. (define (udev-rule file-name contents)
  1699. "Return a directory with a udev rule file FILE-NAME containing CONTENTS."
  1700. (computed-file file-name
  1701. (with-imported-modules '((guix build utils))
  1702. #~(begin
  1703. (use-modules (guix build utils))
  1704. (define rules.d
  1705. (string-append #$output "/lib/udev/rules.d"))
  1706. (mkdir-p rules.d)
  1707. (call-with-output-file
  1708. (string-append rules.d "/" #$file-name)
  1709. (lambda (port)
  1710. (display #$contents port)))))))
  1711. (define (file->udev-rule file-name file)
  1712. "Return a directory with a udev rule file FILE-NAME which is a copy of FILE."
  1713. (computed-file file-name
  1714. (with-imported-modules '((guix build utils))
  1715. #~(begin
  1716. (use-modules (guix build utils))
  1717. (define rules.d
  1718. (string-append #$output "/lib/udev/rules.d"))
  1719. (define file-copy-dest
  1720. (string-append rules.d "/" #$file-name))
  1721. (mkdir-p rules.d)
  1722. (copy-file #$file file-copy-dest)))))
  1723. (define kvm-udev-rule
  1724. ;; Return a directory with a udev rule that changes the group of /dev/kvm to
  1725. ;; "kvm" and makes it #o660. Apparently QEMU-KVM used to ship this rule,
  1726. ;; but now we have to add it by ourselves.
  1727. ;; Build users are part of the "kvm" group, so we can fearlessly make
  1728. ;; /dev/kvm 660 (see <http://bugs.gnu.org/18994>, for background.)
  1729. (udev-rule "90-kvm.rules"
  1730. "KERNEL==\"kvm\", GROUP=\"kvm\", MODE=\"0660\"\n"))
  1731. (define udev-shepherd-service
  1732. ;; Return a <shepherd-service> for UDEV with RULES.
  1733. (match-lambda
  1734. (($ <udev-configuration> udev rules)
  1735. (let* ((rules (udev-rules-union (cons* udev kvm-udev-rule rules)))
  1736. (udev.conf (computed-file "udev.conf"
  1737. #~(call-with-output-file #$output
  1738. (lambda (port)
  1739. (format port
  1740. "udev_rules=\"~a/lib/udev/rules.d\"\n"
  1741. #$rules))))))
  1742. (list
  1743. (shepherd-service
  1744. (provision '(udev))
  1745. ;; Udev needs /dev to be a 'devtmpfs' mount so that new device nodes can
  1746. ;; be added: see
  1747. ;; <http://www.linuxfromscratch.org/lfs/view/development/chapter07/udev.html>.
  1748. (requirement '(root-file-system))
  1749. (documentation "Populate the /dev directory, dynamically.")
  1750. (start
  1751. (with-imported-modules (source-module-closure
  1752. '((gnu build linux-boot)))
  1753. #~(lambda ()
  1754. (define udevd
  1755. ;; 'udevd' from eudev.
  1756. #$(file-append udev "/sbin/udevd"))
  1757. (define (wait-for-udevd)
  1758. ;; Wait until someone's listening on udevd's control
  1759. ;; socket.
  1760. (let ((sock (socket AF_UNIX SOCK_SEQPACKET 0)))
  1761. (let try ()
  1762. (catch 'system-error
  1763. (lambda ()
  1764. (connect sock PF_UNIX "/run/udev/control")
  1765. (close-port sock))
  1766. (lambda args
  1767. (format #t "waiting for udevd...~%")
  1768. (usleep 500000)
  1769. (try))))))
  1770. ;; Allow udev to find the modules.
  1771. (setenv "LINUX_MODULE_DIRECTORY"
  1772. "/run/booted-system/kernel/lib/modules")
  1773. (let* ((kernel-release
  1774. (utsname:release (uname)))
  1775. (linux-module-directory
  1776. (getenv "LINUX_MODULE_DIRECTORY"))
  1777. (directory
  1778. (string-append linux-module-directory "/"
  1779. kernel-release))
  1780. (old-umask (umask #o022)))
  1781. ;; If we're in a container, DIRECTORY might not exist,
  1782. ;; for instance because the host runs a different
  1783. ;; kernel. In that case, skip it; we'll just miss a few
  1784. ;; nodes like /dev/fuse.
  1785. (when (file-exists? directory)
  1786. (make-static-device-nodes directory))
  1787. (umask old-umask))
  1788. (let ((pid (fork+exec-command (list udevd)
  1789. #:environment-variables
  1790. (cons*
  1791. ;; The first one is for udev, the second one for
  1792. ;; eudev.
  1793. (string-append "UDEV_CONFIG_FILE=" #$udev.conf)
  1794. (string-append "EUDEV_RULES_DIRECTORY="
  1795. #$(file-append
  1796. rules "/lib/udev/rules.d"))
  1797. (string-append "LINUX_MODULE_DIRECTORY="
  1798. (getenv "LINUX_MODULE_DIRECTORY"))
  1799. (default-environment-variables)))))
  1800. ;; Wait until udevd is up and running. This appears to
  1801. ;; be needed so that the events triggered below are
  1802. ;; actually handled.
  1803. (wait-for-udevd)
  1804. ;; Trigger device node creation.
  1805. (system* #$(file-append udev "/bin/udevadm")
  1806. "trigger" "--action=add")
  1807. ;; Wait for things to settle down.
  1808. (system* #$(file-append udev "/bin/udevadm")
  1809. "settle")
  1810. pid))))
  1811. (stop #~(make-kill-destructor))
  1812. ;; When halting the system, 'udev' is actually killed by
  1813. ;; 'user-processes', i.e., before its own 'stop' method was called.
  1814. ;; Thus, make sure it is not respawned.
  1815. (respawn? #f)
  1816. ;; We need additional modules.
  1817. (modules `((gnu build linux-boot) ;'make-static-device-nodes'
  1818. ,@%default-modules))
  1819. (actions (list (shepherd-action
  1820. (name 'rules)
  1821. (documentation "Display the directory containing
  1822. the udev rules in use.")
  1823. (procedure #~(lambda (_)
  1824. (display #$rules)
  1825. (newline))))))))))))
  1826. (define udev-service-type
  1827. (service-type (name 'udev)
  1828. (extensions
  1829. (list (service-extension shepherd-root-service-type
  1830. udev-shepherd-service)))
  1831. (compose concatenate) ;concatenate the list of rules
  1832. (extend (lambda (config rules)
  1833. (match config
  1834. (($ <udev-configuration> udev initial-rules)
  1835. (udev-configuration
  1836. (udev udev)
  1837. (rules (append initial-rules rules)))))))
  1838. (default-value (udev-configuration))
  1839. (description
  1840. "Run @command{udev}, which populates the @file{/dev}
  1841. directory dynamically. Get extra rules from the packages listed in the
  1842. @code{rules} field of its value, @code{udev-configuration} object.")))
  1843. (define* (udev-service #:key (udev eudev) (rules '()))
  1844. "Run @var{udev}, which populates the @file{/dev} directory dynamically. Get
  1845. extra rules from the packages listed in @var{rules}."
  1846. (service udev-service-type
  1847. (udev-configuration (udev udev) (rules rules))))
  1848. (define* (udev-rules-service name rules #:key (groups '()))
  1849. "Return a service that extends udev-service-type with RULES and
  1850. account-service-type with GROUPS as system groups. This works by creating a
  1851. singleton service type NAME-udev-rules, of which the returned service is an
  1852. instance."
  1853. (let* ((name (symbol-append name '-udev-rules))
  1854. (account-extension
  1855. (const (map (lambda (group)
  1856. (user-group (name group) (system? #t)))
  1857. groups)))
  1858. (udev-extension (const (list rules)))
  1859. (type (service-type
  1860. (name name)
  1861. (extensions (list
  1862. (service-extension
  1863. account-service-type account-extension)
  1864. (service-extension
  1865. udev-service-type udev-extension))))))
  1866. (service type #f)))
  1867. (define swap-service-type
  1868. (shepherd-service-type
  1869. 'swap
  1870. (lambda (device)
  1871. (define requirement
  1872. (if (string-prefix? "/dev/mapper/" device)
  1873. (list (symbol-append 'device-mapping-
  1874. (string->symbol (basename device))))
  1875. '()))
  1876. (shepherd-service
  1877. (provision (list (symbol-append 'swap- (string->symbol device))))
  1878. (requirement `(udev ,@requirement))
  1879. (documentation "Enable the given swap device.")
  1880. (start #~(lambda ()
  1881. (restart-on-EINTR (swapon #$device))
  1882. #t))
  1883. (stop #~(lambda _
  1884. (restart-on-EINTR (swapoff #$device))
  1885. #f))
  1886. (respawn? #f)))))
  1887. (define (swap-service device)
  1888. "Return a service that uses @var{device} as a swap device."
  1889. (service swap-service-type device))
  1890. (define %default-gpm-options
  1891. ;; Default options for GPM.
  1892. '("-m" "/dev/input/mice" "-t" "ps2"))
  1893. (define-record-type* <gpm-configuration>
  1894. gpm-configuration make-gpm-configuration gpm-configuration?
  1895. (gpm gpm-configuration-gpm ;package
  1896. (default gpm))
  1897. (options gpm-configuration-options ;list of strings
  1898. (default %default-gpm-options)))
  1899. (define gpm-shepherd-service
  1900. (match-lambda
  1901. (($ <gpm-configuration> gpm options)
  1902. (list (shepherd-service
  1903. (requirement '(udev))
  1904. (provision '(gpm))
  1905. (start #~(lambda ()
  1906. ;; 'gpm' runs in the background and sets a PID file.
  1907. ;; Note that it requires running as "root".
  1908. (false-if-exception (delete-file "/var/run/gpm.pid"))
  1909. (fork+exec-command (list #$(file-append gpm "/sbin/gpm")
  1910. #$@options))
  1911. ;; Wait for the PID file to appear; declare failure if
  1912. ;; it doesn't show up.
  1913. (let loop ((i 3))
  1914. (or (file-exists? "/var/run/gpm.pid")
  1915. (if (zero? i)
  1916. #f
  1917. (begin
  1918. (sleep 1)
  1919. (loop (1- i))))))))
  1920. (stop #~(lambda (_)
  1921. ;; Return #f if successfully stopped.
  1922. (not (zero? (system* #$(file-append gpm "/sbin/gpm")
  1923. "-k"))))))))))
  1924. (define gpm-service-type
  1925. (service-type (name 'gpm)
  1926. (extensions
  1927. (list (service-extension shepherd-root-service-type
  1928. gpm-shepherd-service)))
  1929. (default-value (gpm-configuration))
  1930. (description
  1931. "Run GPM, the general-purpose mouse daemon, with the given
  1932. command-line options. GPM allows users to use the mouse in the console,
  1933. notably to select, copy, and paste text. The default options use the
  1934. @code{ps2} protocol, which works for both USB and PS/2 mice.")))
  1935. (define-deprecated (gpm-service #:key (gpm gpm)
  1936. (options %default-gpm-options))
  1937. gpm-service-type
  1938. "Run @var{gpm}, the general-purpose mouse daemon, with the given
  1939. command-line @var{options}. GPM allows users to use the mouse in the console,
  1940. notably to select, copy, and paste text. The default value of @var{options}
  1941. uses the @code{ps2} protocol, which works for both USB and PS/2 mice.
  1942. This service is not part of @var{%base-services}."
  1943. ;; To test in QEMU, use "-usbdevice mouse" and then, in the monitor, use
  1944. ;; "info mice" and "mouse_set X" to use the right mouse.
  1945. (service gpm-service-type
  1946. (gpm-configuration (gpm gpm) (options options))))
  1947. (define-record-type* <kmscon-configuration>
  1948. kmscon-configuration make-kmscon-configuration
  1949. kmscon-configuration?
  1950. (kmscon kmscon-configuration-kmscon
  1951. (default kmscon))
  1952. (virtual-terminal kmscon-configuration-virtual-terminal)
  1953. (login-program kmscon-configuration-login-program
  1954. (default (file-append shadow "/bin/login")))
  1955. (login-arguments kmscon-configuration-login-arguments
  1956. (default '("-p")))
  1957. (auto-login kmscon-configuration-auto-login
  1958. (default #f))
  1959. (hardware-acceleration? kmscon-configuration-hardware-acceleration?
  1960. (default #f))) ; #t causes failure
  1961. (define kmscon-service-type
  1962. (shepherd-service-type
  1963. 'kmscon
  1964. (lambda (config)
  1965. (let ((kmscon (kmscon-configuration-kmscon config))
  1966. (virtual-terminal (kmscon-configuration-virtual-terminal config))
  1967. (login-program (kmscon-configuration-login-program config))
  1968. (login-arguments (kmscon-configuration-login-arguments config))
  1969. (auto-login (kmscon-configuration-auto-login config))
  1970. (hardware-acceleration? (kmscon-configuration-hardware-acceleration? config)))
  1971. (define kmscon-command
  1972. #~(list
  1973. #$(file-append kmscon "/bin/kmscon") "--login"
  1974. "--vt" #$virtual-terminal
  1975. "--no-switchvt" ;Prevent a switch to the virtual terminal.
  1976. #$@(if hardware-acceleration? '("--hwaccel") '())
  1977. "--login" "--"
  1978. #$login-program #$@login-arguments
  1979. #$@(if auto-login
  1980. #~(#$auto-login)
  1981. #~())))
  1982. (shepherd-service
  1983. (documentation "kmscon virtual terminal")
  1984. (requirement '(user-processes udev dbus-system))
  1985. (provision (list (symbol-append 'term- (string->symbol virtual-terminal))))
  1986. (start #~(make-forkexec-constructor #$kmscon-command))
  1987. (stop #~(make-kill-destructor)))))))
  1988. (define-record-type* <static-networking>
  1989. static-networking make-static-networking
  1990. static-networking?
  1991. (interface static-networking-interface)
  1992. (ip static-networking-ip)
  1993. (netmask static-networking-netmask
  1994. (default #f))
  1995. (gateway static-networking-gateway ;FIXME: doesn't belong here
  1996. (default #f))
  1997. (provision static-networking-provision
  1998. (default #f))
  1999. (requirement static-networking-requirement
  2000. (default '()))
  2001. (name-servers static-networking-name-servers ;FIXME: doesn't belong here
  2002. (default '())))
  2003. (define static-networking-shepherd-service
  2004. (match-lambda
  2005. (($ <static-networking> interface ip netmask gateway provision
  2006. requirement name-servers)
  2007. (let ((loopback? (and provision (memq 'loopback provision))))
  2008. (shepherd-service
  2009. (documentation
  2010. "Bring up the networking interface using a static IP address.")
  2011. (requirement requirement)
  2012. (provision (or provision
  2013. (list (symbol-append 'networking-
  2014. (string->symbol interface)))))
  2015. (start #~(lambda _
  2016. ;; Return #t if successfully started.
  2017. (let* ((addr (inet-pton AF_INET #$ip))
  2018. (sockaddr (make-socket-address AF_INET addr 0))
  2019. (mask (and #$netmask
  2020. (inet-pton AF_INET #$netmask)))
  2021. (maskaddr (and mask
  2022. (make-socket-address AF_INET
  2023. mask 0)))
  2024. (gateway (and #$gateway
  2025. (inet-pton AF_INET #$gateway)))
  2026. (gatewayaddr (and gateway
  2027. (make-socket-address AF_INET
  2028. gateway 0))))
  2029. (configure-network-interface #$interface sockaddr
  2030. (logior IFF_UP
  2031. #$(if loopback?
  2032. #~IFF_LOOPBACK
  2033. 0))
  2034. #:netmask maskaddr)
  2035. (when gateway
  2036. (let ((sock (socket AF_INET SOCK_DGRAM 0)))
  2037. (add-network-route/gateway sock gatewayaddr)
  2038. (close-port sock))))))
  2039. (stop #~(lambda _
  2040. ;; Return #f is successfully stopped.
  2041. (let ((sock (socket AF_INET SOCK_STREAM 0)))
  2042. (when #$gateway
  2043. (delete-network-route sock
  2044. (make-socket-address
  2045. AF_INET INADDR_ANY 0)))
  2046. (set-network-interface-flags sock #$interface 0)
  2047. (close-port sock)
  2048. #f)))
  2049. (respawn? #f))))))
  2050. (define (static-networking-etc-files interfaces)
  2051. "Return a /etc/resolv.conf entry for INTERFACES or the empty list."
  2052. (match (delete-duplicates
  2053. (append-map static-networking-name-servers
  2054. interfaces))
  2055. (()
  2056. '())
  2057. ((name-servers ...)
  2058. (let ((content (string-join
  2059. (map (cut string-append "nameserver " <>)
  2060. name-servers)
  2061. "\n" 'suffix)))
  2062. `(("resolv.conf"
  2063. ,(plain-file "resolv.conf"
  2064. (string-append "\
  2065. # Generated by 'static-networking-service'.\n"
  2066. content))))))))
  2067. (define (static-networking-shepherd-services interfaces)
  2068. "Return the list of Shepherd services to bring up INTERFACES, a list of
  2069. <static-networking> objects."
  2070. (define (loopback? service)
  2071. (memq 'loopback (shepherd-service-provision service)))
  2072. (let ((services (map static-networking-shepherd-service interfaces)))
  2073. (match (remove loopback? services)
  2074. (()
  2075. ;; There's no interface other than 'loopback', so we assume that the
  2076. ;; 'networking' service will be provided by dhclient or similar.
  2077. services)
  2078. ((non-loopback ...)
  2079. ;; Assume we're providing all the interfaces, and thus, provide a
  2080. ;; 'networking' service.
  2081. (cons (shepherd-service
  2082. (provision '(networking))
  2083. (requirement (append-map shepherd-service-provision
  2084. services))
  2085. (start #~(const #t))
  2086. (stop #~(const #f))
  2087. (documentation "Bring up all the networking interfaces."))
  2088. services)))))
  2089. (define static-networking-service-type
  2090. ;; The service type for statically-defined network interfaces.
  2091. (service-type (name 'static-networking)
  2092. (extensions
  2093. (list
  2094. (service-extension shepherd-root-service-type
  2095. static-networking-shepherd-services)
  2096. (service-extension etc-service-type
  2097. static-networking-etc-files)))
  2098. (compose concatenate)
  2099. (extend append)
  2100. (description
  2101. "Turn up the specified network interfaces upon startup,
  2102. with the given IP address, gateway, netmask, and so on. The value for
  2103. services of this type is a list of @code{static-networking} objects, one per
  2104. network interface.")))
  2105. (define* (static-networking-service interface ip
  2106. #:key
  2107. netmask gateway provision
  2108. ;; Most interfaces require udev to be usable.
  2109. (requirement '(udev))
  2110. (name-servers '()))
  2111. "Return a service that starts @var{interface} with address @var{ip}. If
  2112. @var{netmask} is true, use it as the network mask. If @var{gateway} is true,
  2113. it must be a string specifying the default network gateway.
  2114. This procedure can be called several times, one for each network
  2115. interface of interest. Behind the scenes what it does is extend
  2116. @code{static-networking-service-type} with additional network interfaces
  2117. to handle."
  2118. (simple-service 'static-network-interface
  2119. static-networking-service-type
  2120. (list (static-networking (interface interface) (ip ip)
  2121. (netmask netmask) (gateway gateway)
  2122. (provision provision)
  2123. (requirement requirement)
  2124. (name-servers name-servers)))))
  2125. (define %base-services
  2126. ;; Convenience variable holding the basic services.
  2127. (list (service login-service-type)
  2128. (service virtual-terminal-service-type)
  2129. (service console-font-service-type
  2130. (map (lambda (tty)
  2131. (cons tty %default-console-font))
  2132. '("tty1" "tty2" "tty3" "tty4" "tty5" "tty6")))
  2133. (service agetty-service-type (agetty-configuration
  2134. (extra-options '("-L")) ; no carrier detect
  2135. (term "vt100")
  2136. (tty #f))) ; automatic
  2137. (service mingetty-service-type (mingetty-configuration
  2138. (tty "tty1")))
  2139. (service mingetty-service-type (mingetty-configuration
  2140. (tty "tty2")))
  2141. (service mingetty-service-type (mingetty-configuration
  2142. (tty "tty3")))
  2143. (service mingetty-service-type (mingetty-configuration
  2144. (tty "tty4")))
  2145. (service mingetty-service-type (mingetty-configuration
  2146. (tty "tty5")))
  2147. (service mingetty-service-type (mingetty-configuration
  2148. (tty "tty6")))
  2149. (service static-networking-service-type
  2150. (list (static-networking (interface "lo")
  2151. (ip "127.0.0.1")
  2152. (requirement '())
  2153. (provision '(loopback)))))
  2154. (syslog-service)
  2155. (service urandom-seed-service-type)
  2156. (service guix-service-type)
  2157. (service nscd-service-type)
  2158. (service rottlog-service-type)
  2159. ;; The LVM2 rules are needed as soon as LVM2 or the device-mapper is
  2160. ;; used, so enable them by default. The FUSE and ALSA rules are
  2161. ;; less critical, but handy.
  2162. (service udev-service-type
  2163. (udev-configuration
  2164. (rules (list lvm2 fuse alsa-utils crda))))
  2165. (service special-files-service-type
  2166. `(("/bin/sh" ,(file-append bash "/bin/sh"))
  2167. ("/usr/bin/env" ,(file-append coreutils "/bin/env"))))))
  2168. ;;; base.scm ends here