{ pkgs, lib, config, ... }: let mkNetworksFromEnvironmentFile = n: builtins.listToAttrs ( map (i: { name = "@SSID_${toString i}@"; value = { psk = "@PSK_${toString i}@"; priority = n - i; }; }) (lib.lists.range 1 n) ); environmentFile = config.sops.secrets.wireless-env.path; #networks = mkNetworksFromEnvironmentFile ((builtins.length (lib.strings.splitString "\n" (builtins.readFile environmentFile))) / 2); networks = mkNetworksFromEnvironmentFile 10; # Number of networks listed in wireless-env in { options = { wifi.enable = lib.mkEnableOption "enables wifi"; }; config = lib.mkIf config.wifi.enable { networking.wireless = { enable = true; # Enables wireless support via wpa_supplicant. userControlled.enable = true; inherit networks; inherit environmentFile; }; }; }