forked from mirrors_public/oddlama_nix-config
feat: modularize link renaming
This commit is contained in:
parent
e8f50ab906
commit
14ef8ef877
10 changed files with 98 additions and 70 deletions
12
flake.lock
generated
12
flake.lock
generated
|
@ -28,11 +28,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1682854491,
|
"lastModified": 1683715679,
|
||||||
"narHash": "sha256-xFTgMA+whHZyRAAN6EQUX0gMAjSGi44+sFbIPOXVShw=",
|
"narHash": "sha256-Zq2liHoVTNYql94XPTpEInQq5yY0NjRa9ZLYJv55dgE=",
|
||||||
"owner": "oddlama",
|
"owner": "oddlama",
|
||||||
"repo": "agenix-rekey",
|
"repo": "agenix-rekey",
|
||||||
"rev": "7096bf1e2acdbf8c6e8dda6f452d06d9d72fb3a7",
|
"rev": "e5e84230bfa071685a05acdc11a94e3be672e541",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -207,11 +207,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1683543852,
|
"lastModified": 1683651229,
|
||||||
"narHash": "sha256-aS9qNcg9GwSYFLCWa3Lw+2nVPG11mmQ3B7Oka1hh04M=",
|
"narHash": "sha256-HN0Mw8g1XQIrcdyzqT00YW0Uqi/V/BUUUAgvcK1pcSM=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "3f3fa731ad0f99741d4dc98e8e1287b45e30b452",
|
"rev": "983f8a1bb965b261492123cd8e2d07da46d4d50a",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -10,8 +10,9 @@
|
||||||
./system.nix
|
./system.nix
|
||||||
./xdg.nix
|
./xdg.nix
|
||||||
|
|
||||||
../../../modules/wireguard.nix
|
../../../modules/interface-naming.nix
|
||||||
../../../modules/microvms.nix
|
../../../modules/microvms.nix
|
||||||
|
../../../modules/wireguard.nix
|
||||||
];
|
];
|
||||||
|
|
||||||
home-manager = {
|
home-manager = {
|
||||||
|
|
|
@ -80,16 +80,5 @@ in {
|
||||||
};
|
};
|
||||||
|
|
||||||
# Rename known network interfaces
|
# Rename known network interfaces
|
||||||
services.udev.packages =
|
extra.networking.renameInterfacesByMac = lib.mapAttrs (_: v: v.mac) (nodeSecrets.networking.interfaces or {});
|
||||||
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]);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,7 @@
|
||||||
optimise.automatic = true;
|
optimise.automatic = true;
|
||||||
gc = {
|
gc = {
|
||||||
automatic = true;
|
automatic = true;
|
||||||
dates = "biweekly";
|
dates = "monthly";
|
||||||
options = "--delete-older-than 90d";
|
options = "--delete-older-than 90d";
|
||||||
};
|
};
|
||||||
# Define global flakes for this system
|
# Define global flakes for this system
|
||||||
|
|
|
@ -27,12 +27,12 @@
|
||||||
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" "r8169"];
|
boot.initrd.availableKernelModules = ["xhci_pci" "ahci" "nvme" "usbhid" "usb_storage" "sd_mod" "sdhci_pci" "r8169"];
|
||||||
|
|
||||||
extra.microvms = let
|
extra.microvms = let
|
||||||
macOffset = config.lib.net.mac.addPrivate nodeSecrets.networking.interfaces."wan-nic".mac;
|
macOffset = config.lib.net.mac.addPrivate nodeSecrets.networking.interfaces.lan.mac;
|
||||||
in {
|
in {
|
||||||
test = {
|
test = {
|
||||||
autostart = true;
|
autostart = true;
|
||||||
mac = macOffset "00:00:00:00:00:01";
|
mac = macOffset "00:00:00:00:00:11";
|
||||||
macvtap = "wan";
|
macvtap = "lan";
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,12 +1,4 @@
|
||||||
{
|
{
|
||||||
config,
|
|
||||||
inputs,
|
|
||||||
lib,
|
|
||||||
microvm,
|
|
||||||
nixos-hardware,
|
|
||||||
pkgs,
|
|
||||||
...
|
|
||||||
}: {
|
|
||||||
imports = [
|
imports = [
|
||||||
../../../common/core
|
../../../common/core
|
||||||
|
|
||||||
|
@ -14,15 +6,4 @@
|
||||||
];
|
];
|
||||||
|
|
||||||
home-manager.users.root.home.minimal = true;
|
home-manager.users.root.home.minimal = true;
|
||||||
|
|
||||||
systemd.network.networks = {
|
|
||||||
"10-wan" = {
|
|
||||||
# TODO
|
|
||||||
matchConfig.Name = "en*";
|
|
||||||
DHCP = "yes";
|
|
||||||
networkConfig.IPv6PrivacyExtensions = "kernel";
|
|
||||||
dhcpV4Config.RouteMetric = 20;
|
|
||||||
dhcpV6Config.RouteMetric = 20;
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,24 +13,12 @@ in {
|
||||||
|
|
||||||
boot.initrd.systemd.network = {
|
boot.initrd.systemd.network = {
|
||||||
enable = true;
|
enable = true;
|
||||||
networks."10-wan" = {
|
networks = {inherit (config.systemd.network.networks) "10-wan";};
|
||||||
DHCP = "yes";
|
|
||||||
#address = [
|
|
||||||
# "192.168.178.2/24"
|
|
||||||
# "fd00::1/64"
|
|
||||||
#];
|
|
||||||
#gateway = [
|
|
||||||
#];
|
|
||||||
matchConfig.MACAddress = nodeSecrets.networking.interfaces."wan-nic".mac;
|
|
||||||
networkConfig.IPv6PrivacyExtensions = "kernel";
|
|
||||||
dhcpV4Config.RouteMetric = 20;
|
|
||||||
dhcpV6Config.RouteMetric = 20;
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
systemd.network.netdevs."10-wan" = {
|
systemd.network.netdevs."10-lan-self" = {
|
||||||
netdevConfig = {
|
netdevConfig = {
|
||||||
Name = "wan";
|
Name = "lan-self";
|
||||||
Kind = "macvtap";
|
Kind = "macvtap";
|
||||||
};
|
};
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
|
@ -41,23 +29,13 @@ in {
|
||||||
|
|
||||||
systemd.network.networks = {
|
systemd.network.networks = {
|
||||||
"10-lan" = {
|
"10-lan" = {
|
||||||
address = [net.lan.ipv4cidr net.lan.ipv6cidr];
|
|
||||||
matchConfig.MACAddress = nodeSecrets.networking.interfaces.lan.mac;
|
matchConfig.MACAddress = nodeSecrets.networking.interfaces.lan.mac;
|
||||||
networkConfig = {
|
|
||||||
IPForward = "yes";
|
|
||||||
IPv6PrivacyExtensions = "kernel";
|
|
||||||
};
|
|
||||||
dhcpV4Config.RouteMetric = 10;
|
|
||||||
dhcpV6Config.RouteMetric = 10;
|
|
||||||
};
|
|
||||||
"10-wan-nic" = {
|
|
||||||
matchConfig.MACAddress = nodeSecrets.networking.interfaces."wan-nic".mac;
|
|
||||||
extraConfig = ''
|
extraConfig = ''
|
||||||
[Network]
|
[Network]
|
||||||
MACVTAP=wan
|
MACVTAP=lan-self
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
"11-wan" = {
|
"10-wan" = {
|
||||||
DHCP = "yes";
|
DHCP = "yes";
|
||||||
#address = [
|
#address = [
|
||||||
# "192.168.178.2/24"
|
# "192.168.178.2/24"
|
||||||
|
@ -65,11 +43,22 @@ in {
|
||||||
#];
|
#];
|
||||||
#gateway = [
|
#gateway = [
|
||||||
#];
|
#];
|
||||||
matchConfig.Name = "wan";
|
matchConfig.MACAddress = nodeSecrets.networking.interfaces.wan.mac;
|
||||||
networkConfig.IPv6PrivacyExtensions = "kernel";
|
networkConfig.IPv6PrivacyExtensions = "kernel";
|
||||||
dhcpV4Config.RouteMetric = 20;
|
dhcpV4Config.RouteMetric = 20;
|
||||||
dhcpV6Config.RouteMetric = 20;
|
dhcpV6Config.RouteMetric = 20;
|
||||||
};
|
};
|
||||||
|
"11-lan-self" = {
|
||||||
|
address = [net.lan.ipv4cidr net.lan.ipv6cidr];
|
||||||
|
matchConfig.Name = "lan-self";
|
||||||
|
networkConfig = {
|
||||||
|
IPForward = "yes";
|
||||||
|
IPv6PrivacyExtensions = "kernel";
|
||||||
|
ConfigureWithoutCarrier = true;
|
||||||
|
};
|
||||||
|
dhcpV4Config.RouteMetric = 10;
|
||||||
|
dhcpV6Config.RouteMetric = 10;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
networking.nftables.firewall = {
|
networking.nftables.firewall = {
|
||||||
|
|
Binary file not shown.
47
modules/interface-naming.nix
Normal file
47
modules/interface-naming.nix
Normal file
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
extraLib,
|
||||||
|
lib,
|
||||||
|
pkgs,
|
||||||
|
...
|
||||||
|
}: let
|
||||||
|
inherit
|
||||||
|
(lib)
|
||||||
|
attrValues
|
||||||
|
concatStringsSep
|
||||||
|
mapAttrsToList
|
||||||
|
mkIf
|
||||||
|
mkOption
|
||||||
|
types
|
||||||
|
;
|
||||||
|
|
||||||
|
cfg = config.extra.networking.renameInterfacesByMac;
|
||||||
|
|
||||||
|
interfaceNamesUdevRules = pkgs.writeTextFile {
|
||||||
|
name = "interface-names-udev-rules";
|
||||||
|
text = concatStringsSep "\n" (mapAttrsToList
|
||||||
|
(name: mac: ''SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${mac}", NAME:="${name}"'')
|
||||||
|
cfg);
|
||||||
|
destination = "/etc/udev/rules.d/01-interface-names.rules";
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
options.extra.networking.renameInterfacesByMac = mkOption {
|
||||||
|
default = {};
|
||||||
|
example = {lan = "11:22:33:44:55:66";};
|
||||||
|
description = "Allows naming of network interfaces based on their physical address";
|
||||||
|
type = types.attrsOf types.str;
|
||||||
|
};
|
||||||
|
|
||||||
|
config = {
|
||||||
|
assertions = let
|
||||||
|
duplicateMacs = extraLib.duplicates (attrValues cfg);
|
||||||
|
in [
|
||||||
|
{
|
||||||
|
assertion = duplicateMacs == [];
|
||||||
|
message = "Duplicate mac addresses found in network interface name assignment: ${concatStringsSep ", " duplicateMacs}";
|
||||||
|
}
|
||||||
|
];
|
||||||
|
|
||||||
|
services.udev.packages = lib.mkIf (cfg != {}) [interfaceNamesUdevRules];
|
||||||
|
};
|
||||||
|
}
|
|
@ -72,6 +72,21 @@
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extra.networking.renameInterfacesByMac.${vmCfg.linkName} = vmCfg.mac;
|
||||||
|
|
||||||
|
systemd.network.networks = {
|
||||||
|
"10-${vmCfg.linkName}" = {
|
||||||
|
matchConfig.Name = vmCfg.linkName;
|
||||||
|
DHCP = "yes";
|
||||||
|
networkConfig = {
|
||||||
|
IPv6PrivacyExtensions = "kernel";
|
||||||
|
ConfigureWithoutCarrier = true;
|
||||||
|
};
|
||||||
|
dhcpV4Config.RouteMetric = 20;
|
||||||
|
dhcpV6Config.RouteMetric = 20;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
# TODO change once microvms are compatible with stage-1 systemd
|
# TODO change once microvms are compatible with stage-1 systemd
|
||||||
boot.initrd.systemd.enable = mkForce false;
|
boot.initrd.systemd.enable = mkForce false;
|
||||||
};
|
};
|
||||||
|
@ -90,6 +105,12 @@ in {
|
||||||
description = mdDoc "Whether this VM should be started automatically with the host";
|
description = mdDoc "Whether this VM should be started automatically with the host";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
linkName = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "wan";
|
||||||
|
description = mdDoc "The main ethernet link name inside of the VM";
|
||||||
|
};
|
||||||
|
|
||||||
mac = mkOption {
|
mac = mkOption {
|
||||||
type = config.lib.net.types.mac;
|
type = config.lib.net.types.mac;
|
||||||
description = mdDoc "The MAC address to assign to this VM";
|
description = mdDoc "The MAC address to assign to this VM";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue