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.

+19 -3
+19 -3
nixos/modules/services/networking/openvpn.nix
··· 29 done 30 31 ${cfg.up} 32 ''; 33 34 downScript = '' 35 #! /bin/sh 36 export PATH=${path} 37 ${cfg.down} 38 ''; 39 40 configFile = pkgs.writeText "openvpn-config-${name}" 41 '' 42 errors-to-stderr 43 - ${optionalString (cfg.up != "" || cfg.down != "") "script-security 2"} 44 ${cfg.config} 45 - ${optionalString (cfg.up != "") "up ${pkgs.writeScript "openvpn-${name}-up" upScript}"} 46 - ${optionalString (cfg.down != "") "down ${pkgs.writeScript "openvpn-${name}-down" downScript}"} 47 ''; 48 49 in { ··· 143 default = true; 144 type = types.bool; 145 description = "Whether this OpenVPN instance should be started automatically."; 146 }; 147 148 };
··· 29 done 30 31 ${cfg.up} 32 + ${optionalString cfg.updateResolvConf 33 + "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"} 34 ''; 35 36 downScript = '' 37 #! /bin/sh 38 export PATH=${path} 39 + ${optionalString cfg.updateResolvConf 40 + "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"} 41 ${cfg.down} 42 ''; 43 44 configFile = pkgs.writeText "openvpn-config-${name}" 45 '' 46 errors-to-stderr 47 + ${optionalString (cfg.up != "" || cfg.down != "" || cfg.updateResolvConf) "script-security 2"} 48 ${cfg.config} 49 + ${optionalString (cfg.up != "" || cfg.updateResolvConf) 50 + "up ${pkgs.writeScript "openvpn-${name}-up" upScript}"} 51 + ${optionalString (cfg.down != "" || cfg.updateResolvConf) 52 + "down ${pkgs.writeScript "openvpn-${name}-down" downScript}"} 53 ''; 54 55 in { ··· 149 default = true; 150 type = types.bool; 151 description = "Whether this OpenVPN instance should be started automatically."; 152 + }; 153 + 154 + updateResolvConf = mkOption { 155 + default = false; 156 + type = types.bool; 157 + description = '' 158 + Use the script from the update-resolv-conf package to automatically 159 + update resolv.conf with the DNS information provided by openvpn. The 160 + script will be run after the "up" commands and before the "down" commands. 161 + ''; 162 }; 163 164 };