nixos/pam: extract autoOrderRules to utils
This function is used to convert an ordered list of rules into an attrset of rules with reasonable 'order' values. This reduces boilerplate to define 'order' and makes it simple to switch how ordering is managed in the future.
This commit is contained in:
@@ -541,6 +541,33 @@ let
|
||||
- https://github.com/qemu/qemu/blob/master/scripts/qemu-binfmt-conf.sh
|
||||
*/
|
||||
binfmtMagics = import ./binfmt-magics.nix;
|
||||
|
||||
# Utilities for working with the security.pam module (pam.nix)
|
||||
pam = {
|
||||
/*
|
||||
Set up the ordering for a set of PAM rules using an ordered list of rules.
|
||||
|
||||
The input is an ordered list of PAM rules. Each rule is an attrset similar to the options
|
||||
in `security.pam.services.<service>.rules.<rule>`, with two modifications:
|
||||
|
||||
1. The `order` option may not be given.
|
||||
2. The `name` option is required.
|
||||
|
||||
The output is an attrset of rules suitable for `security.pam.services.<service>.rules`.
|
||||
|
||||
The `order` option on the resulting rules will automatically be configured according to the
|
||||
(implied) ordering of the input rules.
|
||||
*/
|
||||
autoOrderRules = lib.flip lib.pipe [
|
||||
(lib.imap1 (
|
||||
index: rule:
|
||||
assert lib.assertMsg (!rule ? order) "the 'order' option may not be set when using autoOrderRules";
|
||||
rule // { order = lib.mkDefault (10000 + index * 100); }
|
||||
))
|
||||
(map (rule: lib.nameValuePair rule.name (removeAttrs rule [ "name" ])))
|
||||
lib.listToAttrs
|
||||
];
|
||||
};
|
||||
};
|
||||
in
|
||||
utils
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
utils,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
@@ -898,20 +899,9 @@ let
|
||||
# !!! TODO: move the LDAP stuff to the LDAP module, and the
|
||||
# Samba stuff to the Samba module. This requires that the PAM
|
||||
# module provides the right hooks.
|
||||
rules =
|
||||
let
|
||||
autoOrderRules = lib.flip lib.pipe [
|
||||
(lib.imap1 (
|
||||
index: rule:
|
||||
assert lib.assertMsg (!rule ? order) "the 'order' option may not be set when using autoOrderRules";
|
||||
rule // { order = lib.mkDefault (10000 + index * 100); }
|
||||
))
|
||||
(map (rule: lib.nameValuePair rule.name (removeAttrs rule [ "name" ])))
|
||||
lib.listToAttrs
|
||||
];
|
||||
in
|
||||
rules = (
|
||||
lib.optionalAttrs cfg.useDefaultRules {
|
||||
account = autoOrderRules [
|
||||
account = utils.pam.autoOrderRules [
|
||||
{
|
||||
name = "ldap";
|
||||
enable = use_ldap;
|
||||
@@ -992,7 +982,7 @@ let
|
||||
|
||||
];
|
||||
|
||||
auth = autoOrderRules (
|
||||
auth = utils.pam.autoOrderRules (
|
||||
[
|
||||
{
|
||||
name = "oslogin_login";
|
||||
@@ -1365,7 +1355,7 @@ let
|
||||
]
|
||||
);
|
||||
|
||||
password = autoOrderRules [
|
||||
password = utils.pam.autoOrderRules [
|
||||
{
|
||||
name = "systemd_home";
|
||||
enable = config.services.homed.enable;
|
||||
@@ -1450,7 +1440,7 @@ let
|
||||
}
|
||||
];
|
||||
|
||||
session = autoOrderRules [
|
||||
session = utils.pam.autoOrderRules [
|
||||
{
|
||||
name = "env";
|
||||
enable = cfg.setEnvironment;
|
||||
@@ -1682,7 +1672,8 @@ let
|
||||
modulePath = "${pkgs.intune-portal}/lib/security/pam_intune.so";
|
||||
}
|
||||
];
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user