summaryrefslogtreecommitdiff
path: root/modules/root
diff options
context:
space:
mode:
Diffstat (limited to 'modules/root')
-rw-r--r--modules/root/default.nix1
-rw-r--r--modules/root/net-iface-labels.nix27
2 files changed, 28 insertions, 0 deletions
diff --git a/modules/root/default.nix b/modules/root/default.nix
index 7f647b5..8072525 100644
--- a/modules/root/default.nix
+++ b/modules/root/default.nix
@@ -11,6 +11,7 @@
./hosts.nix
./localization.nix
./nas.nix
+ ./net-iface-labels.nix
./nix.nix
./normaluser.nix
./pipewire.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
+ );
+ };
+}