Move TMPDIR next to NIXREDO_ROOT
parent
870493c34b
commit
52f6a2badf
12
lib.nix
12
lib.nix
|
@ -1,16 +1,14 @@
|
||||||
{ lib ? import <nixpkgs/lib> }:
|
{ lib ? import <nixpkgs/lib> }:
|
||||||
let
|
let
|
||||||
inherit (builtins) length genList pathExists;
|
inherit (builtins) baseNameOf dirOf length genList pathExists;
|
||||||
inherit (lib) take splitString concatStringsSep last foldl foldr head
|
inherit (lib) take splitString concatStringsSep last foldl foldr head
|
||||||
tail singleton removePrefix hasSuffix removeSuffix flatten crossLists reverseList;
|
tail singleton removePrefix hasSuffix removeSuffix flatten crossLists reverseList;
|
||||||
butlast = list: take (length list - 1) list;
|
butlast = list: take (length list - 1) list;
|
||||||
dirname = path: let _p = (butlast (splitString "/" path)); in if _p != [] then concatStringsSep "/" _p else "./";
|
|
||||||
basename = path: (last (splitString "/" path));
|
|
||||||
|
|
||||||
doFileSuffix = "do";
|
doFileSuffix = "do";
|
||||||
|
|
||||||
genPatterns = path: let
|
genPatterns = path: let
|
||||||
fn = basename path;
|
fn = baseNameOf path;
|
||||||
in (map (x: "default." + x)
|
in (map (x: "default." + x)
|
||||||
(foldr (a: b: let x = (head b); in [ (a + "." + x) ] ++ b)
|
(foldr (a: b: let x = (head b); in [ (a + "." + x) ] ++ b)
|
||||||
[ doFileSuffix ]
|
[ doFileSuffix ]
|
||||||
|
@ -37,18 +35,18 @@ let
|
||||||
in foldl (res: p: if res == "" then if pathExists p then p else res else res) "" pathlist;
|
in foldl (res: p: if res == "" then if pathExists p then p else res else res) "" pathlist;
|
||||||
|
|
||||||
d1 = path: pat: let
|
d1 = path: pat: let
|
||||||
dir = (dirname pat) + "/";
|
dir = (dirOf pat) + "/";
|
||||||
in removePrefix dir path;
|
in removePrefix dir path;
|
||||||
|
|
||||||
d2 = path: pat: let
|
d2 = path: pat: let
|
||||||
dir = (dirname pat) + "/";
|
dir = (dirOf pat) + "/";
|
||||||
_path = removePrefix dir path;
|
_path = removePrefix dir path;
|
||||||
_pat = removeSuffix ".${doFileSuffix}" (removePrefix "${dir}default" pat);
|
_pat = removeSuffix ".${doFileSuffix}" (removePrefix "${dir}default" pat);
|
||||||
_out = removeSuffix _pat _path;
|
_out = removeSuffix _pat _path;
|
||||||
in if _out == "" then _path else _out;
|
in if _out == "" then _path else _out;
|
||||||
|
|
||||||
self = {
|
self = {
|
||||||
inherit dirname basename searchPath cwd path doFileSuffix whichdo d1 d2;
|
inherit searchPath cwd path doFileSuffix whichdo d1 d2;
|
||||||
};
|
};
|
||||||
|
|
||||||
in self
|
in self
|
||||||
|
|
15
nixredo
15
nixredo
|
@ -4,6 +4,11 @@ exec >&2
|
||||||
[ "${NIXREDO_ROOT-x}" != x ] || { 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 [ -n "${NIXREDO_ROOT}" ]; then
|
||||||
|
export TMPDIR="${NIXREDO_ROOT}/tmp"
|
||||||
|
mkdir -p "$TMPDIR"
|
||||||
|
fi
|
||||||
|
|
||||||
S=$(realpath -s "$S")
|
S=$(realpath -s "$S")
|
||||||
|
|
||||||
if [ "${NIXREDO_ROOT#$S}" != "${NIXREDO_ROOT}" ]; then
|
if [ "${NIXREDO_ROOT#$S}" != "${NIXREDO_ROOT}" ]; then
|
||||||
|
@ -15,15 +20,15 @@ fi
|
||||||
set -e
|
set -e
|
||||||
set -- "$1" "$1" "$1.redo.tmp"
|
set -- "$1" "$1" "$1.redo.tmp"
|
||||||
f=$(realpath -s "$1")
|
f=$(realpath -s "$1")
|
||||||
|
rm -f -- "$3"
|
||||||
|
# Work around broken local store support. out-links are not correctly resolved.
|
||||||
|
# We solve gcroots in nixredo-gc
|
||||||
out=$(nix -vL --show-trace build ${NIXREDO_ROOT:+--store "$NIXREDO_ROOT"} \
|
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 \
|
||||||
--impure --json --no-link \
|
--impure --json --no-link \
|
||||||
--expr " import @buildernix@ { lib = import @libnix@ {}; root =\"$S\"; filter = [ \"$filter\" ]; } \"$f\"" |
|
--expr " import @buildernix@ { lib = import @libnix@ {}; root =\"$S\"; filter = [ \"$filter\" \"$f\" ]; } \"$f\"" |
|
||||||
@jq@ -r '.[0].outputs.out')
|
@jq@ -r '.[0].outputs.out')
|
||||||
[ -n "$out" ] || exit 127
|
[ -n "$out" ] || exit 127
|
||||||
rm -rf "$3"
|
|
||||||
ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"
|
ln -s "${NIXREDO_ROOT+$NIXREDO_ROOT}$out" "$3"
|
||||||
# ln "${NIXREDO_ROOT+$NIXREDO_ROOT/}$out" "$3"
|
|
||||||
# chmod +w "$3"
|
|
||||||
# touch "$3"
|
|
||||||
mv "$3" "$1"
|
mv "$3" "$1"
|
||||||
|
|
Loading…
Reference in New Issue