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