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:
parent
3f41074f15
commit
a2d2991e32
3 changed files with 51 additions and 1 deletions
pkgs
32
pkgs/generic-bin-wrapper/default.nix
Normal file
32
pkgs/generic-bin-wrapper/default.nix
Normal 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
|
||||
'';
|
||||
}) { }
|
7
pkgs/mullvad-exclude-wrapper/default.nix
Normal file
7
pkgs/mullvad-exclude-wrapper/default.nix
Normal 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; })
|
Loading…
Add table
Add a link
Reference in a new issue