feat: move modules/interface-naming.nix -> nixos-extra-modules

This commit is contained in:
oddlama 2023-12-22 01:49:28 +01:00
parent 61375199e5
commit aa9ba64bff
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
5 changed files with 200 additions and 96 deletions

View file

@ -5,6 +5,7 @@
inputs.agenix.nixosModules.default
inputs.disko.nixosModules.disko
inputs.elewrap.nixosModules.default
inputs.extra-modules.nixosModules.default
inputs.home-manager.nixosModules.default
inputs.impermanence.nixosModules.impermanence
inputs.nixos-nftables-firewall.nixosModules.default
@ -30,7 +31,6 @@
./acme-wildcard.nix
./deterministic-ids.nix
./distributed-config.nix
./interface-naming.nix
./kanidm.nix
./meta.nix
./nginx.nix

View file

@ -32,7 +32,12 @@ in {
hypervisor = mkDefault "qemu";
# Give them some juice by default
mem = mkDefault (2 * 1024);
# TODO
mem = mkDefault 1024;
# Add a writable store overlay, but since this is always ephemeral
# disable any store optimization from nix.
writableStoreOverlay = "/nix/.rw-store";
# MACVTAP bridge to the host's network
interfaces = [
@ -67,10 +72,6 @@ in {
);
};
# Add a writable store overlay, but since this is always ephemeral
# disable any store optimization from nix.
microvm.writableStoreOverlay = "/nix/.rw-store";
networking.renameInterfacesByMac.${guestCfg.networking.mainLinkName} = guestCfg.microvm.mac;
systemd.network.networks."10-${guestCfg.networking.mainLinkName}".matchConfig.MACAddress = guestCfg.microvm.mac;
};

View file

@ -1,48 +0,0 @@
# Provides an option to easily rename interfaces by their mac addresses.
{
config,
lib,
pkgs,
...
}: let
inherit
(lib)
attrValues
concatStringsSep
duplicates
mapAttrsToList
mkOption
types
;
cfg = config.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.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 = lib.mkIf (cfg != {}) {
assertions = let
duplicateMacs = duplicates (attrValues cfg);
in [
{
assertion = duplicateMacs == [];
message = "Duplicate mac addresses found in network interface name assignment: ${concatStringsSep ", " duplicateMacs}";
}
];
services.udev.packages = [interfaceNamesUdevRules];
boot.initrd.services.udev.packages = [interfaceNamesUdevRules];
};
}