declarative-nm: remove with lib;

This commit is contained in:
Simon Gardling 2025-06-24 20:38:23 -07:00
parent 836159960c
commit 3b0d577f3b
Signed by: titaniumtown
GPG Key ID: 9AB28AC10ECE533D

View File

@ -4,12 +4,11 @@
pkgs,
...
}:
with lib;
# from: https://discourse.nixos.org/t/imperative-declarative-wifi-networks-with-wpa-supplicant/12394/6
let
cfg = config.networking.networkmanager;
getFileName = stringAsChars (x: if x == " " then "-" else x);
getFileName = lib.stringAsChars (x: if x == " " then "-" else x);
createWifi = ssid: opt: {
name = "NetworkManager/system-connections/${getFileName ssid}.nmconnection";
@ -24,21 +23,21 @@ let
ssid=${ssid}
[wifi-security]
${optionalString (opt.psk != null) ''
${lib.optionalString (opt.psk != null) ''
key-mgmt=wpa-psk
psk=${opt.psk}''}
'';
};
};
keyFiles = mapAttrs' createWifi config.networking.wireless.networks;
keyFiles = lib.mapAttrs' createWifi config.networking.wireless.networks;
in
{
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {
environment.etc = keyFiles;
systemd.services.NetworkManager-predefined-connections = {
restartTriggers = mapAttrsToList (name: value: value.source) keyFiles;
restartTriggers = lib.mapAttrsToList (name: value: value.source) keyFiles;
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;