diff options
author | gbtb <goodbetterthebeast3@gmail.com> | 2022-12-03 20:24:19 +1000 |
---|---|---|
committer | gbtb <goodbetterthebeast3@gmail.com> | 2022-12-12 23:37:57 +1000 |
commit | 3d17d6fff637cfadd6adb10adaf58bd8451fb90e (patch) | |
tree | 2617db5d142d87ef2b4b7e2ac63fcc83062d5ff2 /nixos/modules/services/networking/openvpn.nix | |
parent | 95f1ec721652d91a2993311d6cf537d3724690be (diff) | |
download | nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar.gz nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar.bz2 nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar.lz nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar.xz nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.tar.zst nixpkgs-3d17d6fff637cfadd6adb10adaf58bd8451fb90e.zip |
nixos/openvpn: added restartAfterSleep option
Additional systemd unit that hooks to sleep.target and kills openvpn processes
Diffstat (limited to 'nixos/modules/services/networking/openvpn.nix')
-rw-r--r-- | nixos/modules/services/networking/openvpn.nix | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/nixos/modules/services/networking/openvpn.nix b/nixos/modules/services/networking/openvpn.nix index 492a0936fdb..3a255b9172c 100644 --- a/nixos/modules/services/networking/openvpn.nix +++ b/nixos/modules/services/networking/openvpn.nix @@ -70,6 +70,16 @@ let serviceConfig.Type = "notify"; }; + restartService = optionalAttrs cfg.restartAfterSleep { + openvpn-restart = { + wantedBy = [ "sleep.target" ]; + path = [ pkgs.procps ]; + script = "pkill --signal SIGHUP --exact openvpn"; + #SIGHUP makes openvpn process to self-exit and then it got restarted by systemd because of Restart=always + description = "Sends a signal to OpenVPN process to trigger a restart after return from sleep"; + }; + }; + in { @@ -201,6 +211,12 @@ in }; + services.openvpn.restartAfterSleep = mkOption { + default = true; + type = types.bool; + description = lib.mdDoc "Whether OpenVPN clients should be restarted after sleep."; + }; + }; @@ -208,7 +224,8 @@ in config = mkIf (cfg.servers != {}) { - systemd.services = listToAttrs (mapAttrsFlatten (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers); + systemd.services = (listToAttrs (mapAttrsFlatten (name: value: nameValuePair "openvpn-${name}" (makeOpenVPNJob value name)) cfg.servers)) + // restartService; environment.systemPackages = [ openvpn ]; |