diff options
Diffstat (limited to 'nixpkgs/nixos/modules/config/system-environment.nix')
-rw-r--r-- | nixpkgs/nixos/modules/config/system-environment.nix | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/nixpkgs/nixos/modules/config/system-environment.nix b/nixpkgs/nixos/modules/config/system-environment.nix new file mode 100644 index 000000000000..6011e354ece4 --- /dev/null +++ b/nixpkgs/nixos/modules/config/system-environment.nix @@ -0,0 +1,43 @@ +# This module defines a system-wide environment that will be +# initialised by pam_env (that is, not only in shells). +{ config, lib, pkgs, ... }: + +with lib; + +let + + cfg = config.environment; + +in + +{ + + options = { + + environment.sessionVariables = mkOption { + default = {}; + description = '' + A set of environment variables used in the global environment. + These variables will be set by PAM. + The value of each variable can be either a string or a list of + strings. The latter is concatenated, interspersed with colon + characters. + ''; + type = with types; attrsOf (either str (listOf str)); + apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v); + }; + + }; + + config = { + + system.build.pamEnvironment = pkgs.writeText "pam-environment" + '' + ${concatStringsSep "\n" ( + (mapAttrsToList (n: v: ''${n}="${concatStringsSep ":" v}"'') + (zipAttrsWith (const concatLists) ([ (mapAttrs (n: v: [ v ]) cfg.sessionVariables) ]))))} + ''; + + }; + +} |