commit
799b381502
|
@ -0,0 +1,32 @@
|
|||
builderArgs:
|
||||
let
|
||||
|
||||
myself = { nixpkgs ? <nixpkgs>, pkgs ? import nixpkgs {}, rargs, cwd }:
|
||||
builder:
|
||||
with builtins;
|
||||
let
|
||||
resolveLocal = arg: let
|
||||
fullPath = cwd + "/" + arg + ".nix";
|
||||
recurse = myself { rargs = [ (toString arg) (toString arg) ]; inherit cwd; };
|
||||
in recurse fullPath;
|
||||
funcPkgs = { __functor = self: arg: resolveLocal arg; } // pkgs;
|
||||
|
||||
_builder = if (tryEval (import builder)).success
|
||||
then import builder
|
||||
else ''
|
||||
#!/bin/sh
|
||||
${builder} $1 $2 $out >$out
|
||||
'';
|
||||
__builder = if isFunction _builder then _builder funcPkgs
|
||||
else _builder;
|
||||
args = { stdenv = pkgs.stdenvNoCC; } // (if isString __builder
|
||||
then { builder = __builder; }
|
||||
else __builder);
|
||||
in (args.deriver or args.stdenv.mkDerivation) ({
|
||||
name = pkgs.lib.strings.sanitizeDerivationName (builtins.elemAt rargs 0);
|
||||
buildCommand = args.builder;
|
||||
passAsFile = [ "buildCommand" ];
|
||||
preferLocalBuild = true;
|
||||
allowSubstitutes = false;
|
||||
} // (removeAttrs args [ "builder" "system" "deriver" ])); # myself
|
||||
in myself builderArgs
|
|
@ -0,0 +1,15 @@
|
|||
{ stdenv, jq }:
|
||||
|
||||
stdenv.mkDerivation {
|
||||
name = "nixredo-1";
|
||||
phases = [ "installPhase" "fixupPhase" ];
|
||||
jq = "${jq}/bin/jq";
|
||||
buildernix = ./builder.nix;
|
||||
|
||||
installPhase = ''
|
||||
mkdir -p $out/bin
|
||||
cp ${./nixredo} $out/bin/nixredo
|
||||
substituteAllInPlace $out/bin/nixredo
|
||||
chmod +x $out/bin/nixredo
|
||||
'';
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
#!/bin/sh
|
||||
exec >&2
|
||||
[ -n "$NIXREDO_ROOT" ] || { printf "Set NIXREDO_ROOT. Set empty to use global nix store\n"; exit 127; }
|
||||
if [ $# -eq 0 ]; then set -- all; fi
|
||||
if [ -e "$1.nix" ]; then
|
||||
set -e
|
||||
set -- "$1" "$1" "$1.redo.tmp"
|
||||
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')
|
||||
[ -n "$out" ] || exit 127
|
||||
rm -rf "$1"
|
||||
ln "${NIXREDO_ROOT+$NIXREDO_ROOT/}$out" "$3"
|
||||
chmod +w "$3"
|
||||
touch "$3"
|
||||
mv "$3" "$1"
|
||||
elif [ -e "$1" ]; then
|
||||
:
|
||||
else
|
||||
printf "Error: No rule to build %s\n" "$1"
|
||||
exit 127
|
||||
fi
|
Loading…
Reference in New Issue