diff options
Diffstat (limited to 'nixpkgs/pkgs/tools/misc/execline')
-rw-r--r-- | nixpkgs/pkgs/tools/misc/execline/default.nix | 111 | ||||
-rw-r--r-- | nixpkgs/pkgs/tools/misc/execline/execlineb-wrapper.c | 43 |
2 files changed, 120 insertions, 34 deletions
diff --git a/nixpkgs/pkgs/tools/misc/execline/default.nix b/nixpkgs/pkgs/tools/misc/execline/default.nix index 5a967ea2095..a1907434181 100644 --- a/nixpkgs/pkgs/tools/misc/execline/default.nix +++ b/nixpkgs/pkgs/tools/misc/execline/default.nix @@ -1,42 +1,85 @@ -{ skawarePackages, makeWrapper }: +{ lib, skawarePackages +# for execlineb-with-builtins +, coreutils, gnugrep, writeScriptBin, runCommand, runCommandCC +# Whether to wrap bin/execlineb to have the execline tools on its PATH. +, execlineb-with-builtins ? true +}: with skawarePackages; -buildPackage { - pname = "execline"; - version = "2.5.1.0"; - sha256 = "0xr6yb50wm6amj1wc7jmxyv7hvlx2ypbnww1vc288j275625d9xi"; +let + outputs = [ "bin" "lib" "dev" "doc" "out" ]; - description = "A small scripting language, to be used in place of a shell in non-interactive scripts"; + execline = + buildPackage { + pname = "execline"; + version = "2.5.1.0"; + sha256 = "0xr6yb50wm6amj1wc7jmxyv7hvlx2ypbnww1vc288j275625d9xi"; - outputs = [ "bin" "lib" "dev" "doc" "out" ]; + description = "A small scripting language, to be used in place of a shell in non-interactive scripts"; + + inherit outputs; + + # TODO: nsss support + configureFlags = [ + "--libdir=\${lib}/lib" + "--dynlibdir=\${lib}/lib" + "--bindir=\${bin}/bin" + "--includedir=\${dev}/include" + "--with-sysdeps=${skalibs.lib}/lib/skalibs/sysdeps" + "--with-include=${skalibs.dev}/include" + "--with-lib=${skalibs.lib}/lib" + "--with-dynlib=${skalibs.lib}/lib" + ]; + + postInstall = '' + # remove all execline executables from build directory + rm $(find -type f -mindepth 1 -maxdepth 1 -executable) + rm libexecline.* - setupHooks = [ makeWrapper ]; - - # TODO: nsss support - configureFlags = [ - "--libdir=\${lib}/lib" - "--dynlibdir=\${lib}/lib" - "--bindir=\${bin}/bin" - "--includedir=\${dev}/include" - "--with-sysdeps=${skalibs.lib}/lib/skalibs/sysdeps" - "--with-include=${skalibs.dev}/include" - "--with-lib=${skalibs.lib}/lib" - "--with-dynlib=${skalibs.lib}/lib" - ]; - - postInstall = '' - # remove all execline executables from build directory - rm $(find -type f -mindepth 1 -maxdepth 1 -executable) - rm libexecline.* - - mv doc $doc/share/doc/execline/html - mv examples $doc/share/doc/execline/examples - - # finally, add all tools to PATH so they are available - # from within execlineb scripts by default - wrapProgram $bin/bin/execlineb \ - --suffix PATH : $bin/bin + mv doc $doc/share/doc/execline/html + mv examples $doc/share/doc/execline/examples + ''; + + }; + + # A wrapper around execlineb, which provides all execline + # tools on `execlineb`’s PATH. + # It is implemented as a C script, because on non-Linux, + # nested shebang lines are not supported. + execlineb-with-builtins-drv = runCommandCC "execlineb" {} '' + mkdir -p $out/bin + cc \ + -O \ + -Wall -Wpedantic \ + -D 'EXECLINEB_PATH()="${execline}/bin/execlineb"' \ + -D 'EXECLINE_BIN_PATH()="${execline}/bin"' \ + -I "${skalibs.dev}/include" \ + -L "${skalibs.lib}/lib" \ + -l"skarnet" \ + -o "$out/bin/execlineb" \ + ${./execlineb-wrapper.c} ''; -} + + # 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 diff --git a/nixpkgs/pkgs/tools/misc/execline/execlineb-wrapper.c b/nixpkgs/pkgs/tools/misc/execline/execlineb-wrapper.c new file mode 100644 index 00000000000..09ccf990af7 --- /dev/null +++ b/nixpkgs/pkgs/tools/misc/execline/execlineb-wrapper.c @@ -0,0 +1,43 @@ +#include <stdlib.h> +#include <string.h> + +#include <skalibs/stralloc.h> +#include <skalibs/djbunix.h> +#include <skalibs/strerr2.h> +#include <skalibs/env.h> + +#define dienomem() strerr_diefu1sys(111, "stralloc_catb") + +// macros from outside +/* const char* EXECLINEB_PATH; */ +/* const char* EXECLINE_BIN_PATH; */ + +int main(int argc, char const* argv[], char const *const *envp) +{ + PROG = "execlineb-wrapper"; + + char const* path = getenv("PATH"); + stralloc path_modif = STRALLOC_ZERO; + + // modify PATH if unset or EXECLINEB_BIN_PATH is not yet there + if ( !path || ! strstr(path, EXECLINE_BIN_PATH())) { + // prepend our execline path + if ( ! stralloc_cats(&path_modif, "PATH=") + || ! stralloc_cats(&path_modif, EXECLINE_BIN_PATH()) ) dienomem(); + // old path was not empty + if ( path && path[0] ) { + if ( ! stralloc_catb(&path_modif, ":", 1) + || ! stralloc_cats(&path_modif, path) ) dienomem(); + } + // append final \0 + if ( ! stralloc_0(&path_modif) ) dienomem(); + } + + // exec into execlineb and append path_modif to the environment + xpathexec_r_name( + EXECLINEB_PATH(), + argv, + envp, env_len(envp), + path_modif.s, path_modif.len + ); +} |