about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Hoeg <peter@hoeg.com>2022-04-08 11:36:20 +0800
committerPeter Hoeg <peter@hoeg.com>2022-04-12 22:59:11 +0800
commitadbf08f9ec3247e43e444c57bac01b52dd648ac6 (patch)
tree15eb34940466b39be13792e52524898652c95db1
parent764c88feaca0b3768176ae907740a53f7ac42af6 (diff)
update-systemd-resolved: inject PATH to avoid wrapping
-rw-r--r--pkgs/tools/networking/openvpn/update-systemd-resolved.nix34
-rw-r--r--pkgs/tools/networking/openvpn/update-systemd-resolved.patch26
2 files changed, 47 insertions, 13 deletions
diff --git a/pkgs/tools/networking/openvpn/update-systemd-resolved.nix b/pkgs/tools/networking/openvpn/update-systemd-resolved.nix
index 5a34d5a7ffe77..1b514eae02f0b 100644
--- a/pkgs/tools/networking/openvpn/update-systemd-resolved.nix
+++ b/pkgs/tools/networking/openvpn/update-systemd-resolved.nix
@@ -1,34 +1,42 @@
-{ lib, stdenv, fetchFromGitHub
-, makeWrapper
-, iproute2, systemd, coreutils, util-linux }:
+{ lib
+, stdenv
+, fetchFromGitHub
+, iproute2
+, runtimeShell
+, systemd
+, coreutils
+, util-linux
+}:
 
 stdenv.mkDerivation rec {
   pname = "update-systemd-resolved";
+  # when updating this, check if additional binaries need injecting into PATH
   version = "1.3.0";
 
   src = fetchFromGitHub {
     owner = "jonathanio";
     repo = "update-systemd-resolved";
     rev = "v${version}";
-    sha256 = "19zhbpyms57yb70hi0ws5sbkpk2yqp9nnix3f86r36h1g93m70lm";
+    hash = "sha256-lYJTR3oBmpENcqNHa9PFXsw7ly6agwjBWf4UXf1d8Kc=";
   };
 
-  nativeBuildInputs = [ makeWrapper ];
-
-  buildFlags = [
-    "PREFIX=${placeholder "out"}/libexec/openvpn"
+  # set SCRIPT_NAME in case we are wrapped and inject PATH
+  patches = [
+    ./update-systemd-resolved.patch
   ];
 
-  installPhase = ''
-    wrapProgram $out/libexec/openvpn/update-systemd-resolved \
-      --prefix PATH : ${lib.makeBinPath [ iproute2 systemd coreutils util-linux ]}
+  PREFIX = "${placeholder "out"}/libexec/openvpn";
+
+  postInstall = ''
+    substituteInPlace ${PREFIX}/update-systemd-resolved \
+      --subst-var-by PATH ${lib.makeBinPath [ coreutils iproute2 runtimeShell systemd util-linux ]}
   '';
 
   meta = with lib; {
     description = "Helper script for OpenVPN to directly update the DNS settings of a link through systemd-resolved via DBus";
     homepage = "https://github.com/jonathanio/update-systemd-resolved";
+    license = licenses.gpl3Only;
     maintainers = with maintainers; [ eadwu ];
-    license = licenses.gpl3;
-    platforms = platforms.unix;
+    platforms = platforms.linux;
   };
 }
diff --git a/pkgs/tools/networking/openvpn/update-systemd-resolved.patch b/pkgs/tools/networking/openvpn/update-systemd-resolved.patch
new file mode 100644
index 0000000000000..e03c476e5090d
--- /dev/null
+++ b/pkgs/tools/networking/openvpn/update-systemd-resolved.patch
@@ -0,0 +1,26 @@
+diff --git a/Makefile b/Makefile
+index 524b6b7..8a880f1 100644
+--- a/Makefile
++++ b/Makefile
+@@ -9,7 +9,6 @@ all: install info
+ 
+ install:
+ 	@install -Dm750 $(SRC) $(DEST)
+-	@install -Dm644 $(SRC).conf $(DEST).conf
+ 
+ info:
+ 	@printf 'Successfully installed %s to %s.\n' $(SRC) $(DEST)
+diff --git a/update-systemd-resolved b/update-systemd-resolved
+index 1452e1a..39641cb 100755
+--- a/update-systemd-resolved
++++ b/update-systemd-resolved
+@@ -29,7 +29,8 @@
+ DBUS_DEST="org.freedesktop.resolve1"
+ DBUS_NODE="/org/freedesktop/resolve1"
+ 
+-SCRIPT_NAME="${BASH_SOURCE[0]##*/}"
++PATH="@PATH@"
++SCRIPT_NAME="update-systemd-resolved"
+ 
+ log() {
+   logger -s -t "$SCRIPT_NAME" "$@"