infrastructure/modules/nixos/dgn-access-control.nix

67 lines
1.3 KiB
Nix
Raw Normal View History

# SPDX-FileCopyrightText: 2024 Tom Hubrecht <tom.hubrecht@dgnum.eu>
#
# SPDX-License-Identifier: EUPL-1.2
{
config,
lib,
dgn-keys,
meta,
2024-04-18 15:53:20 +02:00
nodeMeta,
...
}:
2023-05-22 15:07:03 +02:00
let
2023-07-18 17:00:51 +02:00
inherit (lib)
mkDefault
mkEnableOption
mkIf
mkOption
optionalAttrs
2023-07-18 17:00:51 +02:00
types
;
2023-07-18 17:00:51 +02:00
admins =
2024-02-23 10:50:50 +01:00
meta.organization.groups.root
++ nodeMeta.admins
2024-02-23 10:50:50 +01:00
++ (builtins.concatMap (g: meta.organization.groups.${g}) nodeMeta.adminGroups);
2023-05-22 15:07:03 +02:00
cfg = config.dgn-access-control;
in
{
options.dgn-access-control = {
enable = mkEnableOption "DGNum access control." // {
default = true;
};
2023-05-22 15:07:03 +02:00
users = mkOption {
type = with types; attrsOf (listOf str);
default = { };
description = ''
Attribute set describing which member has access to which user on the node.
2023-05-22 17:24:42 +02:00
Members must be declared in `meta/members.nix`.
'';
example = ''
{
user1 = [ "member1" "member2" ];
}
2023-05-22 15:07:03 +02:00
'';
};
};
2024-12-08 15:41:24 +01:00
config = mkIf cfg.enable {
# Admins have root access to the node
dgn-access-control.users.root = mkDefault admins;
users.mutableUsers = false;
users.users = builtins.mapAttrs (
username: members:
{
openssh.authorizedKeys.keys = dgn-keys.getKeys members;
2024-12-08 15:41:24 +01:00
}
// optionalAttrs (username == "root") { inherit (nodeMeta) hashedPassword; }
) cfg.users;
};
2023-05-22 15:07:03 +02:00
}