2014-06-10 13:07:10 +02:00
|
|
|
# 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 = {
|
|
|
|
|
2014-06-13 17:56:46 +02:00
|
|
|
environment.sessionVariables = mkOption {
|
2014-06-10 13:07:10 +02:00
|
|
|
default = {};
|
2022-08-03 22:46:41 +02:00
|
|
|
description = lib.mdDoc ''
|
2014-06-10 13:07:10 +02:00
|
|
|
A set of environment variables used in the global environment.
|
2019-08-19 16:05:10 +02:00
|
|
|
These variables will be set by PAM early in the login process.
|
|
|
|
|
|
|
|
The value of each session variable can be either a string or a
|
|
|
|
list of strings. The latter is concatenated, interspersed with
|
|
|
|
colon characters.
|
|
|
|
|
|
|
|
Note, due to limitations in the PAM format values may not
|
2022-08-03 22:46:41 +02:00
|
|
|
contain the `"` character.
|
2019-08-19 16:05:10 +02:00
|
|
|
|
|
|
|
Also, these variables are merged into
|
2022-08-03 22:46:41 +02:00
|
|
|
[](#opt-environment.variables) and it is
|
2019-08-19 16:05:10 +02:00
|
|
|
therefore not possible to use PAM style variables such as
|
2022-08-03 22:46:41 +02:00
|
|
|
`@{HOME}`.
|
2014-06-10 13:07:10 +02:00
|
|
|
'';
|
2016-11-04 05:33:59 +01:00
|
|
|
type = with types; attrsOf (either str (listOf str));
|
2014-06-10 13:07:10 +02:00
|
|
|
apply = mapAttrs (n: v: if isList v then concatStringsSep ":" v else v);
|
|
|
|
};
|
|
|
|
|
2019-08-19 16:05:10 +02:00
|
|
|
environment.profileRelativeSessionVariables = mkOption {
|
|
|
|
type = types.attrsOf (types.listOf types.str);
|
|
|
|
example = { PATH = [ "/bin" ]; MANPATH = [ "/man" "/share/man" ]; };
|
2022-08-05 19:39:00 +02:00
|
|
|
description = lib.mdDoc ''
|
2019-08-19 16:05:10 +02:00
|
|
|
Attribute set of environment variable used in the global
|
|
|
|
environment. These variables will be set by PAM early in the
|
|
|
|
login process.
|
|
|
|
|
|
|
|
Variable substitution is available as described in
|
2022-08-05 19:39:00 +02:00
|
|
|
{manpage}`pam_env.conf(5)`.
|
2019-08-19 16:05:10 +02:00
|
|
|
|
|
|
|
Each attribute maps to a list of relative paths. Each relative
|
|
|
|
path is appended to the each profile of
|
2022-08-05 19:39:00 +02:00
|
|
|
{option}`environment.profiles` to form the content of
|
2019-08-19 16:05:10 +02:00
|
|
|
the corresponding environment variable.
|
|
|
|
|
|
|
|
Also, these variables are merged into
|
2022-08-05 19:39:00 +02:00
|
|
|
[](#opt-environment.profileRelativeEnvVars) and it is
|
2019-08-19 16:05:10 +02:00
|
|
|
therefore not possible to use PAM style variables such as
|
2022-08-05 19:39:00 +02:00
|
|
|
`@{HOME}`.
|
2019-08-19 16:05:10 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-06-10 13:07:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
config = {
|
2021-07-28 06:28:25 +02:00
|
|
|
environment.etc."pam/environment".text = let
|
|
|
|
suffixedVariables =
|
|
|
|
flip mapAttrs cfg.profileRelativeSessionVariables (envVar: suffixes:
|
|
|
|
flip concatMap cfg.profiles (profile:
|
|
|
|
map (suffix: "${profile}${suffix}") suffixes
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
|
|
|
# We're trying to use the same syntax for PAM variables and env variables.
|
|
|
|
# That means we need to map the env variables that people might use to their
|
|
|
|
# equivalent PAM variable.
|
|
|
|
replaceEnvVars = replaceStrings ["$HOME" "$USER"] ["@{HOME}" "@{PAM_USER}"];
|
|
|
|
|
|
|
|
pamVariable = n: v:
|
|
|
|
''${n} DEFAULT="${concatStringsSep ":" (map replaceEnvVars (toList v))}"'';
|
|
|
|
|
|
|
|
pamVariables =
|
|
|
|
concatStringsSep "\n"
|
|
|
|
(mapAttrsToList pamVariable
|
|
|
|
(zipAttrsWith (n: concatLists)
|
|
|
|
[
|
|
|
|
# Make sure security wrappers are prioritized without polluting
|
|
|
|
# shell environments with an extra entry. Sessions which depend on
|
|
|
|
# pam for its environment will otherwise have eg. broken sudo. In
|
|
|
|
# particular Gnome Shell sometimes fails to source a proper
|
|
|
|
# environment from a shell.
|
|
|
|
{ PATH = [ config.security.wrapperDir ]; }
|
|
|
|
|
|
|
|
(mapAttrs (n: toList) cfg.sessionVariables)
|
|
|
|
suffixedVariables
|
|
|
|
]));
|
|
|
|
in ''
|
|
|
|
${pamVariables}
|
|
|
|
'';
|
2014-06-10 13:07:10 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|