From mboxrd@z Thu Jan 1 00:00:00 1970 From: iyzsong@member.fsf.org (=?utf-8?B?5a6L5paH5q2m?=) Subject: Re: [PATCH 1/3] services: Add 'session-environment-service'. Date: Thu, 03 Dec 2015 19:59:12 +0800 Message-ID: <87oae7920f.fsf@member.fsf.org> References: <1449063511-689-1-git-send-email-iyzsong@gmail.com> <87mvtsheoy.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Return-path: Received: from eggs.gnu.org ([2001:4830:134:3::10]:56539) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4SXw-0000SX-F1 for guix-devel@gnu.org; Thu, 03 Dec 2015 06:59:37 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a4SXs-0005Gh-BT for guix-devel@gnu.org; Thu, 03 Dec 2015 06:59:36 -0500 Received: from smtp16.openmailbox.org ([62.4.1.50]:34814) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a4SXs-0005GN-5G for guix-devel@gnu.org; Thu, 03 Dec 2015 06:59:32 -0500 In-Reply-To: <87mvtsheoy.fsf@gmail.com> (Alex Kost's message of "Wed, 02 Dec 2015 21:45:49 +0300") List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org Sender: guix-devel-bounces+gcggd-guix-devel=m.gmane.org@gnu.org To: Alex Kost Cc: guix-devel@gnu.org --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Alex Kost writes: > =E5=AE=8B=E6=96=87=E6=AD=A6 (2015-12-02 16:38 +0300) wrote: > >> +(define (environment-variables->environment-file vars) >> + "Return a file for pam_env(8) that contains environment variables VAR= S." >> + (apply mixed-text-file "environment" >> + (fold-right (lambda (pair result) >> + (cons* (car pair) "=3D" (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 "=3D" 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: --=-=-= Content-Type: text/x-patch; charset=utf-8 Content-Disposition: inline; filename=0001-services-Add-session-environment-service.patch Content-Transfer-Encoding: quoted-printable Content-Description: services: Add session-environment-service. >From 0ce1986d4cfca3d40bed4aaf93942cf9caaefb60 Mon Sep 17 00:00:00 2001 From: =3D?UTF-8?q?=3DE5=3DAE=3D8B=3DE6=3D96=3D87=3DE6=3DAD=3DA6?=3D 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 =C2=A9 2013, 2014, 2015 Ludovic Court=C3=A8s ;;; Copyright =C2=A9 2015 Alex Kost ;;; Copyright =C2=A9 2015 Mark H Weaver +;;; Copyright =C2=A9 2015 Sou Bunnbu ;;; ;;; 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." =20 ;;; +;;; 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 "=3D" 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 a= re +strings or string-valued gexps." + (service session-environment-service-type vars)) + + +;;; ;;; Console & co. ;;; =20 --=20 2.5.0 --=-=-=--