15 cfg = config.services.wg-access-server;
17 settingsFormat = pkgs.formats.yaml { };
18 configFile = settingsFormat.generate "config.yaml" cfg.settings;
22 options.services.wg-access-server = {
23 enable = mkEnableOption "wg-access-server";
25 package = mkPackageOption pkgs "wg-access-server" { };
28 type = lib.types.submodule {
29 freeformType = settingsFormat.type;
31 dns.enabled = mkOption {
35 Enable/disable the embedded DNS proxy server.
36 This is enabled by default and allows VPN clients to avoid DNS leaks by sending all DNS requests to wg-access-server itself.
41 default = "sqlite3://db.sqlite";
42 description = "A storage backend connection string. See [storage docs](https://www.freie-netze.org/wg-access-server/3-storage/)";
46 description = "See https://www.freie-netze.org/wg-access-server/2-configuration/ for possible options";
49 secretsFile = mkOption {
52 yaml file containing all secrets. this needs to be in the same structure as the configuration.
54 This must to contain the admin password and wireguard private key.
55 As well as the secrets for your auth backend.
59 adminPassword: <admin password>
61 privateKey: <wireguard private key>
64 clientSecret: <client secret>
70 config = lib.mkIf cfg.enable {
74 assertion = !lib.hasAttrByPath attrPath config.services.wg-access-server.settings;
76 {option}`services.wg-access-server.settings.${lib.concatStringsSep "." attrPath}` must definded
77 in {option}`services.wg-access-server.secretsFile`.
102 boot.kernel.sysctl = {
103 "net.ipv4.conf.all.forwarding" = "1";
104 "net.ipv6.conf.all.forwarding" = "1";
107 systemd.services.wg-access-server = {
108 description = "WG access server";
109 wantedBy = [ "multi-user.target" ];
110 requires = [ "network-online.target" ];
111 after = [ "network-online.target" ];
113 # merge secrets into main config
114 yq eval-all "select(fileIndex == 0) * select(fileIndex == 1)" ${configFile} $CREDENTIALS_DIRECTORY/SECRETS_FILE \
115 > "$STATE_DIRECTORY/config.yml"
117 ${lib.getExe cfg.package} serve --config "$STATE_DIRECTORY/config.yml"
122 # needed by startup script
130 ] ++ lib.optional cfg.settings.dns.enabled "CAP_NET_BIND_SERVICE";
133 WorkingDirectory = "/var/lib/wg-access-server";
134 StateDirectory = "wg-access-server";
137 "SECRETS_FILE:${cfg.secretsFile}"
142 AmbientCapabilities = capabilities;
143 CapabilityBoundingSet = capabilities;