Generalise common networking options

- allow disabling IPv4 or v6 (both enabled by default)
- allow specifying interface (defaults to eth0)
This commit is contained in:
Nicolas Jeannerod 2025-02-10 12:24:10 +01:00 committed by Kiara Grouwstra
parent 52f659b9b2
commit 8d2bda17f1
Signed by: kiara
SSH key fingerprint: SHA256:COspvLoLJ5WC5rFb9ZDe5urVCkK4LJZOsjfF4duRJFU
2 changed files with 62 additions and 44 deletions

View file

@ -1,7 +1,7 @@
{ config, lib, ... }: { config, lib, ... }:
let let
inherit (lib) mkDefault; inherit (lib) mkDefault mkIf mkMerge;
in in
{ {
@ -11,41 +11,14 @@ in
settings.PasswordAuthentication = false; settings.PasswordAuthentication = false;
}; };
networking = { networking = mkMerge [
{
hostName = config.fediversityVm.name; hostName = config.fediversityVm.name;
domain = config.fediversityVm.domain; domain = config.fediversityVm.domain;
## REVIEW: Do we actually need that, considering that we have static IPs? ## REVIEW: Do we actually need that, considering that we have static IPs?
useDHCP = mkDefault true; useDHCP = mkDefault true;
interfaces = {
eth0 = {
ipv4 = {
addresses = [
{
inherit (config.fediversityVm.ipv4) address prefixLength;
}
];
};
ipv6 = {
addresses = [
{
inherit (config.fediversityVm.ipv6) address prefixLength;
}
];
};
};
};
defaultGateway = {
address = config.fediversityVm.ipv4.gateway;
interface = "eth0";
};
defaultGateway6 = {
address = config.fediversityVm.ipv6.gateway;
interface = "eth0";
};
nameservers = [ nameservers = [
"95.215.185.6" "95.215.185.6"
"95.215.185.7" "95.215.185.7"
@ -58,6 +31,29 @@ in
enable = true; enable = true;
rulesetFile = ./nftables-ruleset.nft; rulesetFile = ./nftables-ruleset.nft;
}; };
}
## IPv4
(mkIf config.fediversityVm.ipv4.enable {
interfaces.${config.fediversityVm.ipv4.interface}.ipv4.addresses = [
{ inherit (config.fediversityVm.ipv4) address prefixLength; }
];
defaultGateway = {
address = config.fediversityVm.ipv4.gateway;
interface = config.fediversityVm.ipv4.interface;
}; };
})
## IPv6
(mkIf config.fediversityVm.ipv6.enable {
interfaces.${config.fediversityVm.ipv6.interface}.ipv6.addresses = [
{ inherit (config.fediversityVm.ipv6) address prefixLength; }
];
defaultGateway6 = {
address = config.fediversityVm.ipv6.gateway;
interface = config.fediversityVm.ipv6.interface;
};
})
];
}; };
} }

View file

@ -89,6 +89,17 @@ in
}; };
ipv4 = { ipv4 = {
enable = mkOption {
default = true;
};
interface = mkOption {
description = ''
The interface that carries the machine's IPv4 network.
'';
default = "eth0";
};
address = mkOption { address = mkOption {
description = '' description = ''
The IP address of the machine, version 4. It will be injected as a The IP address of the machine, version 4. It will be injected as a
@ -114,6 +125,17 @@ in
}; };
ipv6 = { ipv6 = {
enable = mkOption {
default = true;
};
interface = mkOption {
description = ''
The interface that carries the machine's IPv6 network.
'';
default = "eth0";
};
address = mkOption { address = mkOption {
description = '' description = ''
The IP address of the machine, version 6. It will be injected as a The IP address of the machine, version 6. It will be injected as a