nixos-config/nixos/modules/system/wifi.nix

88 lines
2.4 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;
2021-11-01 09:20:42 +01:00
in
{
2019-10-24 02:20:38 +02:00
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;
2020-12-16 22:47:38 +01:00
networking.networkmanager.extraConfig = ''
# The number of times a connection activation should be automatically tried
# before switching to another one. This value applies only to connections
# that can auto-connect and have a connection. autoconnect-retries property set to -1.
# If not specified, connections will be tried 4 times.
# Setting this value to 1 means to try activation once, without retry.
autoconnect-retries-default=999
'';
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.dhcpcd.allowInterfaces = cfg.interfaces;
2019-10-24 02:20:38 +02:00
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"
'')
];
})
];
}