about summary refs log tree commit diff
path: root/pkgs/taalo-build
diff options
context:
space:
mode:
authoraszlig <aszlig@nix.build>2019-01-04 15:54:13 +0100
committeraszlig <aszlig@nix.build>2019-01-04 15:54:13 +0100
commit192da558b7c748864703659597d26626eb87677c (patch)
tree099fb4727ad7f901d569c5457be39cced7cb7356 /pkgs/taalo-build
parent18027679fef00ad5f0ee4afd664427d208fc4468 (diff)
taalo-build: Switch back to instantiate + realize
I refactored the two tools a while ago but eventually rendered
taalo-realize useless, because it doesn't copy the derivation to realize
to the remote host.

This is done now, plus the taalo-build command now makes sure that we
instantiate on the local machine, thus speeding up builds a lot (except
maybe if the local host is under very high load).

In addition I added an indirect gcroot inside a temporary directory, so
that we don't get into a race condition when garbage collecting between
instantiate and realize.

Instead of nix-copy-closure, I now use "nix copy", which properly
supports the ssh-ng store backend. However I didn't use "nix build" and
friends, because these commands still lack a few features.

Signed-off-by: aszlig <aszlig@nix.build>
Diffstat (limited to 'pkgs/taalo-build')
-rw-r--r--pkgs/taalo-build/default.nix26
1 files changed, 19 insertions, 7 deletions
diff --git a/pkgs/taalo-build/default.nix b/pkgs/taalo-build/default.nix
index d9ff8976..700dfd1c 100644
--- a/pkgs/taalo-build/default.nix
+++ b/pkgs/taalo-build/default.nix
@@ -1,19 +1,31 @@
-{ stdenv, lib, runCommand, nixUnstable }:
+{ stdenv, lib, runCommand, coreutils, nixUnstable }:
 
 let
   nixRemote = "ssh-ng://nix-remote-build@taalo.headcounter.org?compress=true";
+  remoteEsc = lib.escapeShellArg nixRemote;
+  mkNix = cmd: lib.escapeShellArg "${nixUnstable}/bin/${cmd}";
 
-  mkScript = cmd: lib.escapeShellArg ''
-    #!${stdenv.shell}
-    export NIX_REMOTE=${lib.escapeShellArg nixRemote}
-    exec ${lib.escapeShellArg nixUnstable}/bin/${cmd} "$@"
+  errorOnly = cmd:
+    "if ! outerr=\"$(${cmd} 2>&1)\"; then echo \"$outerr\" >&2; exit 1; fi";
+
+  remoteRealize = pre: arg: ''
+    ${errorOnly "${mkNix "nix"} copy -s --quiet --to ${remoteEsc} ${arg}"}
+    NIX_REMOTE=${remoteEsc} ${pre}${mkNix "nix-store"} -r ${arg}
   '';
 
+  emitScript = content:
+    "echo -n ${lib.escapeShellArg "#!${stdenv.shell}\nset -e\n${content}"}";
+
 in runCommand "taalo-build" {} ''
   mkdir -p "$out/bin"
 
-  echo -n ${mkScript "nix-build"} > "$out/bin/taalo-build"
-  echo -n ${mkScript "nix-store -r"} > "$out/bin/taalo-realize"
+  ${emitScript (''
+    gctmp="$(${lib.escapeShellArg "${coreutils}/bin/mktemp"} -d)"
+    trap 'rm -rf "$gctmp"' EXIT
+    drv="$(${mkNix "nix-instantiate"} --add-root "$gctmp/drv" --indirect "$@")"
+  '' + remoteRealize "" "\"$drv\"")} > "$out/bin/taalo-build"
+
+  ${emitScript (remoteRealize "exec " "\"$@\"")} > "$out/bin/taalo-realize"
 
   chmod +x "$out"/bin/taalo-{build,realize}
 ''