Skip to content

Commit

Permalink
feat(nix): add NixOS module
Browse files Browse the repository at this point in the history
for configuring OpenVPN servers and clients with
`update-systemd-resolved` settings.
  • Loading branch information
tomeon committed Sep 17, 2023
1 parent c5482eb commit 2662959
Show file tree
Hide file tree
Showing 3 changed files with 430 additions and 17 deletions.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
inputs.flake-parts.flakeModules.easyOverlay
./nix/checks.nix
./nix/devshells.nix
./nix/nixos-modules.nix
./nix/packages.nix
];
});
Expand Down
45 changes: 28 additions & 17 deletions nix/checks.nix
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@
};
polkitRules = mkPolkitRulesForService config.systemd.services.${serviceAttrName};
in {
imports = [
self.nixosModules.update-systemd-resolved
];

networking.useNetworkd = true;

services.resolved = {
Expand Down Expand Up @@ -258,6 +262,30 @@
dnsutils # for "dig"
];

programs.update-systemd-resolved.servers.${instanceName} = {
includeAutomatically = true;

settings = {
dns.resolver = {name, ...}: {
address = resolverIP;
port = resolverPort;
sni = name;
};

domain = vpnDomain;

defaultRoute = true;
dnsOverTLS = "yes";
dnssec = true;
dnssecNegativeTrustAnchors = [vpnDomain];
flushCaches = "yes";
llmnr = "resolve";
multicastDNS = "default";
resetServerFeatures = true;
resetStatistics = "yes";
};
};

services.openvpn.servers.${instanceName} = {
config = ''
remote server
Expand All @@ -267,23 +295,6 @@
ifconfig ${clientEndpoint} ${serverEndpoint}
providers legacy default
config ${perSystem.config.packages.update-systemd-resolved}/share/doc/openvpn/update-systemd-resolved.conf
dhcp-option DNS ${resolverIP}:${toString resolverPort}#resolver
dhcp-option DOMAIN ${vpnDomain}
dhcp-option FLUSH-CACHES yes
dhcp-option RESET-SERVER-FEATURES true
dhcp-option RESET-STATISTICS yes
dhcp-option DEFAULT-ROUTE yes
dhcp-option DNS-OVER-TLS yes
dhcp-option LLMNR resolve
dhcp-option MULTICAST-DNS default
dhcp-option DNSSEC true
dhcp-option DNSSEC-NEGATIVE-TRUST-ANCHORS ${vpnDomain}
'';
};

Expand Down
Loading

0 comments on commit 2662959

Please sign in to comment.