1
0
mirror of https://github.com/kmein/niveum synced 2026-03-16 10:11:08 +01:00
Files
niveum/modules/networkmanager-declarative.nix

51 lines
1.3 KiB
Nix
Raw Permalink Normal View History

2021-09-22 07:55:49 +02:00
# https://github.com/jmackie/nixos-networkmanager-profiles/
{ lib, config, ... }:
with lib;
let
nm = config.networking.networkmanager;
mkProfile = profileAttrs:
if !(isAttrs profileAttrs) then
throw "error 1"
else {
enable = true;
mode = "0400"; # readonly (user)
text = (foldlAttrs (accum:
{ name, value }: ''
${accum}
[${name}] ${mkProfileEntry value}'')
"# Generated by nixos-networkmanager-profiles" profileAttrs) + "\n";
};
mkProfileEntry = entryAttrs:
if !(isAttrs entryAttrs) then
throw "error 2"
else
foldlAttrs (accum:
{ name, value }: ''
${accum}
${name}=${toString value}'') "" entryAttrs;
foldlAttrs = op: nul: attrs:
foldl (accum: { fst, snd }: op accum (nameValuePair fst snd)) nul
(lists.zipLists (attrNames attrs) (attrValues attrs));
attrLength = attrs: length (attrValues attrs);
in {
options.networking.networkmanager.profiles = mkOption {
type = types.attrs;
default = { };
};
config = mkIf (attrLength nm.profiles > 0) {
environment.etc = (foldlAttrs (accum:
{ name, value }:
accum // {
"NetworkManager/system-connections/${name}.nmconnection" =
mkProfile value;
}) { } nm.profiles);
};
}