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