openvpn service: source up/down scripts

source the up/down scripts instead of executing them to avoid loosing
access to special variables like $1
This commit is contained in:
Tristan Helmich
2017-04-25 13:18:54 -04:00
committed by Graham Christensen
parent b6714f524b
commit 50ad243f78
+13 -3
View File
@@ -28,9 +28,10 @@ let
fi fi
done done
${cfg.up}
${optionalString cfg.updateResolvConf ${optionalString cfg.updateResolvConf
"${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"} "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"}
${optionalString (cfg.up != "") "source ${userSuppliedUpScript}"}
''; '';
downScript = '' downScript = ''
@@ -38,6 +39,15 @@ let
export PATH=${path} export PATH=${path}
${optionalString cfg.updateResolvConf ${optionalString cfg.updateResolvConf
"${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"} "${pkgs.update-resolv-conf}/libexec/openvpn/update-resolv-conf"}
${optionalString (cfg.down != "") "source ${userSuppliedDownScript}"}
'';
userSuppliedUpScript = pkgs.writeScript "openvpn-${name}-userSuppliedUpScript" ''
${cfg.up}
'';
userSuppliedDownScript = pkgs.writeScript "openvpn-${name}-userSuppliedDownScript" ''
${cfg.down} ${cfg.down}
''; '';
@@ -133,7 +143,7 @@ in
default = ""; default = "";
type = types.lines; type = types.lines;
description = '' description = ''
Shell commands executed when the instance is starting. Shell script sourced by NixOS generated script when the instance is starting.
''; '';
}; };
@@ -141,7 +151,7 @@ in
default = ""; default = "";
type = types.lines; type = types.lines;
description = '' description = ''
Shell commands executed when the instance is shutting down. Shell script sourced by NixOS generated script when the instance is shutting down.
''; '';
}; };