tree-wide: deduplicate network compat script

This commit is contained in:
Primrose 2025-11-02 16:35:11 +08:00
parent 5447573e69
commit 432efd430c
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
5 changed files with 43 additions and 69 deletions

View file

@ -0,0 +1,37 @@
#
# This loads the list of networks as a NixOS wpa_supplicant compatible attrset
#
let
sources = import ../../npins;
lib = import (sources.nixpkgs + "/lib");
# wpa_supplicant uses `strchr` to seek to the first `=`, so the only forbidden character is `=`.
escapePwdKey = lib.replaceStrings ["="] ["_"];
go = networkArgs @ {
ssid,
# Custom fields wrapping nixpkgs module options
hasPassword ? false,
scanOnLowSignal ? false,
randomizeMac ? false,
...
}: {
${ssid} = lib.mkMerge [
(builtins.removeAttrs networkArgs ["ssid" "hasPassword" "scanOnLowSignal" "randomizeMac"])
(lib.optionalAttrs hasPassword {
pskRaw = "ext:${escapePwdKey ssid}";
})
(lib.optionalAttrs scanOnLowSignal {
extraConfig = ''
bgscan="simple:30:-70:3600"
'';
})
(lib.optionalAttrs randomizeMac {
extraConfig = ''
mac_addr=1
'';
})
];
};
in
ns: lib.mkMerge (map go ns)