diff --git a/lib/default.nix b/lib/default.nix index 400dc18..b3febf7 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -4,5 +4,6 @@ nixpkgs.lib.extend (final: prev: { importLib = file: import file {lib = final;}; in { patches = importLib ./patches.nix; + networkManager = importLib ./networkManager.nix; }; }) diff --git a/lib/networkManager.nix b/lib/networkManager.nix new file mode 100644 index 0000000..183501b --- /dev/null +++ b/lib/networkManager.nix @@ -0,0 +1,18 @@ +{lib}: { + /** + Make a NetworkManager wifi profile, to be used with ensureProfiles + */ + mkWifiProfile = {id, ssid, priority ? 0, wifi-security}: { + connection = { + inherit id; + type = "wifi"; + autoconnect-priority = priority; + }; + ipv4.method = "auto"; + wifi = { + mode = "infrastructure"; + inherit ssid; + }; + inherit wifi-security; + }; +} diff --git a/roles/desktop/services/networkmanager.nix b/roles/desktop/services/networkmanager.nix index 2be85d7..8ba9457 100644 --- a/roles/desktop/services/networkmanager.nix +++ b/roles/desktop/services/networkmanager.nix @@ -1,5 +1,6 @@ { config, + lib, flakeSelf, ... }: let @@ -16,35 +17,21 @@ in { ]; ensureProfiles = { environmentFiles = [config.sops.secrets.wifiPasswords.path]; - profiles = { - "4g-modem" = { - connection = { - id = "4G Modem"; - type = "wifi"; - autoconnect-priority = 5; - }; - ipv4.method = "auto"; - wifi = { - mode = "infrastructure"; - ssid = "TP-Link_CCB4"; - }; + profiles = with lib.toast.networkManager; { + "4g-modem" = mkWifiProfile { + id = "4G Modem"; + priority = 5; + ssid = "TP-Link_CCB4"; wifi-security = { auth-alg = "open"; key-mgmt = "wpa-psk"; psk = "$MODEM"; }; }; - phone = { - connection = { - id = "Phone"; - type = "wifi"; - autoconnect-priority = 5; - }; - ipv4.method = "auto"; - wifi = { - mode = "infrastructure"; - ssid = "Redmi Note 10 Pro_5197"; - }; + phone = mkWifiProfile { + id = "Phone"; + priority = 5; + ssid = "Redmi Note 10 Pro_5197"; wifi-security = { auth-alg = "open"; key-mgmt = "sae";