Fediversity/deployment/fediversity/resources/network/default.nix
Kiara Grouwstra c296bdab0a
deploy separate operator applications thru data model
Signed-off-by: Kiara Grouwstra <kiara@procolix.eu>
2025-11-22 17:55:10 +01:00

143 lines
4.4 KiB
Nix

{ lib, ... }:
let
inherit (lib) mkOption types;
inherit (types) submodule;
in
{
resources.network = {
description = "Networking info.";
policy =
{ config, ... }:
{
_class = "fediversity-resource-policy";
options = {
name = mkOption {
description = ''
The name of the machine. Most of the time, this will look like `vm02XXX`
or `fediYYY`.
'';
};
ipv4 = mkOption {
type = submodule {
options = {
# enable = mkOption {
# default = true;
# };
interface = mkOption {
description = ''
The interface that carries the machine's IPv4 network.
'';
default = "eth0";
};
address = mkOption {
description = ''
The IP address of the machine, version 4. It will be injected as a
value in `networking.interfaces.eth0`, but it will also be used to
communicate with the machine via NixOps4.
'';
};
# prefixLength = mkOption {
# description = ''
# The subnet mask of the interface, specified as the number of bits in
# the prefix.
# '';
# default = 24;
# };
gateway = mkOption {
description = ''
The IP address of the default gateway.
'';
default = "185.206.232.1"; # FIXME: compute default from `address` and `prefixLength`.
};
};
};
};
ipv6 = mkOption {
type = submodule {
options = {
# enable = mkOption {
# default = true;
# };
interface = mkOption {
description = ''
The interface that carries the machine's IPv6 network.
'';
default = "eth0";
};
address = mkOption {
description = ''
The IP address of the machine, version 6. It will be injected as a
value in `networking.interfaces.eth0`, but it will also be used to
communicate with the machine via NixOps4.
'';
};
# prefixLength = mkOption {
# description = ''
# The subnet mask of the interface, specified as the number of bits in
# the prefix.
# '';
# default = 64;
# };
gateway = mkOption {
description = ''
The IP address of the default gateway.
'';
default = "2a00:51c0:12:1201::1"; # FIXME: compute default from `address` and `prefixLength`.
};
};
};
};
};
config = {
resource-type = types.unspecified; # NixOS module
apply =
let
cfg = config;
in
_requests:
{ config, ... }:
{
# imports = [
# ../../../../infra/common/nixos/networking.nix
# ];
networking = lib.mkMerge [
{
hostName = cfg.name;
}
{
interfaces.${config.networking.defaultGateway.interface}.ipv4.addresses = [
{
prefixLength = 24;
address = cfg.ipv4.address;
}
];
defaultGateway = {
address = cfg.ipv4.gateway;
};
}
{
interfaces.${config.networking.defaultGateway6.interface}.ipv6.addresses = [
{
prefixLength = 64;
address = cfg.ipv6.address;
}
];
defaultGateway6 = {
address = cfg.ipv6.gateway;
};
}
];
};
};
};
};
}