From 827215d700486a68e6d7f57dc1fae1f629b12509 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Thu, 1 Jun 2023 11:38:39 +0200 Subject: [PATCH] move wifi to components --- nixos/components/network/default.nix | 14 ++++++- nixos/components/network/wifi.nix | 51 ++++++++++++++++++++++++ nixos/machines/chungus/configuration.nix | 2 + nixos/machines/cream/configuration.nix | 3 +- nixos/machines/robi/configuration.nix | 2 + nixos/modules/default.nix | 1 - nixos/modules/system/permown.nix | 3 -- nixos/system/all/shell.nix | 2 - nixos/system/desktop/default.nix | 1 - nixos/system/desktop/network.nix | 6 --- 10 files changed, 70 insertions(+), 15 deletions(-) create mode 100644 nixos/components/network/wifi.nix delete mode 100644 nixos/modules/system/permown.nix delete mode 100644 nixos/system/all/shell.nix delete mode 100644 nixos/system/desktop/network.nix diff --git a/nixos/components/network/default.nix b/nixos/components/network/default.nix index 4664c23..2b02aba 100644 --- a/nixos/components/network/default.nix +++ b/nixos/components/network/default.nix @@ -1,8 +1,20 @@ -{ ... }: +{ pkgs, lib, ... }: +with lib; +with types; { + options.components.network = { + enable = mkOption { + type = bool; + default = true; + }; + }; + imports = [ ./sshd ./tinc ./hosts.nix + ./wifi.nix ]; + + config = mkIf config.components.network.enable { }; } diff --git a/nixos/components/network/wifi.nix b/nixos/components/network/wifi.nix new file mode 100644 index 0000000..1eee22d --- /dev/null +++ b/nixos/components/network/wifi.nix @@ -0,0 +1,51 @@ +{ config, lib, pkgs, ... }: +with lib; +with types; +{ + + options.components.network.wifi.enable = mkOption { + type = bool; + default = config.components.network.enable; + }; + + config = mkIf config.components.network.wifi.enable { + + networking.usePredictableInterfaceNames = true; + + networking.networkmanager.enable = true; + networking.networkmanager.wifi.powersave = lib.mkDefault true; + 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 + ''; + + + hardware.enableRedistributableFirmware = true; + + # because Networkd-wait-online is just failing. + systemd.services.systemd-networkd-wait-online.enable = false; + systemd.services.NetworkManager-wait-online.enable = false; + + 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" + '') + + ]; + }; + +} + diff --git a/nixos/machines/chungus/configuration.nix b/nixos/machines/chungus/configuration.nix index 62752e5..20bc3bb 100644 --- a/nixos/machines/chungus/configuration.nix +++ b/nixos/machines/chungus/configuration.nix @@ -45,6 +45,8 @@ ]; + components.network.enable = true; + components.network.wifi.enable = false; boot.loader.systemd-boot.enable = true; boot.loader.efi.canTouchEfiVariables = true; diff --git a/nixos/machines/cream/configuration.nix b/nixos/machines/cream/configuration.nix index c356d8a..20ed355 100644 --- a/nixos/machines/cream/configuration.nix +++ b/nixos/machines/cream/configuration.nix @@ -30,12 +30,13 @@ components.gui.enable = true; components.terminal.enable = true; + components.network.enable = true; + components.network.wifi.enable = true; services.nginx.enable = true; networking.hostName = "cream"; - system.custom.wifi.interfaces = [ "wlp166s0" ]; services.flatpak.enable = true; diff --git a/nixos/machines/robi/configuration.nix b/nixos/machines/robi/configuration.nix index a74cb05..0fc3043 100644 --- a/nixos/machines/robi/configuration.nix +++ b/nixos/machines/robi/configuration.nix @@ -59,6 +59,8 @@ ./sync-torrent.nix ]; + components.network.enable = true; + components.network.wifi.enable = false; system.custom.mainUser.enable = true; system.custom.mainUser.userName = "palo"; diff --git a/nixos/modules/default.nix b/nixos/modules/default.nix index 01ba222..713a7e3 100644 --- a/nixos/modules/default.nix +++ b/nixos/modules/default.nix @@ -36,7 +36,6 @@ ./system/bluetooth.nix ./system/font.nix ./system/mainUser.nix - ./system/wifi.nix ./system/on-failure.nix ]; diff --git a/nixos/modules/system/permown.nix b/nixos/modules/system/permown.nix deleted file mode 100644 index 88d8a3b..0000000 --- a/nixos/modules/system/permown.nix +++ /dev/null @@ -1,3 +0,0 @@ -{ config, lib, pkgs, ... }: - -{ } diff --git a/nixos/system/all/shell.nix b/nixos/system/all/shell.nix deleted file mode 100644 index b70ab71..0000000 --- a/nixos/system/all/shell.nix +++ /dev/null @@ -1,2 +0,0 @@ -{ config, lib, ... }: -{ } diff --git a/nixos/system/desktop/default.nix b/nixos/system/desktop/default.nix index 3ae8791..ee824b1 100644 --- a/nixos/system/desktop/default.nix +++ b/nixos/system/desktop/default.nix @@ -8,7 +8,6 @@ ./audio.nix ./cachix.nix ./mail-stuff.nix - ./network.nix ./packages.nix ./size.nix ./user.nix diff --git a/nixos/system/desktop/network.nix b/nixos/system/desktop/network.nix deleted file mode 100644 index 6d99911..0000000 --- a/nixos/system/desktop/network.nix +++ /dev/null @@ -1,6 +0,0 @@ -{ config, pkgs, lib, ... }: { - system.custom.wifi = { - enable = true; - system = "networkmanager"; - }; -}