{
  lib,
  config,
  pkgs,
  ...
}:
with lib;
with lib.custom; let
  cfg = config.services.vpn;
in {
  options.services.vpn = with types; {
    enable = mkBoolOpt false "Enable VPN service(s)";

    enableMullvad = mkBoolOpt false "Enable Mullvad VPN Daemon";
  };

  config = mkIf cfg.enable {
    services.mullvad-vpn.enable = cfg.enableMullvad;
    services.openvpn.servers = {
      work = {
        config = ''config /home/zack/Downloads/zachary_myers.ovpn'';
        updateResolvConf = true;
      };
    };

    systemd.services."mullvad-daemon".postStart = let
      mullvad = config.services.mullvad-vpn.package;
    in
      mkIf cfg.enableMullvad ''
        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
      '';
  };
}
