1# This module defines a system-wide environment that will be
2# initialised by pam_env (that is, not only in shells).
3{ config, lib, pkgs, ... }:
4
5with lib;
6
7let
8
9 cfg = config.environment;
10
11in
12
13{
14
15 options = {
16
17 environment.sessionVariables = mkOption {
18 default = {};
19 description = ''
20 A set of environment variables used in the global environment.
21 These variables will be set by PAM.
22 The value of each variable can be either a string or a list of
23 strings. The latter is concatenated, interspersed with colon
24 characters.
25 '';
26 type = with types; attrsOf (either str (listOf str));
27 apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
28 };
29
30 };
31
32 config = {
33
34 system.build.pamEnvironment = pkgs.writeText "pam-environment"
35 ''
36 ${concatStringsSep "\n" (
37 (mapAttrsToList (n: v: ''${n}="${concatStringsSep ":" v}"'')
38 (zipAttrsWith (const concatLists) ([ (mapAttrs (n: v: [ v ]) cfg.sessionVariables) ]))))}
39 '';
40
41 };
42
43}