summaryrefslogtreecommitdiff
path: root/modules/root/wifi.nix
blob: ff143b98bce0f555cae391b2a56d08665823737f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
{ 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 9;  # 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;
		};
	};
}