mirror of
https://codeberg.org/leana8959/.files.git
synced 2025-12-06 06:39: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;
|
||||
scanOnLowSignal = false;
|
||||
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 `=`.
|
||||
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
|
||||
]))
|
||||
|
||||
#
|
||||
# School
|
||||
#
|
||||
(properties [private roaming]
|
||||
privatePriority = 10;
|
||||
limitedPriority = -10;
|
||||
|
||||
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"];
|
||||
auth = ''
|
||||
pairwise=CCMP
|
||||
|
|
@ -87,49 +120,52 @@
|
|||
password=ext:EDUROAM
|
||||
anonymous_identity="anonymous@univ-rennes.fr"
|
||||
'';
|
||||
};
|
||||
})
|
||||
}
|
||||
|
||||
#
|
||||
# Cafés
|
||||
#
|
||||
(properties [private randomizeMac hasPsk]
|
||||
(networks [
|
||||
"A-WAY"
|
||||
"CAT.jpgcafe"
|
||||
"LOUISA" # 區公所
|
||||
"LouisaCoffee" # 七張
|
||||
"MetroTaipei x Louisa" # 大安
|
||||
]))
|
||||
{
|
||||
ssid = "A-WAY";
|
||||
priority = privatePriority;
|
||||
hasPassword = true;
|
||||
randomizeMac = true;
|
||||
}
|
||||
{
|
||||
ssid = "CAT.jpgcafe";
|
||||
priority = privatePriority;
|
||||
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;
|
||||
}
|
||||
|
||||
#
|
||||
# Open networks
|
||||
#
|
||||
#
|
||||
# Use this link to do portal login
|
||||
# http://detectportal.firefox.com/canonical.html
|
||||
(properties [randomizeMac]
|
||||
(networks [
|
||||
# Transport
|
||||
"_SNCF_WIFI_INOUI"
|
||||
"_WIFI_LYRIA"
|
||||
"EurostarTrainsWiFi"
|
||||
"SBB-FREE"
|
||||
"AOT Airport Free Wi-Fi by NT"
|
||||
{ssid = "_SNCF_WIFI_INOUI";}
|
||||
{ssid = "_WIFI_LYRIA";}
|
||||
{ssid = "EurostarTrainsWiFi";}
|
||||
{ssid = "SBB-FREE";}
|
||||
{ssid = "AOT Airport Free Wi-Fi by NT";}
|
||||
{ssid = "NewTaipei";}
|
||||
{ssid = "Fami-WiFi";}
|
||||
|
||||
# Library
|
||||
"NewTaipei"
|
||||
|
||||
"Fami-WiFi"
|
||||
]))
|
||||
|
||||
#
|
||||
# Phones
|
||||
#
|
||||
(properties [limited hasPsk]
|
||||
(networks [
|
||||
"iPhone de Léana 江"
|
||||
]))
|
||||
{
|
||||
ssid = "iPhone de Léana 江";
|
||||
priority = limitedPriority;
|
||||
hasPassword = true;
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue