1
0
Fork 0

Add src directory location info with cwd and (relative) rcwd

master
Michael Raitza 2021-02-17 18:42:17 +01:00
parent 9c20083680
commit d0d5b30f6a
2 changed files with 12 additions and 11 deletions

View File

@ -1,4 +1,4 @@
buildArgs@{ lib ? import ./lib.nix {}, nixpkgs ? <nixpkgs>, pkgs ? import nixpkgs {}, root, filter ? [] }:
buildArgs@{ lib ? import ./lib.nix {}, nixpkgs ? <nixpkgs>, pkgs ? import nixpkgs {}, root, cwd, filter ? [] }:
let
inherit (lib) searchPath whichdo d1 d2;
@ -14,10 +14,13 @@ let
# Funktionalise pkgs; our main entry point to resolve default*nix build scripts.
getSrc = filterSource
(path: type: baseNameOf path != ".git" && baseNameOf path != ".envrc" && (all (x: path != x) filter));
rcwd = dirOf (removePrefix (root + "/") builder);
funcPkgs = {
__functor = self: arg: resolve arg;
redo.getSrc = getSrc;
} // pkgs;
inherit pkgs getSrc cwd rcwd;
};
_builder = let
imported = (tryEval (let
@ -28,17 +31,15 @@ let
then imported.value
else {
src = getSrc (/. + root);
builder = let
relPath = dirOf (removePrefix (root + "/") builder);
in ''
builder = ''
#!/bin/sh
set -e
pout=$(mktemp -u -p $PWD)
cp -r --reflink=auto --no-preserve=mode "$src/" src
cd src/${relPath}
${/. + builder} $d1 $d2 $out >$pout
if [ -e $out -a -s $pout ]; then
printf "Error: %s wrote to stdout and created \$3\n" "$d1" >&2
cd src/${rcwd}
${/. + builder} "$d1" "$d2" "$out" >$pout
if [ -e "$out" -a -s "$pout" ]; then
printf "Error: %s wrote to stdout and created \$3\n" "${baseNameOf builder}" >&2
exit 207
elif [ -s $pout ]; then
mv $pout $out

View File

@ -27,7 +27,7 @@ out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \
--option auto-optimise-store true --option substituters daemon \
--option keep-failed true --option keep-outputs true \
--impure --json --no-link \
--expr " import @buildernix@ { lib = import @libnix@ {}; root =\"$S\"; filter = [ \"$filter\" \"$f\" ]; } \"$f\"" |
--expr " import @buildernix@ { lib = import @libnix@ {}; root =\"$S\"; cwd = \"$PWD\"; filter = [ \"$filter\" \"$f\" ]; } \"$f\"" |
@jq@ -r '.[0].outputs.out')
[ -n "$out" ] || exit 127
ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"