wifi: Fix installation

This commit is contained in:
Geoffrey Frogeye 2025-05-09 13:42:45 +02:00
parent 8179433c41
commit ea9a75d495
4 changed files with 34 additions and 37 deletions

View file

@ -1,19 +0,0 @@
{ ... }:
{
config = {
networking.wireless.networks."38C3".auth = ''
key_mgmt=WPA-EAP
eap=TTLS
identity="38C3"
password="38C3"
ca_cert="${
builtins.fetchurl {
url = "https://letsencrypt.org/certs/isrgrootx1.pem";
sha256 = "sha256:1la36n2f31j9s03v847ig6ny9lr875q3g7smnq33dcsmf2i5gd92";
}
}"
altsubject_match="DNS:radius.c3noc.net"
phase2="auth=PAP"
'';
};
}

View file

@ -5,7 +5,6 @@
../common/frogarized
./battery.nix
./boot
./ccc
./common.nix
./cuda
./desktop

View file

@ -21,9 +21,38 @@ in
temp="$(mktemp --directory --suffix="-install-wifi")"
cd "$temp"
bus_get() {
sudo busctl -j get-property "fi.w1.wpa_supplicant1" "$@"
}
network_config() {
bus_get "$1" "fi.w1.wpa_supplicant1.Network" Properties | jq '.data | keys[] as $k | "\($k)=\(.[$k] | .data)"' -r | sort
}
# Temporarily create a new network to get defaults
default_id="$(wpa_cli add_network | tail -n1)"
network_config "/fi/w1/wpa_supplicant1/Interfaces/0/Networks/$default_id" > default.conf
wpa_cli remove_network "$default_id"
networks_config() {
# List all interfaces
bus_get "/fi/w1/wpa_supplicant1" "fi.w1.wpa_supplicant1" Interfaces | jq '.data[]' -r | while read -r interface
do
# List all networks
bus_get "$interface" "fi.w1.wpa_supplicant1.Interface" Networks | jq '.data[]' -r | while read -r network
do
# Show configuration
echo "[$network]"
network_config "$network" > current.conf
comm -23 current.conf default.conf
rm current.conf
echo
done
done
}
# Save config for diffing later
wpa_cli save_config > /dev/null
cat <(sudo cat /run/wpa_supplicant/wpa_supplicant.conf) > old.conf
networks_config > old.conf
# Export Wi-Fi config from pass
${importScript}
@ -38,11 +67,10 @@ in
sudo ${applyScript}
# Diff the config
wpa_cli save_config > /dev/null
cat <(sudo cat /run/wpa_supplicant/wpa_supplicant.conf) > new.conf
networks_config > new.conf
diff --color=auto -U 5 old.conf new.conf
rm old.conf new.conf
rm default.conf old.conf new.conf
cd /
rmdir "$temp"
'';
@ -58,17 +86,6 @@ in
extraConfig = ''
country=NL
'';
# Public wireless networks
networks = lib.genAttrs [
"CDWiFi"
"EurostarTrainsWiFi"
"_SNCF gare-gratuit"
"_SNCF_WIFI_INOUI"
"Wifi in de trein"
"WiFi in de trein"
"_WIFI_LYRIA"
"WIFIonICE"
] (ssid: { });
userControlled.enable = true; # Allow some control with wpa_cli
};
};

View file

@ -59,7 +59,7 @@ for path in list_networks():
if any("EAP" in m.split("-") for m in data["key_mgmt"]):
data["password"] = password
if "ssid" in data:
if "ssid" not in data:
msg = f"{path}: Missing SSID"
raise KeyError(msg)
data.setdefault("disabled", 0)