records: Allow thunked fields to refer to 'this-record'.
[jackhill/guix/guix.git] / gnu / system / accounts.scm
CommitLineData
f6f67b87
LC
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu system accounts)
20 #:use-module (guix records)
6061d015 21 #:use-module (ice-9 match)
f6f67b87
LC
22 #:export (user-account
23 user-account?
24 user-account-name
25 user-account-password
26 user-account-uid
27 user-account-group
28 user-account-supplementary-groups
29 user-account-comment
30 user-account-home-directory
31 user-account-create-home-directory?
32 user-account-shell
33 user-account-system?
34
35 user-group
36 user-group?
37 user-group-name
38 user-group-password
39 user-group-id
40 user-group-system?
41
6061d015
LC
42 sexp->user-account
43 sexp->user-group
44
f6f67b87
LC
45 default-shell))
46
47
48;;; Commentary:
49;;;
50;;; Data structures representing user accounts and user groups. This is meant
51;;; to be used both on the host side and at run time--e.g., in activation
52;;; snippets.
53;;;
54;;; Code:
55
56(define default-shell
57 ;; Default shell for user accounts (a string or string-valued gexp).
58 (make-parameter "/bin/sh"))
59
60(define-record-type* <user-account>
61 user-account make-user-account
62 user-account?
63 (name user-account-name)
64 (password user-account-password (default #f))
65 (uid user-account-uid (default #f))
66 (group user-account-group) ; number | string
67 (supplementary-groups user-account-supplementary-groups
68 (default '())) ; list of strings
69 (comment user-account-comment (default ""))
70 (home-directory user-account-home-directory)
71 (create-home-directory? user-account-create-home-directory? ;Boolean
72 (default #t))
73 (shell user-account-shell ; gexp
74 (default (default-shell)))
75 (system? user-account-system? ; Boolean
76 (default #f)))
77
78(define-record-type* <user-group>
79 user-group make-user-group
80 user-group?
81 (name user-group-name)
82 (password user-group-password (default #f))
83 (id user-group-id (default #f))
84 (system? user-group-system? ; Boolean
85 (default #f)))
6061d015
LC
86
87(define (sexp->user-group sexp)
88 "Take SEXP, a tuple as returned by 'user-group->gexp', and turn it into a
89user-group record."
90 (match sexp
91 ((name password id system?)
92 (user-group (name name)
93 (password password)
94 (id id)
95 (system? system?)))))
96
97(define (sexp->user-account sexp)
98 "Take SEXP, a tuple as returned by 'user-account->gexp', and turn it into a
99user-account record."
100 (match sexp
101 ((name uid group supplementary-groups comment home-directory
102 create-home-directory? shell password system?)
103 (user-account (name name) (uid uid) (group group)
104 (supplementary-groups supplementary-groups)
105 (comment comment)
106 (home-directory home-directory)
107 (create-home-directory? create-home-directory?)
108 (shell shell) (password password)
109 (system? system?)))))