1
0
Fork 0

Add nixredo-deps; Use outputs from local store when available

master
Michael Raitza 2021-02-16 13:17:01 +01:00
parent 799b381502
commit fc8781a2e0
4 changed files with 27 additions and 12 deletions

View File

@ -20,13 +20,13 @@ let
__builder = if isFunction _builder then _builder funcPkgs __builder = if isFunction _builder then _builder funcPkgs
else _builder; else _builder;
args = { stdenv = pkgs.stdenvNoCC; } // (if isString __builder args = { stdenv = pkgs.stdenvNoCC; } // (if isString __builder
then { builder = __builder; } then { builder = __builder; }
else __builder); else __builder);
in (args.deriver or args.stdenv.mkDerivation) ({ in (args.deriver or args.stdenv.mkDerivation) ({
name = pkgs.lib.strings.sanitizeDerivationName (builtins.elemAt rargs 0); name = pkgs.lib.strings.sanitizeDerivationName (builtins.elemAt rargs 0);
buildCommand = args.builder; buildCommand = args.builder;
passAsFile = [ "buildCommand" ]; passAsFile = [ "buildCommand" ];
preferLocalBuild = true; preferLocalBuild = true;
allowSubstitutes = false; allowSubstitutes = false;
} // (removeAttrs args [ "builder" "system" "deriver" ])); # myself } // (removeAttrs args [ "builder" "system" "deriver" "stdenv" ])); # myself
in myself builderArgs in myself builderArgs

View File

@ -8,8 +8,11 @@ stdenv.mkDerivation {
installPhase = '' installPhase = ''
mkdir -p $out/bin mkdir -p $out/bin
cp ${./nixredo} $out/bin/nixredo for f in ${./nixredo} ${./nixredo-deps}; do
substituteAllInPlace $out/bin/nixredo _f=$out/bin/nixredo''${f##*-nixredo}
chmod +x $out/bin/nixredo cp $f $_f
substituteAllInPlace $_f
chmod +x $_f
done
''; '';
} }

17
nixredo
View File

@ -1,17 +1,22 @@
#!/bin/sh #!/bin/sh
exec >&2 exec >&2
[ -n "$NIXREDO_ROOT" ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; } [ "${NIXREDO_ROOT-x}" != x ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; }
if [ $# -eq 0 ]; then set -- all; fi if [ $# -eq 0 ]; then set -- all; fi
if [ -e "$1.nix" ]; then if [ -e "$1.nix" ]; then
set -e set -e
set -- "$1" "$1" "$1.redo.tmp" set -- "$1" "$1" "$1.redo.tmp"
f=$(realpath "$1.nix") f=$(realpath "$1.nix")
out=$(nix -vL build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} --option auto-optimise-store true --impure --json --no-link --expr "import @buildernix@ { cwd = \"$PWD/\"; rargs = [ \"$1\" \"$1\" ];} \"$f\"" | @jq@ -r '.[0].outputs.out') out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \
--option auto-optimise-store true --option substituters daemon \
--impure --json --no-link \
--expr "import @buildernix@ { cwd = \"$PWD/\"; rargs = [ \"$1\" \"$1\" ];} \"$f\"" |
@jq@ -r '.[0].outputs.out')
[ -n "$out" ] || exit 127 [ -n "$out" ] || exit 127
rm -rf "$1" rm -rf "$3"
ln "${NIXREDO_ROOT+$NIXREDO_ROOT/}$out" "$3" ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"
chmod +w "$3" # ln "${NIXREDO_ROOT+$NIXREDO_ROOT/}$out" "$3"
touch "$3" # chmod +w "$3"
# touch "$3"
mv "$3" "$1" mv "$3" "$1"
elif [ -e "$1" ]; then elif [ -e "$1" ]; then
: :

7
nixredo-deps Normal file
View File

@ -0,0 +1,7 @@
#!/bin/sh
exec >&2
[ "${NIXREDO_ROOT-x}" != x ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; }
f=$(realpath "$1")
drv=$(nix-store --store "$NIXREDO_ROOT" -qd "${f#$NIXREDO_ROOT}/nix/store")
nix-store --store "$NIXREDO_ROOT" -qR "${drv#$NIXREDO_ROOT}"