sneeuwvlok/modules/nixos/services/networking/wireguard/default.nix
Chris Kruining 5b844aab8d
.
2026-03-23 09:38:23 +01:00

47 lines
1.1 KiB
Nix

{
config,
pkgs,
lib,
namespace,
...
}: let
inherit (builtins) length;
inherit (lib) mkIf mkEnableOption mkOption types attrNames attrsToList listToAttrs;
cfg = config.${namespace}.services.networking.wireguard;
hasPeers = (cfg.peer |> attrNames |> length) > 0;
in {
options.${namespace}.services.networking.wireguard = {
# enable = mkEnableOption "enable wireguard" // {default = true;};
peer = mkOption {
type = types.attrsOf (types.submodule {
options = {
port = mkOption {
type = types.port;
description = '''';
};
address = mkOption {
type = types.listOf types.str;
default = [];
description = '''';
};
};
});
};
};
config = mkIf hasPeers {
networking.firewall.allowedUDPPorts = cfg.peer |> lib.attrValues |> lib.map (p: p.port);
networking.wq-quick = {
# enable = cfg.enable;
interfaces =
cfg.peer
|> attrsToList
|> imap0 (i: { name, value }: (namevaluepair "wg${i}" (value // { }));
|> listToAttrs
};
};
}