summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-09-26 21:52:39 +0200
committerLudovic Courtès <ludo@gnu.org>2013-09-27 00:46:17 +0200
commitbacadb026c4e9ab75902933954d5cedd17a74537 (patch)
tree9a38e6a5e7cc951429170b1785e76b10b8e64b99
parentc773aba8708e85a4bbd2415fefe0fb8f48b9c8d1 (diff)
gnu: shadow: Add record type for user accounts.
* gnu/system/shadow.scm (<user-account>): New record type. (passwd-file): Use it. * gnu/system/vm.scm (system-qemu-image): Adjust accordingly.
-rw-r--r--gnu/system/shadow.scm33
-rw-r--r--gnu/system/vm.scm9
2 files changed, 35 insertions, 7 deletions
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index 71f8e0d771..c748596431 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -19,7 +19,18 @@
(define-module (gnu system shadow)
#:use-module (guix store)
#:use-module (ice-9 match)
- #:export (passwd-file))
+ #:use-module (guix records)
+ #:export (user-account
+ user-account?
+ user-account-name
+ user-account-pass
+ user-account-uid
+ user-account-gid
+ user-account-comment
+ user-account-home-directory
+ user-account-shell
+
+ passwd-file))
;;; Commentary:
;;;
@@ -27,16 +38,28 @@
;;;
;;; Code:
+(define-record-type* <user-account>
+ user-account make-user-account
+ user-account?
+ (name user-account-name)
+ (password user-account-pass (default ""))
+ (uid user-account-uid)
+ (gid user-account-gid)
+ (comment user-account-comment (default ""))
+ (home-directory user-account-home-directory)
+ (shell user-account-shell (default "/bin/sh")))
+
(define* (passwd-file store accounts #:key shadow?)
- "Return a password file for ACCOUNTS, a list of vectors as returned by
-'getpwnam'. If SHADOW? is true, then it is a /etc/shadow file, otherwise it
-is a /etc/passwd file."
+ "Return a password file for ACCOUNTS, a list of <user-account> objects. If
+SHADOW? is true, then it is a /etc/shadow file, otherwise it is a /etc/passwd
+file."
;; XXX: The resulting file is world-readable, so beware when SHADOW? is #t!
(define contents
(let loop ((accounts accounts)
(result '()))
(match accounts
- ((#(name pass uid gid comment home-dir shell) rest ...)
+ ((($ <user-account> name pass uid gid comment home-dir shell)
+ rest ...)
(loop rest
(cons (if shadow?
(string-append name
diff --git a/gnu/system/vm.scm b/gnu/system/vm.scm
index 72530e3809..ce15ace617 100644
--- a/gnu/system/vm.scm
+++ b/gnu/system/vm.scm
@@ -475,8 +475,13 @@ Happy birthday, GNU! http://www.gnu.org/gnu30
(dmd-file (string-append (derivation->output-path dmd-drv)
"/bin/dmd"))
(dmd-conf (dmd-configuration-file store %dmd-services))
- (accounts (list (vector "root" "" 0 0 "System administrator"
- "/" bash-file)))
+ (accounts (list (user-account
+ (name "root")
+ (password "")
+ (uid 0) (gid 0)
+ (comment "System administrator")
+ (home-directory "/")
+ (shell bash-file))))
(passwd (passwd-file store accounts))
(shadow (passwd-file store accounts #:shadow? #t))
(group (add-text-to-store store "group"