forked from rarias/jungle
30 lines
1013 B
Nix
30 lines
1013 B
Nix
{ config, lib, ... }:
|
|
|
|
with lib;
|
|
|
|
{
|
|
options = {
|
|
users.jungleUsers = mkOption {
|
|
type = types.attrsOf (types.anything // { check = (x: x ? "hosts"); });
|
|
description = ''
|
|
Same as users.users but with the extra `hosts` attribute, which controls
|
|
access to the nodes by `networking.hostName`.
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = let
|
|
allowedUser = host: userConf: builtins.elem host userConf.hosts;
|
|
filterUsers = host: users: filterAttrs (n: v: allowedUser host v) users;
|
|
removeHosts = users: mapAttrs (n: v: builtins.removeAttrs v [ "hosts" ]) users;
|
|
addExtraGroups = mapAttrs (_: user: user // {
|
|
extraGroups = (user.extraGroups or [ ])
|
|
++ (lib.optionals (allowedUser "fox" user) [ "fox" ])
|
|
++ (lib.optionals (allowedUser "owl1" user || allowedUser "owl2" user) [ "owl" ]);
|
|
});
|
|
currentHost = config.networking.hostName;
|
|
in {
|
|
users.users = removeHosts (addExtraGroups (filterUsers currentHost config.users.jungleUsers));
|
|
};
|
|
}
|