services.scm 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
  3. ;;; Copyright © 2021 Xinglu Chen <public@yoctocell.xyz>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu home services)
  20. #:use-module (gnu services)
  21. #:use-module ((gnu packages package-management) #:select (guix))
  22. #:use-module ((gnu packages base) #:select (coreutils))
  23. #:use-module (guix channels)
  24. #:use-module (guix monads)
  25. #:use-module (guix store)
  26. #:use-module (guix gexp)
  27. #:use-module (guix profiles)
  28. #:use-module (guix sets)
  29. #:use-module (guix ui)
  30. #:use-module (guix discovery)
  31. #:use-module (guix diagnostics)
  32. #:use-module (guix i18n)
  33. #:use-module (guix modules)
  34. #:use-module (srfi srfi-1)
  35. #:use-module (ice-9 match)
  36. #:use-module (ice-9 vlist)
  37. #:export (home-service-type
  38. home-profile-service-type
  39. home-environment-variables-service-type
  40. home-files-service-type
  41. home-xdg-configuration-files-service-type
  42. home-xdg-data-files-service-type
  43. home-run-on-first-login-service-type
  44. home-activation-service-type
  45. home-run-on-change-service-type
  46. home-provenance-service-type
  47. environment-variable-shell-definitions
  48. home-files-directory
  49. xdg-configuration-files-directory
  50. xdg-data-files-directory
  51. fold-home-service-types
  52. lookup-home-service-types
  53. home-provenance
  54. %initialize-gettext)
  55. #:re-export (service
  56. service-type
  57. service-extension))
  58. ;;; Comment:
  59. ;;;
  60. ;;; This module is similar to (gnu system services) module, but
  61. ;;; provides Home Services, which are supposed to be used for building
  62. ;;; home-environment.
  63. ;;;
  64. ;;; Home Services use the same extension as System Services. Consult
  65. ;;; (gnu system services) module or manual for more information.
  66. ;;;
  67. ;;; home-service-type is a root of home services DAG.
  68. ;;;
  69. ;;; home-profile-service-type is almost the same as profile-service-type, at least
  70. ;;; for now.
  71. ;;;
  72. ;;; home-environment-variables-service-type generates a @file{setup-environment}
  73. ;;; shell script, which is expected to be sourced by login shell or other program,
  74. ;;; which starts early and spawns all other processes. Home services for shells
  75. ;;; automatically add code for sourcing this file, if person do not use those home
  76. ;;; services they have to source this script manually in their's shell *profile
  77. ;;; file (details described in the manual).
  78. ;;;
  79. ;;; home-files-service-type is similar to etc-service-type, but doesn't extend
  80. ;;; home-activation, because deploy mechanism for config files is pluggable
  81. ;;; and can be different for different home environments: The default one is
  82. ;;; called symlink-manager, which creates links for various dotfiles and xdg
  83. ;;; configuration files to store, but is possible to implement alternative
  84. ;;; approaches like read-only home from Julien's guix-home-manager.
  85. ;;;
  86. ;;; home-run-on-first-login-service-type provides an @file{on-first-login} guile
  87. ;;; script, which runs provided gexps once, when user makes first login. It can
  88. ;;; be used to start user's Shepherd and maybe some other process. It relies on
  89. ;;; assumption that /run/user/$UID will be created on login by some login
  90. ;;; manager (elogind for example).
  91. ;;;
  92. ;;; home-activation-service-type provides an @file{activate} guile script, which
  93. ;;; do three main things:
  94. ;;;
  95. ;;; - Sets environment variables to the values declared in
  96. ;;; @file{setup-environment} shell script. It's necessary, because user can set
  97. ;;; for example XDG_CONFIG_HOME and it should be respected by activation gexp of
  98. ;;; symlink-manager.
  99. ;;;
  100. ;;; - Sets GUIX_NEW_HOME and possibly GUIX_OLD_HOME vars to paths in the store.
  101. ;;; Later those variables can be used by activation gexps, for example by
  102. ;;; symlink-manager or run-on-change services.
  103. ;;;
  104. ;;; - Run all activation gexps provided by other home services.
  105. ;;;
  106. ;;; home-run-on-change-service-type allows to trigger actions during
  107. ;;; activation if file or directory specified by pattern is changed.
  108. ;;;
  109. ;;; Code:
  110. (define (home-derivation entries mextensions)
  111. "Return as a monadic value the derivation of the 'home'
  112. directory containing the given entries."
  113. (mlet %store-monad ((extensions (mapm/accumulate-builds identity
  114. mextensions)))
  115. (lower-object
  116. (file-union "home" (append entries (concatenate extensions))))))
  117. (define home-service-type
  118. ;; This is the ultimate service type, the root of the home service
  119. ;; DAG. The service of this type is extended by monadic name/item
  120. ;; pairs. These items end up in the "home-environment directory" as
  121. ;; returned by 'home-environment-derivation'.
  122. (service-type (name 'home)
  123. (extensions '())
  124. (compose identity)
  125. (extend home-derivation)
  126. (default-value '())
  127. (description
  128. "Build the home environment top-level directory,
  129. which in turn refers to everything the home environment needs: its
  130. packages, configuration files, activation script, and so on.")))
  131. (define (packages->profile-entry packages)
  132. "Return a system entry for the profile containing PACKAGES."
  133. ;; XXX: 'mlet' is needed here for one reason: to get the proper
  134. ;; '%current-target' and '%current-target-system' bindings when
  135. ;; 'packages->manifest' is called, and thus when the 'package-inputs'
  136. ;; etc. procedures are called on PACKAGES. That way, conditionals in those
  137. ;; inputs see the "correct" value of these two parameters. See
  138. ;; <https://issues.guix.gnu.org/44952>.
  139. (mlet %store-monad ((_ (current-target-system)))
  140. (return `(("profile" ,(profile
  141. (content (packages->manifest
  142. (map identity
  143. ;;(options->transformation transformations)
  144. (delete-duplicates packages eq?))))))))))
  145. ;; MAYBE: Add a list of transformations for packages. It's better to
  146. ;; place it in home-profile-service-type to affect all profile
  147. ;; packages and prevent conflicts, when other packages relies on
  148. ;; non-transformed version of package.
  149. (define home-profile-service-type
  150. (service-type (name 'home-profile)
  151. (extensions
  152. (list (service-extension home-service-type
  153. packages->profile-entry)))
  154. (compose concatenate)
  155. (extend append)
  156. (description
  157. "This is the @dfn{home profile} and can be found in
  158. @file{~/.guix-home/profile}. It contains packages and
  159. configuration files that the user has declared in their
  160. @code{home-environment} record.")))
  161. (define (environment-variable-shell-definitions variables)
  162. "Return a gexp that evaluates to a list of POSIX shell statements defining
  163. VARIABLES, a list of environment variable name/value pairs. The returned code
  164. ensures variable values are properly quoted."
  165. #~(let ((shell-quote
  166. (lambda (value)
  167. ;; Double-quote VALUE, leaving dollar sign as is.
  168. (let ((quoted (list->string
  169. (string-fold-right
  170. (lambda (chr lst)
  171. (case chr
  172. ((#\" #\\)
  173. (append (list chr #\\) lst))
  174. (else (cons chr lst))))
  175. '()
  176. value))))
  177. (string-append "\"" quoted "\"")))))
  178. (string-append
  179. #$@(map (match-lambda
  180. ((key . #f)
  181. "")
  182. ((key . #t)
  183. #~(string-append "export " #$key "\n"))
  184. ((key . value)
  185. #~(string-append "export " #$key "="
  186. (shell-quote #$value) "\n")))
  187. variables))))
  188. (define (environment-variables->setup-environment-script vars)
  189. "Return a file that can be sourced by a POSIX compliant shell which
  190. initializes the environment. The file will source the home
  191. environment profile, set some default environment variables, and set
  192. environment variables provided in @code{vars}. @code{vars} is a list
  193. of pairs (@code{(key . value)}), @code{key} is a string and
  194. @code{value} is a string or gexp.
  195. If value is @code{#f} variable will be omitted.
  196. If value is @code{#t} variable will be just exported.
  197. For any other, value variable will be set to the @code{value} and
  198. exported."
  199. (define (warn-about-duplicate-definitions)
  200. (fold
  201. (lambda (x acc)
  202. (when (equal? (car x) (car acc))
  203. (warning
  204. (G_ "duplicate definition for `~a' environment variable ~%") (car x)))
  205. x)
  206. (cons "" "")
  207. (sort vars (lambda (a b)
  208. (string<? (car a) (car b))))))
  209. (warn-about-duplicate-definitions)
  210. (with-monad
  211. %store-monad
  212. (return
  213. `(("setup-environment"
  214. ;; TODO: It's necessary to source ~/.guix-profile too
  215. ;; on foreign distros
  216. ,(computed-file "setup-environment"
  217. #~(call-with-output-file #$output
  218. (lambda (port)
  219. (set-port-encoding! port "UTF-8")
  220. (display "\
  221. HOME_ENVIRONMENT=$HOME/.guix-home
  222. GUIX_PROFILE=\"$HOME_ENVIRONMENT/profile\"
  223. PROFILE_FILE=\"$HOME_ENVIRONMENT/profile/etc/profile\"
  224. [ -f $PROFILE_FILE ] && . $PROFILE_FILE
  225. case $XDG_DATA_DIRS in
  226. *$HOME_ENVIRONMENT/profile/share*) ;;
  227. *) export XDG_DATA_DIRS=$HOME_ENVIRONMENT/profile/share:$XDG_DATA_DIRS ;;
  228. esac
  229. case $MANPATH in
  230. *$HOME_ENVIRONMENT/profile/share/man*) ;;
  231. *) export MANPATH=$HOME_ENVIRONMENT/profile/share/man:$MANPATH
  232. esac
  233. case $INFOPATH in
  234. *$HOME_ENVIRONMENT/profile/share/info*) ;;
  235. *) export INFOPATH=$HOME_ENVIRONMENT/profile/share/info:$INFOPATH ;;
  236. esac
  237. case $XDG_CONFIG_DIRS in
  238. *$HOME_ENVIRONMENT/profile/etc/xdg*) ;;
  239. *) export XDG_CONFIG_DIRS=$HOME_ENVIRONMENT/profile/etc/xdg:$XDG_CONFIG_DIRS ;;
  240. esac
  241. case $XCURSOR_PATH in
  242. *$HOME_ENVIRONMENT/profile/share/icons*) ;;
  243. *) export XCURSOR_PATH=$HOME_ENVIRONMENT/profile/share/icons:$XCURSOR_PATH ;;
  244. esac
  245. " port)
  246. (display
  247. #$(environment-variable-shell-definitions vars)
  248. port)))))))))
  249. (define home-environment-variables-service-type
  250. (service-type (name 'home-environment-variables)
  251. (extensions
  252. (list (service-extension
  253. home-service-type
  254. environment-variables->setup-environment-script)))
  255. (compose concatenate)
  256. (extend append)
  257. (default-value '())
  258. (description "Set the environment variables.")))
  259. (define (files->files-directory files)
  260. "Return a @code{files} directory that contains FILES."
  261. (define (assert-no-duplicates files)
  262. (let loop ((files files)
  263. (seen (set)))
  264. (match files
  265. (() #t)
  266. (((file _) rest ...)
  267. (when (set-contains? seen file)
  268. (raise (formatted-message (G_ "duplicate '~a' entry for files/")
  269. file)))
  270. (loop rest (set-insert file seen))))))
  271. ;; Detect duplicates early instead of letting them through, eventually
  272. ;; leading to a build failure of "files.drv".
  273. (assert-no-duplicates files)
  274. (file-union "files" files))
  275. ;; Used by symlink-manager
  276. (define home-files-directory "files")
  277. (define (files-entry files)
  278. "Return an entry for the @file{~/.guix-home/files}
  279. directory containing FILES."
  280. (with-monad %store-monad
  281. (return `((,home-files-directory ,(files->files-directory files))))))
  282. (define home-files-service-type
  283. (service-type (name 'home-files)
  284. (extensions
  285. (list (service-extension home-service-type
  286. files-entry)))
  287. (compose concatenate)
  288. (extend append)
  289. (default-value '())
  290. (description "Files that will be put in
  291. @file{~~/.guix-home/files}, and further processed during activation.")))
  292. (define xdg-configuration-files-directory ".config")
  293. (define (xdg-configuration-files files)
  294. "Add .config/ prefix to each file-path in FILES."
  295. (map (match-lambda
  296. ((file-path . rest)
  297. (cons (string-append xdg-configuration-files-directory "/" file-path)
  298. rest)))
  299. files))
  300. (define home-xdg-configuration-files-service-type
  301. (service-type (name 'home-xdg-configuration)
  302. (extensions
  303. (list (service-extension home-files-service-type
  304. xdg-configuration-files)))
  305. (compose concatenate)
  306. (extend append)
  307. (default-value '())
  308. (description "Files that will be put in
  309. @file{~~/.guix-home/files/.config}, and further processed during activation.")))
  310. (define xdg-data-files-directory ".local/share")
  311. (define (xdg-data-files files)
  312. "Add .local/share prefix to each file-path in FILES."
  313. (map (match-lambda
  314. ((file-path . rest)
  315. (cons (string-append xdg-data-files-directory "/" file-path)
  316. rest)))
  317. files))
  318. (define home-xdg-data-files-service-type
  319. (service-type (name 'home-xdg-data)
  320. (extensions
  321. (list (service-extension home-files-service-type
  322. xdg-data-files)))
  323. (compose concatenate)
  324. (extend append)
  325. (default-value '())
  326. (description "Files that will be put in
  327. @file{~~/.guix-home/files/.local/share}, and further processed during
  328. activation.")))
  329. (define %initialize-gettext
  330. #~(begin
  331. (bindtextdomain %gettext-domain
  332. (string-append #$guix "/share/locale"))
  333. (textdomain %gettext-domain)))
  334. (define (compute-on-first-login-script _ gexps)
  335. (program-file
  336. "on-first-login"
  337. (with-imported-modules (source-module-closure '((guix i18n)
  338. (guix diagnostics)))
  339. #~(begin
  340. (use-modules (guix i18n)
  341. (guix diagnostics))
  342. #$%initialize-gettext
  343. (let* ((xdg-runtime-dir (or (getenv "XDG_RUNTIME_DIR")
  344. (format #f "/run/user/~a" (getuid))))
  345. (flag-file-path (string-append
  346. xdg-runtime-dir "/on-first-login-executed"))
  347. (touch (lambda (file-name)
  348. (call-with-output-file file-name (const #t)))))
  349. ;; XDG_RUNTIME_DIR dissapears on logout, that means such trick
  350. ;; allows to launch on-first-login script on first login only
  351. ;; after complete logout/reboot.
  352. (if (file-exists? xdg-runtime-dir)
  353. (unless (file-exists? flag-file-path)
  354. (begin #$@gexps (touch flag-file-path)))
  355. ;; TRANSLATORS: 'on-first-login' is the name of a service and
  356. ;; shouldn't be translated
  357. (warning (G_ "XDG_RUNTIME_DIR doesn't exists, on-first-login script
  358. won't execute anything. You can check if xdg runtime directory exists,
  359. XDG_RUNTIME_DIR variable is set to appropriate value and manually execute the
  360. script by running '$HOME/.guix-home/on-first-login'"))))))))
  361. (define (on-first-login-script-entry on-first-login)
  362. "Return, as a monadic value, an entry for the on-first-login script
  363. in the home environment directory."
  364. (with-monad %store-monad
  365. (return `(("on-first-login" ,on-first-login)))))
  366. (define home-run-on-first-login-service-type
  367. (service-type (name 'home-run-on-first-login)
  368. (extensions
  369. (list (service-extension
  370. home-service-type
  371. on-first-login-script-entry)))
  372. (compose identity)
  373. (extend compute-on-first-login-script)
  374. (default-value #f)
  375. (description "Run gexps on first user login. Can be
  376. extended with one gexp.")))
  377. (define (compute-activation-script init-gexp gexps)
  378. (gexp->script
  379. "activate"
  380. #~(let* ((he-init-file (lambda (he) (string-append he "/setup-environment")))
  381. (he-path (string-append (getenv "HOME") "/.guix-home"))
  382. (new-home-env (getenv "GUIX_NEW_HOME"))
  383. (new-home (or new-home-env
  384. ;; Absolute path of the directory of the activation
  385. ;; file if called interactively.
  386. (canonicalize-path (dirname (car (command-line))))))
  387. (old-home-env (getenv "GUIX_OLD_HOME"))
  388. (old-home (or old-home-env
  389. (if (file-exists? (he-init-file he-path))
  390. (readlink he-path)
  391. #f))))
  392. (if (file-exists? (he-init-file new-home))
  393. (let* ((port ((@ (ice-9 popen) open-input-pipe)
  394. (format #f "source ~a && ~a -0"
  395. (he-init-file new-home)
  396. #$(file-append coreutils "/bin/env"))))
  397. (result ((@ (ice-9 rdelim) read-delimited) "" port))
  398. (vars (map (lambda (x)
  399. (let ((si (string-index x #\=)))
  400. (cons (string-take x si)
  401. (string-drop x (1+ si)))))
  402. ((@ (srfi srfi-1) remove)
  403. string-null?
  404. (string-split result #\nul)))))
  405. (close-port port)
  406. (map (lambda (x) (setenv (car x) (cdr x))) vars)
  407. (setenv "GUIX_NEW_HOME" new-home)
  408. (setenv "GUIX_OLD_HOME" old-home)
  409. #$@gexps
  410. ;; Do not unset env variable if it was set outside.
  411. (unless new-home-env (setenv "GUIX_NEW_HOME" #f))
  412. (unless old-home-env (setenv "GUIX_OLD_HOME" #f)))
  413. (format #t "\
  414. Activation script was either called or loaded by file from this directory:
  415. ~a
  416. It doesn't seem that home environment is somewhere around.
  417. Make sure that you call ./activate by symlink from -home store item.\n"
  418. new-home)))))
  419. (define (activation-script-entry m-activation)
  420. "Return, as a monadic value, an entry for the activation script
  421. in the home environment directory."
  422. (mlet %store-monad ((activation m-activation))
  423. (return `(("activate" ,activation)))))
  424. (define home-activation-service-type
  425. (service-type (name 'home-activation)
  426. (extensions
  427. (list (service-extension
  428. home-service-type
  429. activation-script-entry)))
  430. (compose identity)
  431. (extend compute-activation-script)
  432. (default-value #f)
  433. (description "Run gexps to activate the current
  434. generation of home environment and update the state of the home
  435. directory. @command{activate} script automatically called during
  436. reconfiguration or generation switching. This service can be extended
  437. with one gexp, but many times, and all gexps must be idempotent.")))
  438. ;;;
  439. ;;; On-change.
  440. ;;;
  441. (define (compute-on-change-gexp eval-gexps? pattern-gexp-tuples)
  442. (with-imported-modules (source-module-closure '((guix i18n)))
  443. #~(begin
  444. (use-modules (guix i18n))
  445. #$%initialize-gettext
  446. (define (equal-regulars? file1 file2)
  447. "Check if FILE1 and FILE2 are bit for bit identical."
  448. (let* ((cmp-binary #$(file-append
  449. (@ (gnu packages base) diffutils) "/bin/cmp"))
  450. (stats1 (lstat file1))
  451. (stats2 (lstat file2)))
  452. (cond
  453. ((= (stat:ino stats1) (stat:ino stats2)) #t)
  454. ((not (= (stat:size stats1) (stat:size stats2))) #f)
  455. (else (= (system* cmp-binary file1 file2) 0)))))
  456. (define (equal-symlinks? symlink1 symlink2)
  457. "Check if SYMLINK1 and SYMLINK2 are pointing to the same target."
  458. (string=? (readlink symlink1) (readlink symlink2)))
  459. (define (equal-directories? dir1 dir2)
  460. "Check if DIR1 and DIR2 have the same content."
  461. (define (ordinary-file file)
  462. (not (or (string=? file ".")
  463. (string=? file ".."))))
  464. (let* ((files1 (scandir dir1 ordinary-file))
  465. (files2 (scandir dir2 ordinary-file)))
  466. (if (equal? files1 files2)
  467. (map (lambda (file)
  468. (equal-files?
  469. (string-append dir1 "/" file)
  470. (string-append dir2 "/" file)))
  471. files1)
  472. #f)))
  473. (define (equal-files? file1 file2)
  474. "Compares files, symlinks or directories of the same type."
  475. (case (file-type file1)
  476. ((directory) (equal-directories? file1 file2))
  477. ((symlink) (equal-symlinks? file1 file2))
  478. ((regular) (equal-regulars? file1 file2))
  479. (else
  480. (display "The file type is unsupported by on-change service.\n")
  481. #f)))
  482. (define (file-type file)
  483. (stat:type (lstat file)))
  484. (define (something-changed? file1 file2)
  485. (cond
  486. ((and (not (file-exists? file1))
  487. (not (file-exists? file2))) #f)
  488. ((or (not (file-exists? file1))
  489. (not (file-exists? file2))) #t)
  490. ((not (eq? (file-type file1) (file-type file2))) #t)
  491. (else
  492. (not (equal-files? file1 file2)))))
  493. (define expressions-to-eval
  494. (map
  495. (lambda (x)
  496. (let* ((file1 (string-append
  497. (or (getenv "GUIX_OLD_HOME")
  498. "/gnu/store/non-existing-generation")
  499. "/" (car x)))
  500. (file2 (string-append (getenv "GUIX_NEW_HOME") "/" (car x)))
  501. (_ (format #t (G_ "Comparing ~a and\n~10t~a...") file1 file2))
  502. (any-changes? (something-changed? file1 file2))
  503. (_ (format #t (G_ " done (~a)\n")
  504. (if any-changes? "changed" "same"))))
  505. (if any-changes? (cadr x) "")))
  506. '#$pattern-gexp-tuples))
  507. (if #$eval-gexps?
  508. (begin
  509. ;;; TRANSLATORS: 'on-change' is the name of a service type, it
  510. ;;; probably shouldn't be translated.
  511. (display (G_ "Evaluating on-change gexps.\n\n"))
  512. (for-each primitive-eval expressions-to-eval)
  513. (display (G_ "On-change gexps evaluation finished.\n\n")))
  514. (display "\
  515. On-change gexps won't be evaluated; evaluation has been disabled in the
  516. service configuration")))))
  517. (define home-run-on-change-service-type
  518. (service-type (name 'home-run-on-change)
  519. (extensions
  520. (list (service-extension
  521. home-activation-service-type
  522. identity)))
  523. (compose concatenate)
  524. (extend compute-on-change-gexp)
  525. (default-value #t)
  526. (description "\
  527. G-expressions to run if the specified files have changed since the
  528. last generation. The extension should be a list of lists where the
  529. first element is the pattern for file or directory that expected to be
  530. changed, and the second element is the G-expression to be evaluated.")))
  531. ;;;
  532. ;;; Provenance tracking.
  533. ;;;
  534. (define home-provenance-service-type
  535. (service-type
  536. (name 'home-provenance)
  537. (extensions
  538. (list (service-extension
  539. home-service-type
  540. (service-extension-compute
  541. (first (service-type-extensions provenance-service-type))))))
  542. (default-value #f) ;the HE config file
  543. (description "\
  544. Store provenance information about the home environment in the home
  545. environment itself: the channels used when building the home
  546. environment, and its configuration file, when available.")))
  547. (define sexp->home-provenance sexp->system-provenance)
  548. (define home-provenance system-provenance)
  549. ;;;
  550. ;;; Searching
  551. ;;;
  552. (define (parent-directory directory)
  553. "Get the parent directory of DIRECTORY"
  554. (string-join (drop-right (string-split directory #\/) 1) "/"))
  555. (define %guix-home-root-directory
  556. ;; Absolute file name of the module hierarchy.
  557. (parent-directory
  558. (dirname (dirname (search-path %load-path "gnu/home/services.scm")))))
  559. (define %service-type-path
  560. ;; Search path for service types.
  561. (make-parameter `((,%guix-home-root-directory . "gnu/home/services"))))
  562. (define (all-home-service-modules)
  563. "Return the default set of `home service' modules."
  564. (cons (resolve-interface '(gnu home services))
  565. (all-modules (%service-type-path)
  566. #:warn warn-about-load-error)))
  567. (define* (fold-home-service-types proc seed)
  568. (fold-service-types proc seed (all-home-service-modules)))
  569. (define lookup-home-service-types
  570. (let ((table
  571. (delay (fold-home-service-types (lambda (type result)
  572. (vhash-consq (service-type-name type)
  573. type result))
  574. vlist-null))))
  575. (lambda (name)
  576. "Return the list of services with the given NAME (a symbol)."
  577. (vhash-foldq* cons '() name (force table)))))