57 lines
1.0 KiB
Nix
57 lines
1.0 KiB
Nix
{
|
|
python3,
|
|
makeWrapper,
|
|
runCommand,
|
|
lib,
|
|
}:
|
|
|
|
{
|
|
name,
|
|
text,
|
|
runtimePackages ? ps: [],
|
|
pythonPackage ? python3,
|
|
runtimeInputs ? [],
|
|
meta ? {},
|
|
passthru ? {},
|
|
derivationArgs ? {},
|
|
}:
|
|
|
|
let
|
|
|
|
pythonWithPackages = pythonPackage.withPackages runtimePackages;
|
|
|
|
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;
|
|
preferLocalBuild = false;
|
|
text = ''
|
|
#!${lib.getExe pythonWithPackages}
|
|
|
|
${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}"
|
|
''
|