From 192da558b7c748864703659597d26626eb87677c Mon Sep 17 00:00:00 2001 From: aszlig Date: Fri, 4 Jan 2019 15:54:13 +0100 Subject: 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 --- pkgs/taalo-build/default.nix | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) (limited to 'pkgs/taalo-build') 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} '' -- cgit 1.4.1