0
0
Fork 0
mirror of https://github.com/NixOS/nixpkgs.git synced 2025-07-13 21:50:33 +03:00

nixos/environment: remove with lib;

This commit is contained in:
Felix Buehler 2024-08-27 20:42:49 +02:00
parent c39ad44462
commit 21d7a61b1a

View file

@ -1,9 +1,6 @@
# This module defines a system-wide environment that will be # This module defines a system-wide environment that will be
# initialised by pam_env (that is, not only in shells). # initialised by pam_env (that is, not only in shells).
{ config, lib, options, pkgs, ... }: { config, lib, options, pkgs, ... }:
with lib;
let let
cfg = config.environment; cfg = config.environment;
@ -14,7 +11,7 @@ in
options = { options = {
environment.sessionVariables = mkOption { environment.sessionVariables = lib.mkOption {
default = {}; default = {};
description = '' description = ''
A set of environment variables used in the global environment. A set of environment variables used in the global environment.
@ -35,8 +32,8 @@ in
inherit (options.environment.variables) type apply; inherit (options.environment.variables) type apply;
}; };
environment.profileRelativeSessionVariables = mkOption { environment.profileRelativeSessionVariables = lib.mkOption {
type = types.attrsOf (types.listOf types.str); type = lib.types.attrsOf (lib.types.listOf lib.types.str);
example = { PATH = [ "/bin" ]; MANPATH = [ "/man" "/share/man" ]; }; example = { PATH = [ "/bin" ]; MANPATH = [ "/man" "/share/man" ]; };
description = '' description = ''
Attribute set of environment variable used in the global Attribute set of environment variable used in the global
@ -63,8 +60,8 @@ in
config = { config = {
environment.etc."pam/environment".text = let environment.etc."pam/environment".text = let
suffixedVariables = suffixedVariables =
flip mapAttrs cfg.profileRelativeSessionVariables (envVar: suffixes: lib.flip lib.mapAttrs cfg.profileRelativeSessionVariables (envVar: suffixes:
flip concatMap cfg.profiles (profile: lib.flip lib.concatMap cfg.profiles (profile:
map (suffix: "${profile}${suffix}") suffixes map (suffix: "${profile}${suffix}") suffixes
) )
); );
@ -72,15 +69,15 @@ in
# We're trying to use the same syntax for PAM variables and env variables. # 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 # That means we need to map the env variables that people might use to their
# equivalent PAM variable. # equivalent PAM variable.
replaceEnvVars = replaceStrings ["$HOME" "$USER"] ["@{HOME}" "@{PAM_USER}"]; replaceEnvVars = lib.replaceStrings ["$HOME" "$USER"] ["@{HOME}" "@{PAM_USER}"];
pamVariable = n: v: pamVariable = n: v:
''${n} DEFAULT="${concatStringsSep ":" (map replaceEnvVars (toList v))}"''; ''${n} DEFAULT="${lib.concatStringsSep ":" (map replaceEnvVars (lib.toList v))}"'';
pamVariables = pamVariables =
concatStringsSep "\n" lib.concatStringsSep "\n"
(mapAttrsToList pamVariable (lib.mapAttrsToList pamVariable
(zipAttrsWith (n: concatLists) (lib.zipAttrsWith (n: lib.concatLists)
[ [
# Make sure security wrappers are prioritized without polluting # Make sure security wrappers are prioritized without polluting
# shell environments with an extra entry. Sessions which depend on # shell environments with an extra entry. Sessions which depend on
@ -89,7 +86,7 @@ in
# environment from a shell. # environment from a shell.
{ PATH = [ config.security.wrapperDir ]; } { PATH = [ config.security.wrapperDir ]; }
(mapAttrs (n: toList) cfg.sessionVariables) (lib.mapAttrs (n: lib.toList) cfg.sessionVariables)
suffixedVariables suffixedVariables
])); ]));
in '' in ''