mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
refactor: static networking
This commit is contained in:
parent
1a4b5ee8b2
commit
91d4895c6f
13 changed files with 155 additions and 16 deletions
32
modules/meta/access.nix
Normal file
32
modules/meta/access.nix
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
{
|
||||
config,
|
||||
access,
|
||||
...
|
||||
}: let
|
||||
nixosModule = {
|
||||
config,
|
||||
...
|
||||
}: {
|
||||
config = {
|
||||
_module.args.access = access // {
|
||||
systemFor = hostName: if hostName == config.networking.hostName
|
||||
then config
|
||||
else access.systemFor hostName;
|
||||
systemForOrNull = hostName: if hostName == config.networking.hostName
|
||||
then config
|
||||
else access.systemForOrNull hostName;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
config = {
|
||||
network.nixos.extraModules = [
|
||||
nixosModule
|
||||
];
|
||||
|
||||
_module.args.access = {
|
||||
systemFor = hostName: config.network.nodes.${hostName};
|
||||
systemForOrNull = hostName: config.network.nodes.${hostName} or null;
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
@ -8,9 +8,6 @@
|
|||
inherit (config.networking) hostName;
|
||||
in {
|
||||
options.networking.access = with lib.types; {
|
||||
static.ipv4 = mkOption {
|
||||
type = str;
|
||||
};
|
||||
hostnameForNetwork = mkOption {
|
||||
type = attrsOf str;
|
||||
default = { };
|
||||
|
|
|
|||
|
|
@ -1,14 +1,53 @@
|
|||
{
|
||||
config,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
with lib; {
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkMerge mkOptionDefault;
|
||||
inherit (lib.trivial) eui64;
|
||||
inherit (config) networking services;
|
||||
networkModule = { config, ... }: {
|
||||
options = with lib.types; {
|
||||
mdns = {
|
||||
enable = mkEnableOption "SLAAC" // {
|
||||
default = config.matchConfig.Type or null == "ether" && services.resolved.enable;
|
||||
};
|
||||
};
|
||||
slaac = {
|
||||
enable = mkEnableOption "SLAAC" // {
|
||||
default = config.matchConfig.Type or null == "ether" && networking.enableIPv6;
|
||||
};
|
||||
postfix = mkOption {
|
||||
type = str;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
slaac.postfix = mkIf (config.matchConfig.MACAddress or null != null) (
|
||||
mkOptionDefault (eui64 config.matchConfig.MACAddress)
|
||||
);
|
||||
networkConfig = mkMerge [
|
||||
(mkIf config.slaac.enable {
|
||||
IPv6AcceptRA = true;
|
||||
})
|
||||
(mkIf config.mdns.enable {
|
||||
MulticastDNS = true;
|
||||
})
|
||||
];
|
||||
linkConfig = mkIf config.mdns.enable {
|
||||
Multicast = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
in {
|
||||
options.deploy.system = mkOption {
|
||||
type = types.unspecified;
|
||||
type = lib.types.unspecified;
|
||||
readOnly = true;
|
||||
};
|
||||
options.systemd.network.networks = mkOption {
|
||||
type = with lib.types; attrsOf (submodule networkModule);
|
||||
};
|
||||
config = {
|
||||
deploy.system = config.system.build.toplevel;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue