1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-11 07:10:39 +02:00

feat: add declarative microvms

This commit is contained in:
oddlama 2023-05-08 14:48:59 +02:00
parent 1a7472207a
commit 1b9d9fc58a
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
8 changed files with 124 additions and 80 deletions

View file

@ -16,7 +16,7 @@
;
in {
networking = {
hostName = mkDefault nodeName;
hostName = nodeName;
useDHCP = mkForce false;
useNetworkd = true;
dhcpcd.enable = false;
@ -80,14 +80,16 @@ in {
};
# Rename known network interfaces
services.udev.packages = let
interfaceNamesUdevRules = pkgs.writeTextFile {
name = "interface-names-udev-rules";
text = concatStringsSep "\n" (mapAttrsToList (
interface: attrs: ''SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${attrs.mac}", NAME:="${interface}"''
)
nodeSecrets.networking.interfaces);
destination = "/etc/udev/rules.d/01-interface-names.rules";
};
in [interfaceNamesUdevRules];
services.udev.packages =
lib.mkIf ((nodeSecrets.networking.interfaces or {}) != {})
(let
interfaceNamesUdevRules = pkgs.writeTextFile {
name = "interface-names-udev-rules";
text = concatStringsSep "\n" (mapAttrsToList (
interface: attrs: ''SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${attrs.mac}", NAME:="${interface}"''
)
nodeSecrets.networking.interfaces);
destination = "/etc/udev/rules.d/01-interface-names.rules";
};
in [interfaceNamesUdevRules]);
}

View file

@ -1,5 +1,8 @@
{
config,
inputs,
lib,
microvm,
nixos-hardware,
pkgs,
...
@ -8,6 +11,8 @@
nixos-hardware.common-cpu-intel
nixos-hardware.common-pc-ssd
microvm.host
../common/core
../common/hardware/intel.nix
../common/hardware/physical.nix
@ -23,6 +28,22 @@
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" "r8169"];
microvm.vms = {
test = let
node =
(import ../../nix/generate-node.nix inputs)
"ward-microvm-test" {
system = "x86_64-linux";
config = ./microvms/test;
};
in {
inherit (node) pkgs specialArgs;
config = {
inherit (node) imports;
};
};
};
#services.authelia.instances.main = {
# enable = true;
# settings = {

View file

@ -0,0 +1,28 @@
{
config,
inputs,
lib,
microvm,
nixos-hardware,
pkgs,
...
}: {
imports = [
microvm.microvm
../../../common/core
../../../../users/root
];
systemd.network.networks = {
"10-wan" = {
# TODO
matchConfig.Name = "en*";
DHCP = "yes";
networkConfig.IPv6PrivacyExtensions = "kernel";
dhcpV4Config.RouteMetric = 20;
dhcpV6Config.RouteMetric = 20;
};
};
}