gnu: samba: Fix corrupted man pages.
[jackhill/guix/guix.git] / gnu / home.scm
CommitLineData
7fcc6425
AT
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2021 Andrew Tropin <andrew@trop.in>
61db74a6 3;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
7fcc6425
AT
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
20(define-module (gnu home)
0e8d2df0 21 #:use-module (gnu home services)
ba8ddb34
OP
22 #:use-module (gnu home services symlink-manager)
23 #:use-module (gnu home services shells)
24 #:use-module (gnu home services xdg)
25 #:use-module (gnu home services fontutils)
7fcc6425
AT
26 #:use-module (gnu services)
27 #:use-module (guix records)
28 #:use-module (guix diagnostics)
ed818c66
AT
29 #:use-module (guix gexp)
30 #:use-module (guix store)
61db74a6
LC
31 #:use-module (ice-9 match)
32 #:use-module (ice-9 regex)
7fcc6425
AT
33 #:export (home-environment
34 home-environment?
35 this-home-environment
36
37 home-environment-derivation
38 home-environment-user-services
39 home-environment-essential-services
40 home-environment-services
41 home-environment-location
42
61db74a6
LC
43 home-environment-with-provenance
44
45 home-generation-base))
7fcc6425 46
994c66bf
AT
47;;; Comment:
48;;;
49;;; This module provides a <home-environment> record for managing
50;;; per-user packages and configuration files in the similar way as
51;;; <operating-system> do for system packages and configuration files.
52;;;
53;;; Code:
54
7fcc6425
AT
55(define-record-type* <home-environment> home-environment
56 make-home-environment
57 home-environment?
58 this-home-environment
59
60 (packages home-environment-packages ; list of (PACKAGE OUTPUT...)
61 (default '()))
62
63 (essential-services home-environment-essential-services ; list of services
64 (thunked)
65 (default (home-environment-default-essential-services
66 this-home-environment)))
67
68 (services home-environment-user-services
69 (default '()))
70
71 (location home-environment-location ; <location>
72 (default (and=> (current-source-location)
73 source-properties->location))
74 (innate)))
75
76(define (home-environment-default-essential-services he)
77 "Return the list of essential services for home environment."
78 (list
79 (service home-run-on-first-login-service-type)
80 (service home-activation-service-type)
81 (service home-environment-variables-service-type)
82
83 (service home-symlink-manager-service-type)
84
85 (service home-fontconfig-service-type)
86 (service home-xdg-base-directories-service-type)
87 (service home-shell-profile-service-type)
88
89 (service home-service-type)
90 (service home-profile-service-type (home-environment-packages he))))
91
92(define* (home-environment-services he)
93 "Return all the services of home environment."
94 (instantiate-missing-services
95 (append (home-environment-user-services he)
96 (home-environment-essential-services he))))
97
98(define* (home-environment-derivation he)
e60ba7eb 99 "Return a derivation that builds home environment."
7fcc6425
AT
100 (let* ((services (home-environment-services he))
101 (home (fold-services services
102 #:target-type home-service-type)))
103 (service-value home)))
104
105(define* (home-environment-with-provenance he config-file)
106 "Return a variant of HE that stores its own provenance information,
107including CONFIG-FILE, if available. This is achieved by adding an instance
108of HOME-PROVENANCE-SERVICE-TYPE to its services."
109 (home-environment
110 (inherit he)
111 (services (cons (service home-provenance-service-type config-file)
112 (home-environment-user-services he)))))
ed818c66
AT
113
114(define-gexp-compiler (home-environment-compiler (he <home-environment>)
115 system target)
116 ((store-lift
117 (lambda (store)
118 (run-with-store store (home-environment-derivation he)
119 #:system system
120 #:target target)))))
61db74a6
LC
121
122(define %profile-generation-rx
123 ;; Regexp that matches profile generation.
124 (make-regexp "(.*)-([0-9]+)-link$"))
125
126(define (home-generation-base file)
127 "If FILE is a Home generation GC root such as \"guix-home-42-link\",
128return its corresponding base---e.g., \"guix-home\". Otherwise return #f.
129
130This is similar to the 'generation-profile' procedure but applied to Home
131generations."
132 (match (regexp-exec %profile-generation-rx file)
133 (#f #f)
134 (m (let ((profile (match:substring m 1)))
135 ;; Distinguish from a "real" profile and from a system generation.
136 (and (file-exists? (string-append profile "/on-first-login"))
137 (file-exists? (string-append profile "/profile/manifest"))
138 profile)))))