initial implementation of meta

This commit is contained in:
Vivian 2024-01-05 17:30:26 +01:00
parent dfd934873b
commit f156c2396f
7 changed files with 129 additions and 48 deletions

View file

@ -21,7 +21,8 @@ in {
helix
inputs.attic.packages.${pkgs.system}.attic
inputs.comma.packages.${pkgs.system}.default
inputs.webcord.packages.${pkgs.system}.default
# inputs.webcord.packages.${pkgs.system}.default
discord
jetbrains.clion
jetbrains.rust-rover
kdenlive

View file

@ -1,18 +1,22 @@
{ config, pkgs, lib, hosts, flat_hosts, ... }:
{ config, pkgs, lib, self, ... }:
# DNS Module to set up Unbound DNS with all my hosts in the config
# Used for DNS Servers and my laptop
with lib;
let
inherit (builtins) filter hasAttr attrNames;
domains = attrNames hosts;
ipv4Host = filter (hasAttr "ip") flat_hosts;
ipv6Hosts = filter (hasAttr "ip6") flat_hosts;
inherit (builtins) filter attrValues;
domains = [ "hades" "olympus" "thalassa" ];
mapConfig = host: {
inherit (host.config.networking) hostName domain;
inherit (host.config.meta) ipv4 ipv6;
};
hosts = (map mapConfig (attrValues self.nixosConfigurations));
ipv4Hosts = filter (v: v.ipv4 != null) hosts;
ipv6Hosts = filter (v: v.ipv6 != null) hosts;
localData = { hostname, realm, ip, ... }: ''"${hostname}.${realm}. A ${ip}"'';
local6Data = { hostname, realm, ip6, ... }:
''"${hostname}.${realm}. AAAA ${ip6}"'';
ptrData = { hostname, realm, ip, ... }: ''"${ip} ${hostname}.${realm}"'';
ptr6Data = { hostname, realm, ip6, ... }: ''"${ip6} ${hostname}.${realm}"'';
localData = { hostName, domain, ipv4, ... }: ''"${hostName}.${domain}. A ${ipv4}"'';
local6Data = { hostName, domain, ipv6, ... }: ''"${hostName}.${domain}. AAAA ${ipv6}"'';
ptrData = { hostName, domain, ipv4, ... }: ''"${ipv4} ${hostName}.${domain}"'';
ptr6Data = { hostName, domain, ipv6, ... }: ''"${ipv6} ${hostName}.${domain}"'';
cfg = config.services.v.dns;
in {
@ -37,7 +41,7 @@ in {
};
mode = mkOption {
type = enum [ "server" "laptop" ];
type = types.enum [ "server" "laptop" ];
default = "laptop";
description = ''
Whether to configure the DNS in server mode (listen on all interfaces) or laptop mode (just on localhost)
@ -69,8 +73,8 @@ in {
local-zone =
map (localdomain: ''"${localdomain}}." transparent'') domains;
local-data = (map localData ipv4Host) ++ (map local6Data ipv6Hosts);
local-data-ptr = (map ptrData ipv4Host) ++ (map ptr6Data ipv6Hosts);
local-data = (map localData ipv4Hosts) ++ (map local6Data ipv6Hosts);
local-data-ptr = (map ptrData ipv4Hosts) ++ (map ptr6Data ipv6Hosts);
private-address = [
"127.0.0.0/8"

View file

@ -1,4 +1,4 @@
{ lib, ... }:
{ lib, config, ... }:
with lib;
let
exposesOpts = {
@ -6,7 +6,7 @@ let
domain = mkOption {
type = types.str;
example = "<name>.example.com";
description = ''
description = lib.mdDoc ''
The domain under which this service should be available
'';
};
@ -14,30 +14,76 @@ let
type = types.int;
default = 80;
example = 4242;
description = ''
description = lib.mdDoc ''
The port under which the service runs on the host
'';
};
};
};
in
{
in {
options.meta = {
exposes = mkOption {
type = with types; attrsOf (submodule exposesOpts);
default = { };
description = ''
Exposed services
'';
};
ipv4 = mkOption {
type = types.str;
description = ''
Own IPv4 Address
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
Host's IPv4 Address
'';
};
ipv6 = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
Host's IPv6 address
'';
};
mac = mkOption {
type = types.nullOr types.str;
default = null;
description = lib.mdDoc ''
Own MAC Address
'';
};
isLaptop = mkOption {
type = types.bool;
default = false;
description = lib.mdDoc ''
Is this host a Laptop (i.e. no DNS entries should be made).
'';
};
realm = mkOption {
readOnly = true;
type = types.nullOr (types.enum [ "thalassa" "hades" "olympus" ]);
default = config.networking.domain;
defaultText = literalExpression "config.network.domain";
};
};
config = { };
config = {
# TODO: Open Firewall
assertions = [
{
assertion = config.meta.mac != null;
message =
"${config.networking.fqdnOrHostName} is missing a mac address";
}
{
assertion = !config.meta.isLaptop -> config.meta.ipv4 != null;
message =
"${config.networking.fqdnOrHostName} needs ipv4 address set as it is not a laptop";
}
];
};
}