Compare commits

...

2 commits

Author SHA1 Message Date
54623a589b allow configuring whether a node uses QEMU 2025-07-01 11:10:57 +02:00
0c23115cff allow configuring network interface (#413)
Reviewed-on: Fediversity/Fediversity#413
Reviewed-by: Valentin Gagarin <valentin.gagarin@tweag.io>
Co-authored-by: Kiara Grouwstra <kiara@procolix.eu>
Co-committed-by: Kiara Grouwstra <kiara@procolix.eu>
2025-06-30 19:23:51 +02:00
3 changed files with 141 additions and 93 deletions

View file

@ -1,64 +1,86 @@
{ modulesPath, ... }: { config, lib, ... }:
let
inherit (lib) mkIf mkMerge;
in
{ {
_class = "nixos"; _class = "nixos";
imports = [ (modulesPath + "/profiles/qemu-guest.nix") ]; config = mkMerge [
{
boot.loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
}
boot = { (mkIf config.fediversityVm.isQemuVm {
loader = {
systemd-boot.enable = true;
efi.canTouchEfiVariables = true;
};
initrd = { boot.initrd = {
availableKernelModules = [ availableKernelModules = [
"ata_piix" "ata_piix"
"uhci_hcd" "uhci_hcd"
"virtio_pci" "sd_mod"
"virtio_scsi" "sr_mod"
"sd_mod"
"sr_mod"
];
kernelModules = [ "dm-snapshot" ];
};
};
disko.devices.disk.main = { # from `/profiles/qemu-guest.nix`
device = "/dev/sda"; "virtio_net"
type = "disk"; "virtio_pci"
"virtio_mmio"
"virtio_blk"
"virtio_scsi"
"9p"
"9pnet_virtio"
];
kernelModules = [
"dm-snapshot"
content = { # from `/profiles/qemu-guest.nix`
type = "gpt"; "virtio_balloon"
"virtio_console"
"virtio_rng"
"virtio_gpu"
];
};
partitions = { disko.devices.disk.main = {
MBR = { device = "/dev/sda";
priority = 0; type = "disk";
size = "1M";
type = "EF02";
};
ESP = { content = {
priority = 1; type = "gpt";
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
root = { partitions = {
priority = 2; MBR = {
size = "100%"; priority = 0;
content = { size = "1M";
type = "filesystem"; type = "EF02";
format = "ext4"; };
mountpoint = "/";
ESP = {
priority = 1;
size = "500M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
};
};
root = {
priority = 2;
size = "100%";
content = {
type = "filesystem";
format = "ext4";
mountpoint = "/";
};
};
}; };
}; };
}; };
}; })
}; ];
} }

View file

@ -1,7 +1,7 @@
{ config, lib, ... }: { config, lib, ... }:
let let
inherit (lib) mkDefault; inherit (lib) mkDefault mkIf mkMerge;
in in
{ {
@ -13,53 +13,49 @@ in
settings.PasswordAuthentication = false; settings.PasswordAuthentication = false;
}; };
networking = { networking = mkMerge [
hostName = config.fediversityVm.name; {
domain = config.fediversityVm.domain; hostName = config.fediversityVm.name;
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 = { nameservers = [
eth0 = { "95.215.185.6"
ipv4 = { "95.215.185.7"
addresses = [ "2a00:51c0::5fd7:b906"
{ "2a00:51c0::5fd7:b907"
inherit (config.fediversityVm.ipv4) address prefixLength; ];
}
]; firewall.enable = false;
}; nftables = {
ipv6 = { enable = true;
addresses = [ rulesetFile = ./nftables-ruleset.nft;
{
inherit (config.fediversityVm.ipv6) address prefixLength;
}
];
};
}; };
}; }
defaultGateway = { ## IPv4
address = config.fediversityVm.ipv4.gateway; (mkIf config.fediversityVm.ipv4.enable {
interface = "eth0"; interfaces.${config.fediversityVm.ipv4.interface}.ipv4.addresses = [
}; { inherit (config.fediversityVm.ipv4) address prefixLength; }
defaultGateway6 = { ];
address = config.fediversityVm.ipv6.gateway; defaultGateway = {
interface = "eth0"; address = config.fediversityVm.ipv4.gateway;
}; interface = config.fediversityVm.ipv4.interface;
};
})
nameservers = [ ## IPv6
"95.215.185.6" (mkIf config.fediversityVm.ipv6.enable {
"95.215.185.7" interfaces.${config.fediversityVm.ipv6.interface}.ipv6.addresses = [
"2a00:51c0::5fd7:b906" { inherit (config.fediversityVm.ipv6) address prefixLength; }
"2a00:51c0::5fd7:b907" ];
]; defaultGateway6 = {
address = config.fediversityVm.ipv6.gateway;
firewall.enable = false; interface = config.fediversityVm.ipv6.interface;
nftables = { };
enable = true; })
rulesetFile = ./nftables-ruleset.nft; ];
};
};
}; };
} }

View file

@ -91,6 +91,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
@ -116,6 +127,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
@ -155,5 +177,13 @@ in
this for testing machines, as it is a security hole for so many reasons. this for testing machines, as it is a security hole for so many reasons.
''; '';
}; };
isQemuVm = mkOption {
description = ''
Whether the machine is a QEMU VM. This will import all the necessary
things.
'';
default = true;
};
}; };
} }