nixos-config/modules/system/wifi.nix

77 lines
1.8 KiB
Nix
Raw Normal View History

2019-10-24 02:20:38 +02:00
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system.custom.wifi;
in {
options.system.custom.wifi = {
enable = mkEnableOption "enable wifi";
2019-12-20 05:54:26 +01:00
system = mkOption {
2019-10-24 02:20:38 +02:00
default = "wpa_supplicant";
2019-12-20 05:54:26 +01:00
type = with types; enum [ "wpa_supplicant" "networkmanager" ];
2019-10-24 02:20:38 +02:00
};
2019-12-20 05:54:26 +01:00
configurationFile = mkOption {
2019-10-24 02:20:38 +02:00
default = null;
type = with types; nullOr path;
description = ''
the target of /etc/wpa_supplicant.conf
'';
};
interfaces = mkOption {
2019-12-20 05:54:26 +01:00
type = with types; listOf string;
default = [ ];
2019-10-24 02:20:38 +02:00
description = ''
list of interfaces to take care of,
if empty it will test all interfaces
'';
};
};
config = mkMerge [
(mkIf (cfg.system == "wpa_supplicant") {
networking.wireless.enable = true;
networking.wireless.interfaces = cfg.interfaces;
})
(mkIf (cfg.system == "networkmanager") {
networking.networkmanager.enable = true;
2020-01-29 03:00:12 +01:00
networking.networkmanager.wifi.powersave = true;
2019-10-24 02:20:38 +02:00
})
(mkIf (cfg.configurationFile != null) {
environment.etc."wpa_supplicant.conf".source = cfg.configurationFile;
})
(mkIf cfg.enable {
networking.usePredictableInterfaceNames = true;
hardware.enableRedistributableFirmware = true;
environment.systemPackages = [
(pkgs.writeShellScriptBin "scan-wifi" ''
# todo : use column to make a nice view
${pkgs.wirelesstools}/bin/iwlist scan | \
grep -v "Interface doesn't support scanning" | \
sed -e '/^\s*$/d' | \
grep -e "ESSID" -e "Encrypt" | \
sed -e "s/Encryption key:on/encrypted/g" | \
sed -e "s/Encryption key:off/open/g" | \
sed -e "s/ESSID://g" | \
xargs -L 2 printf "%9s - '%s'\n"
'')
];
})
];
}