From d9f0a23704a038640329fae6e2273e5813cdb8ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20Court=C3=A8s?= Date: Thu, 3 Oct 2013 21:30:30 +0200 Subject: gnu: vm: Rewrite helper functions as monadic functions. * gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service, syslog-service, guix-service, static-networking-service): Rewrite as monadic functions. (dmd-configuration-file): Use 'text-file' instead of 'add-text-to-store'. * gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic function. * gnu/system/linux.scm (pam-services->directory): Likewise. * gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts): Likewise. * gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image, union, system-qemu-image): Likewise. --- gnu/system/shadow.scm | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) (limited to 'gnu/system/shadow.scm') diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm index 4f59b2b325..654fd4d55b 100644 --- a/gnu/system/shadow.scm +++ b/gnu/system/shadow.scm @@ -20,6 +20,7 @@ #:use-module (guix store) #:use-module (guix records) #:use-module (guix packages) + #:use-module (guix monads) #:use-module ((gnu packages system) #:select (shadow)) #:use-module (srfi srfi-1) @@ -72,7 +73,7 @@ (id user-group-id) (members user-group-members (default '()))) -(define (group-file store groups) +(define (group-file groups) "Return a /etc/group file for GROUPS, a list of objects." (define contents (let loop ((groups groups) @@ -87,9 +88,9 @@ (() (string-join (reverse result) "\n" 'suffix))))) - (add-text-to-store store "group" contents)) + (text-file "group" contents)) -(define* (passwd-file store accounts #:key shadow?) +(define* (passwd-file accounts #:key shadow?) "Return a password file for ACCOUNTS, a list of objects. If SHADOW? is true, then it is a /etc/shadow file, otherwise it is a /etc/passwd file." @@ -114,28 +115,27 @@ file." (() (string-join (reverse result) "\n" 'suffix))))) - (add-text-to-store store (if shadow? "shadow" "passwd") - contents '())) + (text-file (if shadow? "shadow" "passwd") contents)) -(define* (guix-build-accounts store count #:key +(define* (guix-build-accounts count #:key (first-uid 30001) (gid 30000) (shadow shadow)) "Return a list of COUNT user accounts for Guix build users, with UIDs starting at FIRST-UID, and under GID." - (let* ((gid* gid) - (no-login (string-append (package-output store shadow) "/sbin/nologin"))) - (unfold (cut > <> count) - (lambda (n) - (user-account - (name (format #f "guixbuilder~2,'0d" n)) - (password "!") - (uid (+ first-uid n -1)) - (gid gid*) - (comment (format #f "Guix Build User ~2d" n)) - (home-directory "/var/empty") - (shell no-login))) - 1+ - 1))) + (mlet* %store-monad ((gid* -> gid) + (no-login (package-file shadow "sbin/nologin"))) + (return (unfold (cut > <> count) + (lambda (n) + (user-account + (name (format #f "guixbuilder~2,'0d" n)) + (password "!") + (uid (+ first-uid n -1)) + (gid gid*) + (comment (format #f "Guix Build User ~2d" n)) + (home-directory "/var/empty") + (shell no-login))) + 1+ + 1)))) ;;; shadow.scm ends here -- cgit v1.2.3