summary refs log tree commit diff
path: root/gnu/system/shadow.scm
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2013-09-26 22:02:02 +0200
committerLudovic Courtès <ludo@gnu.org>2013-09-27 00:46:17 +0200
commit16a0e9dc3449fb9de699486ad6db2c0bc62b616b (patch)
tree68c50558d0ee89b6c9f02e1fd3838f444b111ae7 /gnu/system/shadow.scm
parentbacadb026c4e9ab75902933954d5cedd17a74537 (diff)
downloadguix-16a0e9dc3449fb9de699486ad6db2c0bc62b616b.tar.gz
gnu: shadow: Add record type for user groups.
* gnu/system/shadow.scm (<user-group>): New record type.
  (group-file): New procedure.
* gnu/system/vm.scm (system-qemu-image): Use it.
Diffstat (limited to 'gnu/system/shadow.scm')
-rw-r--r--gnu/system/shadow.scm35
1 files changed, 34 insertions, 1 deletions
diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm
index c748596431..b2a2121b08 100644
--- a/gnu/system/shadow.scm
+++ b/gnu/system/shadow.scm
@@ -30,7 +30,15 @@
             user-account-home-directory
             user-account-shell
 
-            passwd-file))
+            user-group
+            user-group?
+            user-group-name
+            user-group-password
+            user-group-id
+            user-group-members
+
+            passwd-file
+            group-file))
 
 ;;; Commentary:
 ;;;
@@ -49,6 +57,31 @@
   (home-directory user-account-home-directory)
   (shell          user-account-shell (default "/bin/sh")))
 
+(define-record-type* <user-group>
+  user-group make-user-group
+  user-group?
+  (name           user-group-name)
+  (password       user-group-password (default #f))
+  (id             user-group-id)
+  (members        user-group-members (default '())))
+
+(define (group-file store groups)
+  "Return a /etc/group file for GROUPS, a list of <user-group> objects."
+  (define contents
+    (let loop ((groups groups)
+               (result '()))
+      (match groups
+        ((($ <user-group> name _ gid (users ...)) rest ...)
+         ;; XXX: Ignore the group password.
+         (loop rest
+               (cons (string-append name "::" (number->string gid)
+                                    ":" (string-join users ","))
+                     result)))
+        (()
+         (string-join (reverse result) "\n" 'suffix)))))
+
+  (add-text-to-store store "group" contents))
+
 (define* (passwd-file store accounts #:key shadow?)
   "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