config/modules/nixos/services/vpn/default.nix

42 lines
994 B
Nix
Raw Normal View History

2024-05-23 20:26:30 +00:00
{
lib,
config,
pkgs,
...
}:
with lib;
with lib.custom; let
cfg = config.services.vpn;
in {
options.services.vpn = with types; {
2024-05-23 21:24:09 +00:00
enable = mkBoolOpt false "Enable VPN service(s)";
2024-05-27 03:11:41 -04:00
mullvad = mkBoolOpt false "Enable Mullvad VPN Daemon";
2024-05-23 20:26:30 +00:00
};
config = mkIf cfg.enable {
2024-05-27 03:11:41 -04:00
services.mullvad-vpn.enable = cfg.mullvad;
services.openvpn = {
servers = {
work = {
config = ''config /home/zoey/Downloads/zachary_myers.ovpn'';
updateResolvConf = true;
2024-09-12 10:58:53 -04:00
extraArgs = [''''];
};
2024-05-23 20:26:30 +00:00
};
};
systemd.services.openvpn-work.wantedBy = lib.mkForce [];
2024-05-23 21:24:09 +00:00
systemd.services."mullvad-daemon".postStart = let
mullvad = config.services.mullvad-vpn.package;
in
2024-05-27 03:11:41 -04:00
mkIf cfg.mullvad ''
2024-05-23 21:24:09 +00:00
while ! ${mullvad}/bin/mullvad status >/dev/null; do sleep 1; done
${mullvad}/bin/mullvad auto-connect set on
${mullvad}/bin/mullvad tunnel set ipv6 on
${mullvad}/bin/mullvad connect
'';
2024-05-23 20:26:30 +00:00
};
}