mirror of
https://codeberg.org/leana8959/.files.git
synced 2026-02-01 22:49:41 +00:00
51 lines
1.7 KiB
Nix
51 lines
1.7 KiB
Nix
#
|
|
# This loads the list of networks as a NixOS wpa_supplicant compatible attrset
|
|
#
|
|
# View the example config
|
|
# less $(nix-build --no-out-link '<nixpkgs>' -A 'wpa_supplicant')/share/doc/wpa_supplicant/wpa_supplicant.conf.example
|
|
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,
|
|
bssid ? null,
|
|
# Custom fields wrapping nixpkgs module options
|
|
hasPassword ? false,
|
|
scanOnLowSignal ? false,
|
|
randomizeMac ? false,
|
|
...
|
|
}:
|
|
{
|
|
${
|
|
# We use a unique key here to make sure no "same ssid different bssid" networks collide in key.
|
|
# This is ordered, we still show "null" so that it would come after hex characters [a-z0-9].
|
|
# The serialization is based on string order.
|
|
"${ssid},${if bssid != null then bssid else "null"}"
|
|
} =
|
|
lib.mkMerge [
|
|
(builtins.removeAttrs networkArgs [
|
|
"hasPassword"
|
|
"scanOnLowSignal"
|
|
"randomizeMac"
|
|
])
|
|
(lib.optionalAttrs hasPassword {
|
|
pskRaw = "ext:${
|
|
# this implies changing the external password key if you set a bssid!
|
|
escapePwdKey (if bssid == null then ssid else "${ssid},${bssid}")
|
|
}";
|
|
})
|
|
{
|
|
extraConfig = ''
|
|
${lib.optionalString scanOnLowSignal "bgscan=\"simple:30:-70:3600\""}
|
|
${lib.optionalString randomizeMac "mac_addr=1"}
|
|
'';
|
|
}
|
|
];
|
|
};
|
|
in
|
|
ns: lib.mkMerge (map go ns)
|