feat(pkgs): add genericBinWrapper & mullvadExcludeWrapper

These allow creating wrapped packages that passthrough their arguments, so
`.override` can still be called on them with same arguments.
This commit is contained in:
Felix Schröter 2023-04-26 00:11:42 +02:00
parent 3f41074f15
commit a2d2991e32
Signed by: felschr
GPG key ID: 671E39E6744C807D
3 changed files with 51 additions and 1 deletions
pkgs
generic-bin-wrapper
mullvad-exclude-wrapper

View file

@ -0,0 +1,32 @@
{ stdenv, callPackage }:
{ package # pkg must contain $out/bin with executables within.
, binPath ?
"bin/${package.meta.mainProgram or package.pname}" # path to look for binary
, wrapper # wrapper must contain @EXECUTABLE@ as a placeholder for the binary to run.
}:
# pass through all arguments to wrapped package to allow overriding
# arguments in wrapped package
callPackage (args:
stdenv.mkDerivation {
name = "${package.name}-wrapped";
inherit (package) version;
src = package.override args;
dontUnpack = true;
# inherit passthru
inherit (package) passthru;
installPhase = ''
local executable=$out/${binPath}
install -D ${wrapper} "$executable"
substituteInPlace "$executable" --subst-var-by EXECUTABLE "$f"
# Symlink the share directory so that .desktop files and such continue to work.
if [[ -d $src/share ]]
then
ln -s $src/share $out/share
fi
'';
}) { }

View file

@ -0,0 +1,7 @@
{ writeShellScript, genericBinWrapper, mullvad-vpn }:
args:
let
wrapper = writeShellScript "mullvad-exclude" ''
${mullvad-vpn}/bin/mullvad-exclude "@EXECUTABLE@" "$@"
'';
in genericBinWrapper (args // { inherit wrapper; })