networks: implement bssid support

This commit is contained in:
Primrose 2025-12-07 16:01:51 +08:00
parent b66c63601f
commit 076a4448e7
Signed by: primrose
GPG key ID: 4E887A4CA9714ADA
3 changed files with 23 additions and 18 deletions

View file

@ -6,6 +6,7 @@ in
[
{
ssid = "~";
bssid = "de:ad:de:ad:d0:d0"; # dead dead dodo
priority = preferredPriority;
hasPassword = true;
}

View file

@ -13,31 +13,35 @@ let
go =
networkArgs@{
ssid,
bssid ? null,
# Custom fields wrapping nixpkgs module options
hasPassword ? false,
scanOnLowSignal ? false,
randomizeMac ? false,
...
}:
let
uniqueKey = "${ssid}${lib.optionalString (bssid != null) bssid}";
in
{
${ssid} = lib.mkMerge [
(builtins.removeAttrs networkArgs [
# We keep ssid, because it overrides the attrset name ssid
# "ssid"
"hasPassword"
"scanOnLowSignal"
"randomizeMac"
])
(lib.optionalAttrs hasPassword {
pskRaw = "ext:${escapePwdKey ssid}";
})
{
extraConfig = ''
${lib.optionalString scanOnLowSignal "bgscan=\"simple:30:-70:3600\""}
${lib.optionalString randomizeMac "mac_addr=1"}
'';
}
];
${uniqueKey} # we use a unique key here to make sure no "same ssid different bssid" networks collide in key.
=
lib.mkMerge [
(builtins.removeAttrs networkArgs [
"hasPassword"
"scanOnLowSignal"
"randomizeMac"
])
(lib.optionalAttrs hasPassword {
pskRaw = "ext:${escapePwdKey uniqueKey}"; # this implies changing the external password key if you set a bssid!
})
{
extraConfig = ''
${lib.optionalString scanOnLowSignal "bgscan=\"simple:30:-70:3600\""}
${lib.optionalString randomizeMac "mac_addr=1"}
'';
}
];
};
in
ns: lib.mkMerge (map go ns)

Binary file not shown.