mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 14:49:14 +00:00
vanadium/connectivity: refactor network
Another week another useless abstraction
This commit is contained in:
parent
6c6d4ec13a
commit
3ac7e3b73b
1 changed files with 120 additions and 84 deletions
|
|
@ -38,43 +38,76 @@
|
||||||
secretsFile = config.age.secrets.wpa_password.path;
|
secretsFile = config.age.secrets.wpa_password.path;
|
||||||
scanOnLowSignal = false;
|
scanOnLowSignal = false;
|
||||||
networks = let
|
networks = let
|
||||||
properties = lib.flip lib.pipe;
|
|
||||||
networks = lib.flip lib.genAttrs (_: {});
|
|
||||||
|
|
||||||
# The higher the more preferred
|
|
||||||
setPrio = i: lib.mapAttrs (_: conf: conf // {priority = i;});
|
|
||||||
private = setPrio 10;
|
|
||||||
limited = setPrio (-10);
|
|
||||||
|
|
||||||
extraConfig = value: conf: conf // {extraConfig = conf.extraConfig or "" + value;};
|
|
||||||
randomizeMac = lib.mapAttrs (_: extraConfig "mac_addr=1\n");
|
|
||||||
roaming = lib.mapAttrs (_: extraConfig "bgscan=\"simple:30:-70:3600\"\n");
|
|
||||||
|
|
||||||
hasPsk = let
|
|
||||||
# wpa_supplicant uses `strchr` to seek to the first `=`, so the only forbidden character is `=`.
|
# wpa_supplicant uses `strchr` to seek to the first `=`, so the only forbidden character is `=`.
|
||||||
escapePwdKey = lib.replaceStrings ["="] ["_"];
|
escapePwdKey = lib.replaceStrings ["="] ["_"];
|
||||||
in
|
|
||||||
lib.mapAttrs (name: conf: conf // {pskRaw = "ext:${escapePwdKey conf.ssid or name}";});
|
|
||||||
in
|
|
||||||
lib.mkMerge [
|
|
||||||
(properties [private hasPsk]
|
|
||||||
(networks [
|
|
||||||
"~"
|
|
||||||
"Pei’s Wifi"
|
|
||||||
"girlypop-net"
|
|
||||||
]))
|
|
||||||
(properties [private roaming hasPsk]
|
|
||||||
(networks [
|
|
||||||
"annapurna"
|
|
||||||
"5526-1" # TODO: prefer dead dead dodo later
|
|
||||||
]))
|
|
||||||
|
|
||||||
#
|
privatePriority = 10;
|
||||||
# School
|
limitedPriority = -10;
|
||||||
#
|
|
||||||
(properties [private roaming]
|
fromList = ns: let
|
||||||
|
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
|
||||||
|
lib.mkMerge (map go ns);
|
||||||
|
in
|
||||||
|
fromList [
|
||||||
{
|
{
|
||||||
eduroam = {
|
ssid = "~";
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "Pei’s Wifi";
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "girlypop-net";
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ssid = "annapurna";
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
scanOnLowSignal = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "5526-1"; # TODO: set bssid preference ?
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
scanOnLowSignal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
ssid = "eduroam";
|
||||||
|
priority = privatePriority;
|
||||||
|
scanOnLowSignal = true;
|
||||||
|
|
||||||
authProtocols = ["WPA-EAP"];
|
authProtocols = ["WPA-EAP"];
|
||||||
auth = ''
|
auth = ''
|
||||||
pairwise=CCMP
|
pairwise=CCMP
|
||||||
|
|
@ -87,49 +120,52 @@
|
||||||
password=ext:EDUROAM
|
password=ext:EDUROAM
|
||||||
anonymous_identity="anonymous@univ-rennes.fr"
|
anonymous_identity="anonymous@univ-rennes.fr"
|
||||||
'';
|
'';
|
||||||
};
|
}
|
||||||
})
|
|
||||||
|
|
||||||
#
|
{
|
||||||
# Cafés
|
ssid = "A-WAY";
|
||||||
#
|
priority = privatePriority;
|
||||||
(properties [private randomizeMac hasPsk]
|
hasPassword = true;
|
||||||
(networks [
|
randomizeMac = true;
|
||||||
"A-WAY"
|
}
|
||||||
"CAT.jpgcafe"
|
{
|
||||||
"LOUISA" # 區公所
|
ssid = "CAT.jpgcafe";
|
||||||
"LouisaCoffee" # 七張
|
priority = privatePriority;
|
||||||
"MetroTaipei x Louisa" # 大安
|
hasPassword = true;
|
||||||
]))
|
randomizeMac = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "LOUISA"; # 區公所
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
randomizeMac = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "LouisaCoffee"; # 七張
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
randomizeMac = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
ssid = "MetroTaipei x Louisa"; # 大安
|
||||||
|
priority = privatePriority;
|
||||||
|
hasPassword = true;
|
||||||
|
randomizeMac = true;
|
||||||
|
}
|
||||||
|
|
||||||
#
|
{ssid = "_SNCF_WIFI_INOUI";}
|
||||||
# Open networks
|
{ssid = "_WIFI_LYRIA";}
|
||||||
#
|
{ssid = "EurostarTrainsWiFi";}
|
||||||
#
|
{ssid = "SBB-FREE";}
|
||||||
# Use this link to do portal login
|
{ssid = "AOT Airport Free Wi-Fi by NT";}
|
||||||
# http://detectportal.firefox.com/canonical.html
|
{ssid = "NewTaipei";}
|
||||||
(properties [randomizeMac]
|
{ssid = "Fami-WiFi";}
|
||||||
(networks [
|
|
||||||
# Transport
|
|
||||||
"_SNCF_WIFI_INOUI"
|
|
||||||
"_WIFI_LYRIA"
|
|
||||||
"EurostarTrainsWiFi"
|
|
||||||
"SBB-FREE"
|
|
||||||
"AOT Airport Free Wi-Fi by NT"
|
|
||||||
|
|
||||||
# Library
|
{
|
||||||
"NewTaipei"
|
ssid = "iPhone de Léana 江";
|
||||||
|
priority = limitedPriority;
|
||||||
"Fami-WiFi"
|
hasPassword = true;
|
||||||
]))
|
}
|
||||||
|
|
||||||
#
|
|
||||||
# Phones
|
|
||||||
#
|
|
||||||
(properties [limited hasPsk]
|
|
||||||
(networks [
|
|
||||||
"iPhone de Léana 江"
|
|
||||||
]))
|
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue