Commit | Line | Data |
---|---|---|
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 "")) | |
cf848cc0 LC |
70 | (home-directory user-account-home-directory (thunked) |
71 | (default (default-home-directory this-record))) | |
f6f67b87 LC |
72 | (create-home-directory? user-account-create-home-directory? ;Boolean |
73 | (default #t)) | |
74 | (shell user-account-shell ; gexp | |
75 | (default (default-shell))) | |
76 | (system? user-account-system? ; Boolean | |
77 | (default #f))) | |
78 | ||
79 | (define-record-type* <user-group> | |
80 | user-group make-user-group | |
81 | 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 | |
86 | (default #f))) | |
6061d015 | 87 | |
cf848cc0 LC |
88 | (define (default-home-directory account) |
89 | "Return the default home directory for ACCOUNT." | |
90 | (string-append "/home/" (user-account-name account))) | |
91 | ||
6061d015 LC |
92 | (define (sexp->user-group sexp) |
93 | "Take SEXP, a tuple as returned by 'user-group->gexp', and turn it into a | |
94 | user-group record." | |
95 | (match sexp | |
96 | ((name password id system?) | |
97 | (user-group (name name) | |
98 | (password password) | |
99 | (id id) | |
100 | (system? system?))))) | |
101 | ||
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." | |
105 | (match sexp | |
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) | |
110 | (comment comment) | |
111 | (home-directory home-directory) | |
112 | (create-home-directory? create-home-directory?) | |
113 | (shell shell) (password password) | |
114 | (system? system?))))) |