blob: 383b974f5674eba95f0b840addba306c432ac3aa (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
{ 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}";
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"
${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}
''
|