nixos-config/modules/system/wifi.nix
Ingolf Wagner 54bab918d7
init
2019-10-24 02:24:33 +02:00

76 lines
1.8 KiB
Nix

{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.system.custom.wifi;
in {
options.system.custom.wifi = {
enable = mkEnableOption "enable wifi";
system = mkOption{
default = "wpa_supplicant";
type = with types; enum ["wpa_supplicant" "networkmanager"];
};
configurationFile = mkOption{
default = null;
type = with types; nullOr path;
description = ''
the target of /etc/wpa_supplicant.conf
'';
};
interfaces = mkOption {
type = with types; listOf string;
default = [];
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;
})
(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"
'')
];
})
];
}