aboutsummaryrefslogtreecommitdiff
path: root/gnu/services/base.scm
diff options
context:
space:
mode:
author宋文武 <iyzsong@gmail.com>2015-12-02 19:59:29 +0800
committer宋文武 <iyzsong@gmail.com>2015-12-05 10:51:49 +0800
commite10964efd26fdbc3f8b2b5c3a0d359916df1b914 (patch)
tree81b3318c07c42fe9bfa369caa2dc8fa501309f25 /gnu/services/base.scm
parent2aacd9179ca618fe4f3d568caf2052a47b17cbe6 (diff)
downloadguix-e10964efd26fdbc3f8b2b5c3a0d359916df1b914.tar
guix-e10964efd26fdbc3f8b2b5c3a0d359916df1b914.tar.gz
services: Add 'session-environment-service'.
* gnu/services/base.scm (session-environment-service): New procedure. (session-environment-service-type): New variable. (environment-variables->environment-file): New procedure.
Diffstat (limited to 'gnu/services/base.scm')
-rw-r--r--gnu/services/base.scm36
1 files changed, 36 insertions, 0 deletions
diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index c242c7dbb8..a86e8e04c7 100644
--- a/gnu/services/base.scm
+++ b/gnu/services/base.scm
@@ -2,6 +2,7 @@
;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
;;; Copyright © 2015 Alex Kost <alezost@gmail.com>
;;; Copyright © 2015 Mark H Weaver <mhw@netris.org>
+;;; Copyright © 2015 Sou Bunnbu <iyzsong@gmail.com>
;;;
;;; This file is part of GNU Guix.
;;;
@@ -48,6 +49,8 @@
device-mapping-service
swap-service
user-processes-service
+ session-environment-service
+ session-environment-service-type
host-name-service
console-keymap-service
console-font-service
@@ -368,6 +371,39 @@ stopped before 'kill' is called."
;;;
+;;; System-wide environment variables.
+;;;
+
+(define (environment-variables->environment-file vars)
+ "Return a file for pam_env(8) that contains environment variables VARS."
+ (apply mixed-text-file "environment"
+ (append-map (match-lambda
+ ((key . value)
+ (list key "=" value "\n")))
+ vars)))
+
+(define session-environment-service-type
+ (service-type
+ (name 'session-environment)
+ (extensions
+ (list (service-extension
+ etc-service-type
+ (lambda (vars)
+ (list `("environment"
+ ,(environment-variables->environment-file vars)))))))
+ (compose concatenate)
+ (extend append)))
+
+(define (session-environment-service vars)
+ "Return a service that builds the @file{/etc/environment}, which can be read
+by PAM-aware applications to set environment variables for sessions.
+
+VARS should be an association list in which both the keys and the values are
+strings or string-valued gexps."
+ (service session-environment-service-type vars))
+
+
+;;;
;;; Console & co.
;;;