1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
4 ;;; This file is part of GNU Guix.
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.
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.
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/>.
19 (define-module (gnu system accounts)
20 #:use-module (guix records)
21 #:use-module (ice-9 match)
22 #:export (user-account
28 user-account-supplementary-groups
30 user-account-home-directory
31 user-account-create-home-directory?
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
57 ;; Default shell for user accounts (a string or string-valued gexp).
58 (make-parameter "/bin/sh"))
60 (define-record-type* <user-account>
61 user-account make-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 (thunked)
71 (default (default-home-directory this-record)))
72 (create-home-directory? user-account-create-home-directory? ;Boolean
74 (shell user-account-shell ; gexp
75 (default (default-shell)))
76 (system? user-account-system? ; Boolean
79 (define-record-type* <user-group>
80 user-group make-user-group
82 (name user-group-name)
83 (password user-group-password (default #f))
84 (id user-group-id (default #f))
85 (system? user-group-system? ; Boolean
88 (define (default-home-directory account)
89 "Return the default home directory for ACCOUNT."
90 (string-append "/home/" (user-account-name account)))
92 (define (sexp->user-group sexp)
93 "Take SEXP, a tuple as returned by 'user-group->gexp', and turn it into a
96 ((name password id system?)
97 (user-group (name name)
100 (system? system?)))))
102 (define (sexp->user-account sexp)
103 "Take SEXP, a tuple as returned by 'user-account->gexp', and turn it into a
104 user-account record."
106 ((name uid group supplementary-groups comment home-directory
107 create-home-directory? shell password system?)
108 (user-account (name name) (uid uid) (group group)
109 (supplementary-groups supplementary-groups)
111 (home-directory home-directory)
112 (create-home-directory? create-home-directory?)
113 (shell shell) (password password)
114 (system? system?)))))