mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-12 20:55:31 +03:00
Merge #2692: Use pam_env to properly setup system-wide env
This commit is contained in:
parent
927c41e258
commit
18a0cdd864
10 changed files with 73 additions and 12 deletions
|
@ -76,7 +76,7 @@ in
|
||||||
|
|
||||||
environment.systemPackages = [ glibcLocales ];
|
environment.systemPackages = [ glibcLocales ];
|
||||||
|
|
||||||
environment.variables =
|
environment.systemVariables =
|
||||||
{ LANG = config.i18n.defaultLocale;
|
{ LANG = config.i18n.defaultLocale;
|
||||||
LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
|
LOCALE_ARCHIVE = "/run/current-system/sw/lib/locale/locale-archive";
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,6 +19,7 @@ in
|
||||||
default = {};
|
default = {};
|
||||||
description = ''
|
description = ''
|
||||||
A set of environment variables used in the global environment.
|
A set of environment variables used in the global environment.
|
||||||
|
These variables will be set on shell initialisation.
|
||||||
The value of each variable can be either a string or a list of
|
The value of each variable can be either a string or a list of
|
||||||
strings. The latter is concatenated, interspersed with colon
|
strings. The latter is concatenated, interspersed with colon
|
||||||
characters.
|
characters.
|
||||||
|
|
56
nixos/modules/config/system-environment.nix
Normal file
56
nixos/modules/config/system-environment.nix
Normal file
|
@ -0,0 +1,56 @@
|
||||||
|
# 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.systemVariables = 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 = types.attrsOf (mkOptionType {
|
||||||
|
name = "a string or a list of strings";
|
||||||
|
merge = loc: defs:
|
||||||
|
let
|
||||||
|
defs' = filterOverrides defs;
|
||||||
|
res = (head defs').value;
|
||||||
|
in
|
||||||
|
if isList res then concatLists (getValues defs')
|
||||||
|
else if lessThan 1 (length defs') then
|
||||||
|
throw "The option `${showOption loc}' is defined multiple times, in ${showFiles (getFiles defs)}."
|
||||||
|
else if !isString res then
|
||||||
|
throw "The option `${showOption loc}' does not have a string value, in ${showFiles (getFiles defs)}."
|
||||||
|
else res;
|
||||||
|
});
|
||||||
|
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.systemVariables) ]))))}
|
||||||
|
'';
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ in
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
|
|
||||||
environment.variables.TZDIR = "/etc/zoneinfo";
|
environment.systemVariables.TZDIR = "/etc/zoneinfo";
|
||||||
|
|
||||||
systemd.globalEnvironment.TZDIR = tzdir;
|
systemd.globalEnvironment.TZDIR = tzdir;
|
||||||
|
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
./config/power-management.nix
|
./config/power-management.nix
|
||||||
./config/pulseaudio.nix
|
./config/pulseaudio.nix
|
||||||
./config/shells-environment.nix
|
./config/shells-environment.nix
|
||||||
|
./config/system-environment.nix
|
||||||
./config/swap.nix
|
./config/swap.nix
|
||||||
./config/sysctl.nix
|
./config/sysctl.nix
|
||||||
./config/system-path.nix
|
./config/system-path.nix
|
||||||
|
|
|
@ -19,13 +19,16 @@ in
|
||||||
environment.variables =
|
environment.variables =
|
||||||
{ LOCATE_PATH = "/var/cache/locatedb";
|
{ LOCATE_PATH = "/var/cache/locatedb";
|
||||||
NIXPKGS_CONFIG = "/etc/nix/nixpkgs-config.nix";
|
NIXPKGS_CONFIG = "/etc/nix/nixpkgs-config.nix";
|
||||||
NIX_PATH =
|
PAGER = "less -R";
|
||||||
|
EDITOR = "nano";
|
||||||
|
};
|
||||||
|
|
||||||
|
environment.systemVariables =
|
||||||
|
{ NIX_PATH =
|
||||||
[ "/nix/var/nix/profiles/per-user/root/channels/nixos"
|
[ "/nix/var/nix/profiles/per-user/root/channels/nixos"
|
||||||
"nixpkgs=/etc/nixos/nixpkgs"
|
"nixpkgs=/etc/nixos/nixpkgs"
|
||||||
"nixos-config=/etc/nixos/configuration.nix"
|
"nixos-config=/etc/nixos/configuration.nix"
|
||||||
];
|
];
|
||||||
PAGER = "less -R";
|
|
||||||
EDITOR = "nano";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
environment.profiles =
|
environment.profiles =
|
||||||
|
|
|
@ -12,9 +12,11 @@ with lib;
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|
||||||
environment.variables.OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
environment.systemVariables =
|
||||||
environment.variables.CURL_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
{ OPENSSL_X509_CERT_FILE = "/etc/ssl/certs/ca-bundle.crt";
|
||||||
environment.variables.GIT_SSL_CAINFO = "/etc/ssl/certs/ca-bundle.crt";
|
CURL_CA_BUNDLE = "/etc/ssl/certs/ca-bundle.crt";
|
||||||
|
GIT_SSL_CAINFO = "/etc/ssl/certs/ca-bundle.crt";
|
||||||
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -186,6 +186,7 @@ let
|
||||||
"password optional ${pkgs.samba}/lib/security/pam_smbpass.so nullok use_authtok try_first_pass"}
|
"password optional ${pkgs.samba}/lib/security/pam_smbpass.so nullok use_authtok try_first_pass"}
|
||||||
|
|
||||||
# Session management.
|
# Session management.
|
||||||
|
session required pam_env.so envfile=${config.system.build.pamEnvironment}
|
||||||
session required pam_unix.so
|
session required pam_unix.so
|
||||||
${optionalString cfg.setLoginUid
|
${optionalString cfg.setLoginUid
|
||||||
"session required pam_loginuid.so"}
|
"session required pam_loginuid.so"}
|
||||||
|
|
|
@ -58,9 +58,6 @@ in
|
||||||
# Don't edit this file. Set the NixOS option ‘security.sudo.configFile’ instead.
|
# Don't edit this file. Set the NixOS option ‘security.sudo.configFile’ instead.
|
||||||
|
|
||||||
# Environment variables to keep for root and %wheel.
|
# Environment variables to keep for root and %wheel.
|
||||||
Defaults:root,%wheel env_keep+=LOCALE_ARCHIVE
|
|
||||||
Defaults:root,%wheel env_keep+=NIX_CONF_DIR
|
|
||||||
Defaults:root,%wheel env_keep+=NIX_PATH
|
|
||||||
Defaults:root,%wheel env_keep+=TERMINFO_DIRS
|
Defaults:root,%wheel env_keep+=TERMINFO_DIRS
|
||||||
Defaults:root,%wheel env_keep+=TERMINFO
|
Defaults:root,%wheel env_keep+=TERMINFO
|
||||||
|
|
||||||
|
|
|
@ -318,7 +318,7 @@ in
|
||||||
};
|
};
|
||||||
|
|
||||||
# Set up the environment variables for running Nix.
|
# Set up the environment variables for running Nix.
|
||||||
environment.variables = cfg.envVars;
|
environment.systemVariables = cfg.envVars;
|
||||||
|
|
||||||
environment.extraInit =
|
environment.extraInit =
|
||||||
''
|
''
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue