vanadium: refactor network configuration

This generates the "key" used in a external password configuration,
reducing the boilerplate.
This commit is contained in:
Primrose 2025-09-10 13:24:44 +08:00
parent 8cb8166254
commit 545234254b
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
2 changed files with 43 additions and 34 deletions

View file

@ -32,41 +32,52 @@
userControlled.enable = true;
secretsFile = config.age.secrets.wpa_password.path;
networks = let
orderedByGroups = networkGroups: let
groupsCount = builtins.length networkGroups;
withPriority =
lib.lists.imap0
(i: lib.mapAttrs (_: n: n // {priority = groupsCount - i;}))
networkGroups;
# The higher the more preferred
prio = i: lib.mapAttrs (_: conf: conf // {priority = i;});
privatePrio = prio 10;
limitedDataPrio = prio (-10);
openNetworks = lib.flip lib.genAttrs (_: {});
pskNetworks = let
# wpa_supplicant uses `strchr` to seek to the first `=`, so the only forbidden character is `=`.
escapePwdKey = lib.replaceStrings ["="] ["_"];
in
lib.mkMerge withPriority;
lib.flip lib.genAttrs (name: {pskRaw = "ext:${escapePwdKey name}";});
in
orderedByGroups [
{
"HiddenParadize@Earth2077".pskRaw = "ext:HOME";
"Peis Wifi".pskRaw = "ext:PEI";
"girlypop-net".pskRaw = "ext:GIRLYPOP";
"annapurna".pskRaw = "ext:ANNAPURNA";
"5526-1" = {
pskRaw = "ext:5526-1";
extraConfig = ''
bgscan="simple:30:-70:3600"
'';
};
}
{
"A-WAY".pskRaw = "ext:A-WAY";
"CAT.jpgcafe".pskRaw = "ext:CAT.jpgcafe";
lib.mkMerge [
(privatePrio (pskNetworks [
"HiddenParadize@Earth2077"
"Peis Wifi"
"girlypop-net"
"annapurna"
"5526-1"
"A-WAY"
"CAT.jpgcafe"
# TODO: Figure out how to configure networks of "same password, different ssid".
#
# In the following documentation, bssid can be used to match
# Besides, is it possible to have duplicated SSID?
# https://man.freebsd.org/cgi/man.cgi?wpa_supplicant.conf%285%29
"LOUISA".pskRaw = "ext:LOUISA"; # 區公所
"LouisaCoffee".pskRaw = "ext:LouisaCoffee"; # 七張
"LOUISA" # 區公所
"LouisaCoffee" # 七張
]))
(limitedDataPrio (pskNetworks [
"iPhone de Léana "
]))
(openNetworks [
"_SNCF_WIFI_INOUI"
"_WIFI_LYRIA"
"EurostarTrainsWiFi"
"SBB-FREE"
"AOT Airport Free Wi-Fi by NT"
])
# TODO: Delete this when my account is deactivated
{
eduroam = {
authProtocols = ["WPA-EAP"];
auth = ''
@ -82,15 +93,13 @@
'';
};
}
# Other per-network configuration
# bgscan has performance penalty so we don't enable it globally
{
"_SNCF_WIFI_INOUI" = {};
"_WIFI_LYRIA" = {};
"EurostarTrainsWiFi" = {};
"SBB-FREE" = {};
"AOT Airport Free Wi-Fi by NT" = {};
}
{
"iPhone de Léana ".pskRaw = "ext:PHONE";
"5526-1".extraConfig = ''
bgscan="simple:30:-70:3600"
'';
}
];
};