1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2013, 2014 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 shadow)
20 #:use-module (guix records)
21 #:use-module (guix gexp)
22 #:use-module (guix monads)
23 #:use-module ((gnu system file-systems)
25 #:use-module ((gnu packages admin)
27 #:use-module (gnu packages bash)
28 #:use-module (gnu packages guile-wm)
29 #:export (user-account
35 user-account-supplementary-groups
37 user-account-home-directory
54 ;;; Utilities for configuring the Shadow tool suite ('login', 'passwd', etc.)
58 (define-record-type* <user-account>
59 user-account make-user-account
61 (name user-account-name)
62 (password user-account-password (default #f))
63 (uid user-account-uid (default #f))
64 (group user-account-group) ; number | string
65 (supplementary-groups user-account-supplementary-groups
66 (default '())) ; list of strings
67 (comment user-account-comment (default ""))
68 (home-directory user-account-home-directory)
69 (shell user-account-shell ; gexp
70 (default #~(string-append #$bash "/bin/bash")))
71 (system? user-account-system? ; Boolean
74 (define-record-type* <user-group>
75 user-group make-user-group
77 (name user-group-name)
78 (password user-group-password (default #f))
79 (id user-group-id (default #f))
80 (system? user-group-system? ; Boolean
84 ;; Default set of groups.
85 (let-syntax ((system-group (syntax-rules ()
87 (user-group (system? #t) args ...)))))
88 (list (system-group (name "root") (id 0))
89 (system-group (name "wheel")) ; root-like users
90 (system-group (name "users")) ; normal users
91 (system-group (name "nogroup")) ; for daemons etc.
93 ;; The following groups are conventionally used by things like udev to
94 ;; control access to hardware devices.
95 (system-group (name "tty") (id %tty-gid))
96 (system-group (name "dialout"))
97 (system-group (name "kmem"))
98 (system-group (name "input")) ; input devices, from udev
99 (system-group (name "video"))
100 (system-group (name "audio"))
101 (system-group (name "netdev")) ; used in avahi-dbus.conf
102 (system-group (name "lp"))
103 (system-group (name "disk"))
104 (system-group (name "floppy"))
105 (system-group (name "cdrom"))
106 (system-group (name "tape"))
107 (system-group (name "kvm"))))) ; for /dev/kvm
109 (define (default-skeletons)
110 "Return the default skeleton files for /etc/skel. These files are copied by
111 'useradd' in the home directory of newly created user accounts."
112 (define copy-guile-wm
114 (use-modules (guix build utils))
115 (copy-file (car (find-files #$guile-wm "wm-init-sample.scm"))
118 (mlet %store-monad ((profile (text-file "bash_profile" "\
119 # Honor per-interactive-shell startup file
120 if [ -f ~/.bashrc ]; then . ~/.bashrc; fi\n"))
121 (bashrc (text-file "bashrc" "\
122 PS1='\\u@\\h \\w\\$ '
123 alias ls='ls -p --color'
124 alias ll='ls -l'\n"))
125 (guile-wm (gexp->derivation "guile-wm" copy-guile-wm
127 '((guix build utils))))
128 (xdefaults (text-file "Xdefaults" "\
130 XTerm*metaSendsEscape: true\n"))
131 (gdbinit (text-file "gdbinit" "\
132 # Tell GDB where to look for separate debugging files.
133 set debug-file-directory ~/.guix-profile/lib/debug\n")))
134 (return `((".bash_profile" ,profile)
136 (".Xdefaults" ,xdefaults)
137 (".guile-wm" ,guile-wm)
138 (".gdbinit" ,gdbinit)))))
140 (define (skeleton-directory skeletons)
141 "Return a directory containing SKELETONS, a list of name/derivation pairs."
142 (gexp->derivation "skel"
144 (use-modules (ice-9 match))
149 ;; Note: copy the skeletons instead of symlinking
150 ;; them like 'file-union' does, because 'useradd'
151 ;; would just copy the symlinks as is.
152 (for-each (match-lambda
154 (copy-file source target)))
158 ;;; shadow.scm ends here