From d0d5b30f6abef866365b1a1b7714fd5d9faafc28 Mon Sep 17 00:00:00 2001 From: Michael Raitza Date: Wed, 17 Feb 2021 18:42:17 +0100 Subject: [PATCH] Add src directory location info with cwd and (relative) rcwd --- builder.nix | 21 +++++++++++---------- nixredo | 2 +- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/builder.nix b/builder.nix index 5ecf5c2..efb296f 100644 --- a/builder.nix +++ b/builder.nix @@ -1,4 +1,4 @@ -buildArgs@{ lib ? import ./lib.nix {}, nixpkgs ? , pkgs ? import nixpkgs {}, root, filter ? [] }: +buildArgs@{ lib ? import ./lib.nix {}, 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 diff --git a/nixredo b/nixredo index af025bf..0953911 100644 --- a/nixredo +++ b/nixredo @@ -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"