Serge Bazanski | 6abe4fa | 2020-10-03 00:18:34 +0200 | [diff] [blame] | 1 | # Sketchy little module to renamei interfaces by MAC. |
| 2 | # This only works on startup. |
| 3 | |
| 4 | { config, lib, pkgs, ... }: |
| 5 | |
| 6 | with lib; |
| 7 | let |
| 8 | cfg = config.hscloud.renameInterfaces; |
| 9 | in { |
| 10 | options.hscloud.renameInterfaces = mkOption { |
| 11 | type = with types; attrsOf (submodule { |
| 12 | options = { |
| 13 | mac = mkOption { |
| 14 | type = types.str; |
| 15 | description = '' |
| 16 | MAC address to match by, in hexadecimal form (ie. ac:1f:6b:1c:d7:ae). |
| 17 | ''; |
| 18 | }; |
| 19 | }; |
| 20 | }); |
| 21 | description = '' |
| 22 | Interfaces to rename by property (eg. MAC address). |
| 23 | ''; |
| 24 | }; |
| 25 | |
| 26 | config.services.udev.extraRules = concatStringsSep "\n" (mapAttrsToList (n: v: '' |
| 27 | ACTION=="add", SUBSYSTEM=="net", ATTR{address}=="${v.mac}", ATTR{addr_assign_type}=="0", NAME="${n}" |
| 28 | '') cfg); |
| 29 | } |