execline: provide tools to execlineb via execline wrapper

Introduces the `execlineb-with-builtins` flag, which when
true (default) will add all execline builtins to the PATH of
`execlineb`.

This is usually what users expect.

If the flag is set to `false`, the unpatched execline derivation is
returned instead.
This commit is contained in:
Profpatsch 2019-10-14 17:11:48 +02:00
parent bbcdd01f6b
commit 2d28753c4c

View File

@ -1,7 +1,16 @@
{ skawarePackages }: { lib, skawarePackages
# for execlineb-with-builtins
, coreutils, gnugrep, writeScriptBin, runCommand
# Whether to wrap bin/execlineb to have the execline tools on its PATH.
, execlineb-with-builtins ? true
}:
with skawarePackages; with skawarePackages;
let
outputs = [ "bin" "lib" "dev" "doc" "out" ];
execline =
buildPackage { buildPackage {
pname = "execline"; pname = "execline";
version = "2.5.1.0"; version = "2.5.1.0";
@ -9,7 +18,7 @@ buildPackage {
description = "A small scripting language, to be used in place of a shell in non-interactive scripts"; description = "A small scripting language, to be used in place of a shell in non-interactive scripts";
outputs = [ "bin" "lib" "dev" "doc" "out" ]; inherit outputs;
# TODO: nsss support # TODO: nsss support
configureFlags = [ configureFlags = [
@ -32,4 +41,50 @@ buildPackage {
mv examples $doc/share/doc/execline/examples mv examples $doc/share/doc/execline/examples
''; '';
};
# a wrapper around execlineb, which provides all execline
# tools on `execlineb`s PATH.
execlineb-with-builtins-drv =
let eldir = "${execline}/bin";
in writeScriptBin "execlineb" ''
#!${eldir}/execlineb -s0
# appends the execlineb bin dir to PATH if not yet in PATH
${eldir}/define eldir ${eldir}
''${eldir}/ifelse
{
# since this is nix, we can grep for the execline drv hash in PATH
# to see whether its already in there
''${eldir}/pipeline
{ ${coreutils}/bin/printenv PATH }
${gnugrep}/bin/grep --quiet "${eldir}"
} }
# its there already
{ ''${eldir}/execlineb $@ }
# not there yet, add it
''${eldir}/importas oldpath PATH
''${eldir}/export PATH "''${eldir}:''${oldpath}"
''${eldir}/execlineb $@
'';
# the original execline package, with bin/execlineb overwritten
execline-with-builtins = runCommand "my-execline"
(execline.drvAttrs // {
preferLocalBuild = true;
allowSubstitutes = false;
})
# copy every output and just overwrite the execlineb binary in $bin
''
${lib.concatMapStringsSep "\n"
(output: ''
cp -r ${execline.${output}} "''$${output}"
chmod --recursive +w "''$${output}"
'')
outputs}
install ${execlineb-with-builtins-drv}/bin/execlineb $bin/bin/execlineb
'';
in
if execlineb-with-builtins
then execline-with-builtins
else execline