summary refs log tree commit diff
path: root/nixos/modules/services/networking/openvpn.nix
diff options
context:
space:
mode:
authorBenno Fünfstück <benno.fuenfstueck@gmail.com>2016-06-06 19:17:27 +0200
committerBenno Fünfstück <benno.fuenfstueck@gmail.com>2016-06-06 20:43:52 +0200
commitc85f2b20e677e72fd3334f48b0cb0123dbaee16d (patch)
tree5027d360b702d1feca34979d75b9020c40140e9d /nixos/modules/services/networking/openvpn.nix
parent32cbc5b794ed2f098e2c76405b7d6211029bbd10 (diff)
downloadnixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar.gz
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar.bz2
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar.lz
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar.xz
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.tar.zst
nixpkgs-c85f2b20e677e72fd3334f48b0cb0123dbaee16d.zip
nixos/openvpn: add support for resolvconf
The update-resolve-conf script from the update-resolv-conf
package is very useful and should work in most of the common
cases, so this adds an option to enable it. The option is
disabled by default for backwards compatibility.
Diffstat (limited to 'nixos/modules/services/networking/openvpn.nix')
-rw-r--r--nixos/modules/services/networking/openvpn.nix22
1 files changed, 19 insertions, 3 deletions
diff --git a/nixos/modules/services/networking/openvpn.nix b/nixos/modules/services/networking/openvpn.nix
index a96888dec86..82173a841a3 100644
--- a/nixos/modules/services/networking/openvpn.nix
+++ b/nixos/modules/services/networking/openvpn.nix
@@ -29,21 +29,27 @@ let
         done
 
         ${cfg.up}
+        ${optionalString cfg.updateResolvConf
+           "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"}
       '';
 
       downScript = ''
         #! /bin/sh
         export PATH=${path}
+        ${optionalString cfg.updateResolvConf
+           "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"}
         ${cfg.down}
       '';
 
       configFile = pkgs.writeText "openvpn-config-${name}"
         ''
           errors-to-stderr
-          ${optionalString (cfg.up != "" || cfg.down != "") "script-security 2"}
+          ${optionalString (cfg.up != "" || cfg.down != "" || cfg.updateResolvConf) "script-security 2"}
           ${cfg.config}
-          ${optionalString (cfg.up != "") "up ${pkgs.writeScript "openvpn-${name}-up" upScript}"}
-          ${optionalString (cfg.down != "") "down ${pkgs.writeScript "openvpn-${name}-down" downScript}"}
+          ${optionalString (cfg.up != "" || cfg.updateResolvConf)
+              "up ${pkgs.writeScript "openvpn-${name}-up" upScript}"}
+          ${optionalString (cfg.down != "" || cfg.updateResolvConf)
+              "down ${pkgs.writeScript "openvpn-${name}-down" downScript}"}
         '';
 
     in {
@@ -145,6 +151,16 @@ in
           description = "Whether this OpenVPN instance should be started automatically.";
         };
 
+        updateResolvConf = mkOption {
+          default = false;
+          type = types.bool;
+          description = ''
+            Use the script from the update-resolv-conf package to automatically
+            update resolv.conf with the DNS information provided by openvpn. The
+            script will be run after the "up" commands and before the "down" commands.
+          '';
+        };
+
       };
 
     };