unofficial mirror of guix-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: iyzsong@member.fsf.org (宋文武)
To: Alex Kost <alezost@gmail.com>
Cc: guix-devel@gnu.org
Subject: Re: [PATCH 1/3] services: Add 'session-environment-service'.
Date: Thu, 03 Dec 2015 19:59:12 +0800	[thread overview]
Message-ID: <87oae7920f.fsf@member.fsf.org> (raw)
In-Reply-To: <87mvtsheoy.fsf@gmail.com> (Alex Kost's message of "Wed, 02 Dec 2015 21:45:49 +0300")

[-- Attachment #1: Type: text/plain, Size: 749 bytes --]

Alex Kost <alezost@gmail.com> writes:

> 宋文武 (2015-12-02 16:38 +0300) wrote:
>
>> +(define (environment-variables->environment-file vars)
>> +  "Return a file for pam_env(8) that contains environment variables VARS."
>> +  (apply mixed-text-file "environment"
>> +         (fold-right (lambda (pair result)
>> +                       (cons* (car pair) "=" (cdr pair) "\n" result))
>> +                     '() vars)))
>
> Hm, car and cdr.  Wouldn't it be clearer to do it like this:
>
>   (map (match-lambda
>          ((name . value)
>           (string-append name "=" value "\n")))
>        vars)
Yes, match-lambda is more clear, thanks!
(I have to use list instead of string-append so that gexps can work)

Updated:


[-- Attachment #2: services: Add session-environment-service. --]
[-- Type: text/x-patch, Size: 2540 bytes --]

From 0ce1986d4cfca3d40bed4aaf93942cf9caaefb60 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=AE=8B=E6=96=87=E6=AD=A6?= <iyzsong@gmail.com>
Date: Wed, 2 Dec 2015 19:59:29 +0800
Subject: [PATCH] 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.
---
 gnu/services/base.scm | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/gnu/services/base.scm b/gnu/services/base.scm
index c242c7d..a86e8e0 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."
 
 \f
 ;;;
+;;; 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))
+
+\f
+;;;
 ;;; Console & co.
 ;;;
 
-- 
2.5.0


  reply	other threads:[~2015-12-03 11:59 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-12-02 13:38 [PATCH 1/3] services: Add 'session-environment-service' 宋文武
2015-12-02 13:38 ` [PATCH 2/3] system: Add /etc/environment 宋文武
2015-12-04 14:33   ` Ludovic Courtès
2015-12-05  2:55     ` 宋文武
2015-12-02 13:38 ` [PATCH 3/3] system: pam: Honor /etc/environment 宋文武
2015-12-04 14:38   ` Ludovic Courtès
2015-12-02 18:45 ` [PATCH 1/3] services: Add 'session-environment-service' Alex Kost
2015-12-03 11:59   ` 宋文武 [this message]
2015-12-04 14:29     ` Ludovic Courtès

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87oae7920f.fsf@member.fsf.org \
    --to=iyzsong@member.fsf.org \
    --cc=alezost@gmail.com \
    --cc=guix-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).