nixos-config/lib/instance.nix

95 lines
2.9 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
2021-02-25 12:45:50 -08:00
with lib;
2021-10-01 16:05:56 -07:00
let
2021-10-04 10:20:53 -07:00
user = import ./types/user.nix { inherit lib; };
2021-10-04 13:23:40 -07:00
host = import ./types/host.nix { inherit lib; };
2021-10-04 10:20:53 -07:00
2021-10-01 16:05:56 -07:00
in {
2021-09-30 08:40:47 -07:00
options.instance = with types; {
hostname = mkOption {
2021-09-30 08:40:47 -07:00
type = str;
description = "Hostname of this specific host (without domain).";
};
build-timestamp = mkOption {
type = int;
description = "Timestamp associated with the build. Used for e.g. DNS serials.";
};
2021-10-01 16:05:56 -07:00
local-domain = mkOption {
type = str;
description = "Domain name of the current local host.";
};
2021-10-11 15:04:06 -07:00
local-profile = mkOption {
type = str;
description = "Profile name of the current local host.";
};
2021-10-01 16:05:56 -07:00
local-site = mkOption {
type = str;
description = "Site name of the current local host.";
};
local-admins = mkOption {
type = listOf str;
description = "List of users who should have admin access to the local host.";
};
local-groups = mkOption {
2021-10-04 10:20:53 -07:00
type = attrsOf (submodule user.groupOpts);
2021-10-01 16:05:56 -07:00
description = "List of groups which should be created on the local host.";
};
local-hosts = mkOption {
2021-10-05 10:18:54 -07:00
type = attrsOf (submodule host.hostOpts);
2021-10-01 16:05:56 -07:00
description = "List of hosts that should be considered local to the current host.";
};
local-users = mkOption {
2021-10-04 10:20:53 -07:00
type = attrsOf (submodule user.userOpts);
2021-10-01 16:05:56 -07:00
description = "List of users who should have access to the local host";
};
};
config = let
local-host = config.instance.hostname;
local-domain = config.fudo.hosts.${local-host}.domain;
local-site = config.fudo.hosts.${local-host}.site;
2021-10-11 15:04:06 -07:00
host = config.fudo.hosts.${local-host};
host-user-list = host.local-users;
2021-10-01 16:05:56 -07:00
domain-user-list = config.fudo.domains."${local-domain}".local-users;
site-user-list = config.fudo.sites."${local-site}".local-users;
local-users =
getAttrs (host-user-list ++ domain-user-list ++ site-user-list) config.fudo.users;
2021-10-11 15:04:06 -07:00
host-admin-list = host.local-admins;
2021-10-01 16:05:56 -07:00
domain-admin-list = config.fudo.domains."${local-domain}".local-admins;
site-admin-list = config.fudo.sites."${local-site}".local-admins;
local-admins = host-admin-list ++ domain-admin-list ++ site-admin-list;
2021-10-11 15:04:06 -07:00
host-group-list = host.local-groups;
2021-10-01 16:05:56 -07:00
domain-group-list = config.fudo.domains."${local-domain}".local-groups;
site-group-list = config.fudo.sites."${local-site}".local-groups;
local-groups =
getAttrs (host-group-list ++ domain-group-list ++ site-group-list)
config.fudo.groups;
local-hosts =
filterAttrs (host: hostOpts: hostOpts.site == local-site) config.fudo.hosts;
in {
instance = {
local-domain = local-domain;
local-site = local-site;
local-users = local-users;
local-admins = local-admins;
local-groups = local-groups;
local-hosts = local-hosts;
2021-10-11 15:04:06 -07:00
local-profile = host.profile;
2021-10-01 16:05:56 -07:00
};
};
}