# # This loads the list of networks as a NixOS wpa_supplicant compatible attrset # # View the example config # less $(nix-build --no-out-link -E '(import {}).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, # Custom fields wrapping nixpkgs module options hasPassword ? false, scanOnLowSignal ? false, randomizeMac ? false, ... }: { ${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"} ''; } ]; }; in ns: lib.mkMerge (map go ns)