diff --git a/pkgs/build-support/writePythonScript.nix b/pkgs/build-support/writePythonScript.nix index c670818..337eb67 100644 --- a/pkgs/build-support/writePythonScript.nix +++ b/pkgs/build-support/writePythonScript.nix @@ -1,6 +1,7 @@ { python3, - writeTextFile, + makeWrapper, + runCommand, lib, }: @@ -9,6 +10,7 @@ text, runtimePackages ? ps: [], pythonPackage ? python3, + runtimeInputs ? [], meta ? {}, passthru ? {}, derivationArgs ? {}, @@ -18,13 +20,17 @@ let pythonWithPackages = pythonPackage.withPackages runtimePackages; -in writeTextFile { - inherit - name - meta - passthru - derivationArgs - ; +in runCommand name ({ + passAsFile = [ "text" ] ++ (derivationArgs.passAsFile or []); + + meta = { + mainProgram = name; + } // meta // (derivationArgs.meta or {}); + + passthru = passthru // (derivationArgs.passthru or {}); + + nativeBuildInputs = [ makeWrapper ] ++ (derivationArgs.nativeBuildInputs or []); + executable = true; destination = "/bin/${name}"; allowSubstitutes = true; @@ -34,4 +40,17 @@ in writeTextFile { ${text} ''; -} +} // ( + builtins.removeAttrs derivationArgs [ "passAsFile" "meta" "passthru" "nativeBuildInputs" ] +)) +'' +mkdir -p $out/bin + +target=$out/bin/${lib.escapeShellArg name} + +cp "$textPath" "$target" + +chmod +x "$target" + +wrapProgram "$target" --prefix PATH : "${lib.makeBinPath runtimeInputs}" +''