2021-01-10 20:56:52 +01:00
|
|
|
{ depot, pkgs, ... }:
|
|
|
|
let
|
2021-01-17 12:32:09 +01:00
|
|
|
bins = depot.nix.getBins pkgs.coreutils [ "printf" "echo" "cat" "printenv" ]
|
|
|
|
// depot.nix.getBins pkgs.fdtools [ "multitee" ]
|
|
|
|
;
|
2021-01-10 20:56:52 +01:00
|
|
|
|
|
|
|
debugExec = msg: depot.nix.writeExecline "debug-exec" {} [
|
|
|
|
"if" [
|
|
|
|
"fdmove" "-c" "1" "2"
|
|
|
|
"if" [ bins.printf "%s: " msg ]
|
|
|
|
"if" [ bins.echo "$@" ]
|
|
|
|
]
|
|
|
|
"$@"
|
|
|
|
];
|
|
|
|
|
|
|
|
eprintf = depot.nix.writeExecline "eprintf" {} [
|
2021-01-10 21:41:33 +01:00
|
|
|
"fdmove" "-c" "1" "2" bins.printf "$@"
|
2021-01-10 20:56:52 +01:00
|
|
|
];
|
|
|
|
|
2021-01-17 12:32:09 +01:00
|
|
|
eprint-stdin = depot.nix.writeExecline "eprint-stdin" {} [
|
|
|
|
"pipeline" [ bins.multitee "0-1,2" ] "$@"
|
|
|
|
];
|
|
|
|
|
|
|
|
eprintenv = depot.nix.writeExecline "eprintenv" { readNArgs = 1; } [
|
2021-01-29 15:44:17 +01:00
|
|
|
"fdmove" "-c" "1" "2" bins.printenv "$1" "$@"
|
2021-01-17 12:32:09 +01:00
|
|
|
];
|
|
|
|
|
2021-02-09 21:50:21 +01:00
|
|
|
# remove everything but a few selected environment variables
|
|
|
|
runInEmptyEnv = keepVars:
|
|
|
|
let
|
|
|
|
importas = pkgs.lib.concatMap (var: [ "importas" "-i" var var ]) keepVars;
|
|
|
|
# we have to explicitely call export here, because PATH is probably empty
|
|
|
|
export = pkgs.lib.concatMap (var: [ "${pkgs.execline}/bin/export" var ''''${${var}}'' ]) keepVars;
|
|
|
|
in depot.nix.writeExecline "empty-env" {}
|
|
|
|
(importas ++ [ "emptyenv" ] ++ export ++ [ "${pkgs.execline}/bin/exec" "$@" ]);
|
|
|
|
|
|
|
|
|
2021-01-10 20:56:52 +01:00
|
|
|
in {
|
|
|
|
inherit
|
|
|
|
debugExec
|
|
|
|
eprintf
|
2021-01-17 12:32:09 +01:00
|
|
|
eprint-stdin
|
|
|
|
eprintenv
|
2021-02-09 21:50:21 +01:00
|
|
|
runInEmptyEnv
|
2021-01-10 20:56:52 +01:00
|
|
|
;
|
|
|
|
}
|