From f354cefff68bd8b3d66e077bd35a857f155d70dd Mon Sep 17 00:00:00 2001 From: Tim Keller Date: Tue, 19 Aug 2025 21:38:50 -0500 Subject: add net interface labeling feature --- modules/root/net-iface-labels.nix | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 modules/root/net-iface-labels.nix (limited to 'modules/root/net-iface-labels.nix') diff --git a/modules/root/net-iface-labels.nix b/modules/root/net-iface-labels.nix new file mode 100644 index 0000000..4949659 --- /dev/null +++ b/modules/root/net-iface-labels.nix @@ -0,0 +1,27 @@ +{ config, lib, ... }: let + validMac = str: builtins.match ''^[0-9a-fA-F]{2}(:[0-9a-fA-F]{2}){5}$'' str != null; + macAddressType = lib.types.str // { + check = validMac; + description = "a mac address (xx:xx:xx:xx:xx:xx)"; + }; +in { + options.networking.interfaceLabels = { + enable = lib.mkEnableOption "manually label network interfaces"; + interfaces = lib.mkOption { + type = lib.types.attrsOf macAddressType; + default = {}; + example = { + "lan0" = "00:11:22:33:44:55"; + "lan1" = "66:77:88:99:AA:BB"; + }; + description = "label network interfaces by their mac address"; + }; + }; + + config = lib.mkIf config.networking.interfaceLabels.enable { + networking.usePredictableInterfaceNames = false; + services.udev.extraRules = lib.concatStringsSep "\n" ( + lib.mapAttrsToList (name: mac: ''ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="${mac}", NAME="${name}"'') config.networking.interfaceLabels.interfaces + ); + }; +} -- cgit v1.2.3