61 lines
1.3 KiB
Nix
61 lines
1.3 KiB
Nix
# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
|
|
#
|
|
# SPDX-License-Identifier: EUPL-1.2
|
|
|
|
{
|
|
config,
|
|
lib,
|
|
name,
|
|
dgn-keys,
|
|
nodeMeta,
|
|
...
|
|
}:
|
|
let
|
|
inherit (lib)
|
|
mkDefault
|
|
mkEnableOption
|
|
mkIf
|
|
mkOption
|
|
optionalAttrs
|
|
|
|
types
|
|
;
|
|
|
|
cfg = config.dgn-access-control;
|
|
in
|
|
|
|
{
|
|
options.dgn-access-control = {
|
|
enable = mkEnableOption "DGNum access control." // {
|
|
default = true;
|
|
};
|
|
|
|
users = mkOption {
|
|
type = with types; attrsOf (listOf str);
|
|
default = { };
|
|
description = ''
|
|
Attribute set describing which member has access to which user on the node.
|
|
Members must be declared in `meta/members.nix`.
|
|
'';
|
|
example = ''
|
|
{
|
|
user1 = [ "member1" "member2" ];
|
|
}
|
|
'';
|
|
};
|
|
};
|
|
|
|
config = mkIf cfg.enable {
|
|
# Admins have root access to the node
|
|
dgn-access-control.users.root = mkDefault (dgn-keys.getNodeAdmins name);
|
|
users.mutableUsers = false;
|
|
users.users = builtins.mapAttrs (
|
|
username: members:
|
|
{
|
|
isNormalUser = lib.mkIf (username != "root") true;
|
|
openssh.authorizedKeys.keys = dgn-keys.getMemberKeys members;
|
|
}
|
|
// optionalAttrs (username == "root") { inherit (nodeMeta) hashedPassword; }
|
|
) cfg.users;
|
|
};
|
|
}
|