diff options
| author | aristote <quentin.aristote@irif.fr> | 2025-07-29 15:25:11 +0200 |
|---|---|---|
| committer | aristote <quentin.aristote@irif.fr> | 2025-07-29 15:25:11 +0200 |
| commit | fc019d789523ce5f89436b8dbc458cf3b79abf43 (patch) | |
| tree | ec56fd1b1ed9fc75096c0b09db48a152975e4d53 /modules/nixos/personal/networking | |
| parent | a3d19bc509d9f39fb41256cd55d2bd7706de202f (diff) | |
reformat everything with nixfmt
Diffstat (limited to 'modules/nixos/personal/networking')
| -rw-r--r-- | modules/nixos/personal/networking/default.nix | 50 | ||||
| -rw-r--r-- | modules/nixos/personal/networking/wifi.nix | 101 |
2 files changed, 81 insertions, 70 deletions
diff --git a/modules/nixos/personal/networking/default.nix b/modules/nixos/personal/networking/default.nix index 3caddb1..cef72eb 100644 --- a/modules/nixos/personal/networking/default.nix +++ b/modules/nixos/personal/networking/default.nix @@ -4,16 +4,19 @@ pkgs, options, ... -}: let +}: +let cfg = config.personal.networking; - mkFirewallEnableOption = name: + mkFirewallEnableOption = + name: lib.mkOption { type = lib.types.bool; default = false; description = "Whether to open ports for ${name}."; }; -in { - imports = [./wifi.nix]; +in +{ + imports = [ ./wifi.nix ]; options.personal.networking = { enable = lib.mkEnableOption "networking"; @@ -28,19 +31,24 @@ in { }; config = lib.mkIf cfg.enable { - environment.systemPackages = - lib.optional cfg.networkmanager.enable pkgs.networkmanager; + environment.systemPackages = lib.optional cfg.networkmanager.enable pkgs.networkmanager; networking = { networkmanager = lib.mkIf cfg.networkmanager.enable { enable = true; - unmanaged = ["interface-name:ve-*"]; + unmanaged = [ "interface-name:ve-*" ]; }; firewall = { enable = true; allowedTCPPorts = lib.optional cfg.firewall.syncthing 22000 - ++ lib.optionals cfg.firewall.http [80 443]; - allowedUDPPorts = lib.optionals cfg.firewall.syncthing [22000 21027]; + ++ lib.optionals cfg.firewall.http [ + 80 + 443 + ]; + allowedUDPPorts = lib.optionals cfg.firewall.syncthing [ + 22000 + 21027 + ]; allowedTCPPortRanges = lib.optional cfg.firewall.kdeconnect { from = 1714; to = 1764; @@ -52,26 +60,26 @@ in { }; }; services = lib.mkIf cfg.ssh.enable { - openssh = - { - enable = true; - extraConfig = '' - AcceptEnv PS1 - ''; - } - // ( - if options.services.openssh ? settings - then { + openssh = { + enable = true; + extraConfig = '' + AcceptEnv PS1 + ''; + } + // ( + if options.services.openssh ? settings then + { settings = { PermitRootLogin = "no"; PasswordAuthentication = false; }; } - else { + else + { permitRootLogin = "no"; passwordAuthentication = false; } - ); + ); fail2ban = { enable = true; maxretry = 16; diff --git a/modules/nixos/personal/networking/wifi.nix b/modules/nixos/personal/networking/wifi.nix index d7415a8..2e23349 100644 --- a/modules/nixos/personal/networking/wifi.nix +++ b/modules/nixos/personal/networking/wifi.nix @@ -2,39 +2,42 @@ config, lib, ... -}: let +}: +let cfg = config.personal.networking.wifi; - mkWifiProfile = { - id, - ssid, - }: { - "${id}" = { - connection = { - id = "${id}"; - type = "wifi"; - }; - wifi = { - inherit ssid; - mode = "infrastructure"; - }; - wifi-security = { - key-mgmt = "wpa-psk"; - # fill-in password on first connection - # this will create a new connection - # disable the personal.networking.wifi.enable option - # to keep it for next rebuild - }; - ipv4 = { - method = "auto"; - }; - ipv6 = { - addr-gen-mode = "stable-privacy"; - method = "auto"; - }; - proxy = { + mkWifiProfile = + { + id, + ssid, + }: + { + "${id}" = { + connection = { + id = "${id}"; + type = "wifi"; + }; + wifi = { + inherit ssid; + mode = "infrastructure"; + }; + wifi-security = { + key-mgmt = "wpa-psk"; + # fill-in password on first connection + # this will create a new connection + # disable the personal.networking.wifi.enable option + # to keep it for next rebuild + }; + ipv4 = { + method = "auto"; + }; + ipv6 = { + addr-gen-mode = "stable-privacy"; + method = "auto"; + }; + proxy = { + }; }; }; - }; knownSSIDs = { home = "Quentintranet"; home-iot = "Quentinternet of Things"; @@ -46,16 +49,20 @@ montlaur = "Nordnet_E080"; montlaur-5g = "Nordnet_E080_5G"; }; -in { +in +{ options.personal.networking.wifi = { enable = lib.mkEnableOption "personal WiFi networks"; networks = lib.mkOption { type = with lib.types; listOf str; - default = ["home-private" "hotspot"]; + default = [ + "home-private" + "hotspot" + ]; }; extraNetworks = lib.mkOption { type = with lib.types; listOf (attrsOf str); - default = []; + default = [ ]; example = [ { id = "my-wifi"; @@ -65,20 +72,16 @@ in { }; }; - config.networking.networkmanager.ensureProfiles.profiles = let - networks = - builtins.map (id: { - inherit id; - ssid = - if lib.hasAttr id knownSSIDs - then lib.getAttr id knownSSIDs - else throw "Unknown WiFi ID: ${id}"; - }) - cfg.networks - ++ cfg.extraNetworks; - profiles = lib.mergeAttrsList (builtins.map mkWifiProfile networks); - in - lib.mkIf - cfg.enable - profiles; + config.networking.networkmanager.ensureProfiles.profiles = + let + networks = + builtins.map (id: { + inherit id; + ssid = + if lib.hasAttr id knownSSIDs then lib.getAttr id knownSSIDs else throw "Unknown WiFi ID: ${id}"; + }) cfg.networks + ++ cfg.extraNetworks; + profiles = lib.mergeAttrsList (builtins.map mkWifiProfile networks); + in + lib.mkIf cfg.enable profiles; } |
