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 [
|
|
|
|
|
2020-03-11 08:37:54 +01:00
|
|
|
(mkIf (cfg.enable && cfg.system == "wpa_supplicant") {
|
2019-10-24 02:20:38 +02:00
|
|
|
networking.wireless.enable = true;
|
|
|
|
networking.wireless.interfaces = cfg.interfaces;
|
|
|
|
})
|
|
|
|
|
2020-03-11 08:37:54 +01:00
|
|
|
(mkIf (cfg.enable && cfg.system == "networkmanager") {
|
2019-10-24 02:20:38 +02:00
|
|
|
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
|
|
|
})
|
|
|
|
|
2020-03-11 08:37:54 +01:00
|
|
|
(mkIf (cfg.enable && cfg.configurationFile != null) {
|
2019-10-24 02:20:38 +02:00
|
|
|
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"
|
|
|
|
'')
|
|
|
|
|
|
|
|
];
|
|
|
|
})
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
}
|
|
|
|
|