about summary refs log tree commit diff
path: root/modules
diff options
context:
space:
mode:
authoraszlig <aszlig@redmoonstudios.org>2016-05-29 20:09:38 +0200
committeraszlig <aszlig@redmoonstudios.org>2016-05-29 20:09:38 +0200
commit53e5da6c11b9fb00b460363e0ff670f5454c00e5 (patch)
tree6b6b9d04110f4eb56d81a61ffe445a9eb2d4a59f /modules
parent9959d0977b1772e9991e7c1c7810fad2c1cf4dfc (diff)
programs/taalo-build: Split into realize and build
With just taalo-build we can't realize plain .drv files, so let's use
the Perl part to just realize the derivations given by the command line
and provide two shell script wrappers on top of it:

 * taalo-build: Similar to nix-build
 * taalo-realize: Similar to nix-store -r

Having a command like taalo-realize is very useful if evaluation is done
on a different machine and the closure is just copied over to the local
machine before being sent to taalo.

Signed-off-by: aszlig <aszlig@redmoonstudios.org>
Diffstat (limited to 'modules')
-rw-r--r--modules/user/aszlig/programs/taalo-build/default.nix106
1 files changed, 58 insertions, 48 deletions
diff --git a/modules/user/aszlig/programs/taalo-build/default.nix b/modules/user/aszlig/programs/taalo-build/default.nix
index 6b50df1d..6e3ee86e 100644
--- a/modules/user/aszlig/programs/taalo-build/default.nix
+++ b/modules/user/aszlig/programs/taalo-build/default.nix
@@ -1,65 +1,75 @@
 { config, pkgs, lib, ... }:
 
-with lib;
+let
+  backend = pkgs.writeScript "taalo-realize-backend" ''
+    #!${pkgs.perl}/bin/perl -I${pkgs.nix}/lib/perl5/site_perl
+    use strict;
+    use Nix::CopyClosure;
+    use Nix::SSH;
+    use IPC::Open2;
 
-{
-  options.vuizvui.user.aszlig.programs.taalo-build = {
-    enable = mkEnableOption "aszlig's build helper for remote builds";
-  };
-  config = mkIf config.vuizvui.user.aszlig.programs.taalo-build.enable {
-    environment.systemPackages = singleton (pkgs.writeScriptBin "taalo-build" ''
-      #!${pkgs.perl}/bin/perl -I${pkgs.nix}/lib/perl5/site_perl
-      use strict;
-      use Nix::CopyClosure;
-      use Nix::SSH;
-      use IPC::Open2;
+    binmode STDERR, ":encoding(utf8)";
+
+    my ($from, $to);
+    my $dest = 'nix-remote-build@taalo.headcounter.org';
+    my $cmd = "exec ssh $dest -C -- nix-store --serve --write";
+    my $pid = open2($from, $to, $cmd);
 
-      binmode STDERR, ":encoding(utf8)";
+    # Do the handshake.
+    my $magic;
+    eval {
+        my $SERVE_MAGIC_1 = 0x390c9deb; # FIXME
+        my $clientVersion = 0x200;
+        syswrite($to, pack("L<x4L<x4", $SERVE_MAGIC_1, $clientVersion))
+          or die;
+        $magic = readInt($from);
+    };
 
-      open my $instantiate, "-|", "nix-instantiate", @ARGV
-        or die "Failed to run nix-instantiate";
-      my $to_realize = join "", <$instantiate>;
-      close $instantiate or exit $? >> 8;
+    die "unable to connect to taalo\n" if $@;
+    die "did not get valid handshake from taalo\n" if $magic != 0x5452eecb;
 
-      chomp $to_realize;
+    my $serverVersion = readInt($from);
+    die "unsupported server version\n"
+      if $serverVersion < 0x200 || $serverVersion >= 0x300;
 
-      my ($from, $to);
-      my $dest = 'nix-remote-build@taalo.headcounter.org';
-      my $cmd = "exec ssh $dest -C -- nix-store --serve --write";
-      my $pid = open2($from, $to, $cmd);
+    Nix::CopyClosure::copyToOpen(
+      $from, $to, "taalo", \@ARGV, 0, 0, 0, 1
+    );
 
-      # Do the handshake.
-      my $magic;
-      eval {
-          my $SERVE_MAGIC_1 = 0x390c9deb; # FIXME
-          my $clientVersion = 0x200;
-          syswrite($to, pack("L<x4L<x4", $SERVE_MAGIC_1, $clientVersion))
-            or die;
-          $magic = readInt($from);
-      };
+    writeInt(6, $to) or die;
+    writeStrings(\@ARGV, $to);
+    writeInt(0, $to);
+    writeInt(0, $to);
 
-      die "unable to connect to taalo\n" if $@;
-      die "did not get valid handshake from taalo\n" if $magic != 0x5452eecb;
+    my $res = readInt($from);
 
-      my $serverVersion = readInt($from);
-      die "unsupported server version\n"
-        if $serverVersion < 0x200 || $serverVersion >= 0x300;
+    close $to;
 
-      Nix::CopyClosure::copyToOpen(
-        $from, $to, "taalo", [$to_realize], 0, 0, 0, 1
-      );
+    waitpid($pid, 0);
+    exit $res;
+  '';
 
-      writeInt(6, $to) or die;
-      writeStrings([$to_realize], $to);
-      writeInt(0, $to);
-      writeInt(0, $to);
+  taalo-realize = pkgs.writeScriptBin "taalo-realize" ''
+    #!${pkgs.stdenv.shell}
+    if [ $# -le 0 -o "$1" = "--help" -o "$1" = "-h" ]; then
+      echo "Usage: $0 DERIVATION..." >&2
+      exit 1
+    fi
 
-      my $res = readInt($from);
+    exec ${backend} "$@"
+  '';
 
-      close $to;
+  taalo-build = pkgs.writeScriptBin "taalo-build" ''
+    #!${pkgs.stdenv.shell}
+    drvs="$(nix-instantiate "$@")" || exit 1
+    exec ${backend} $drvs
+  '';
 
-      waitpid($pid, 0);
-      exit $res;
-    '');
+in {
+  options.vuizvui.user.aszlig.programs.taalo-build = {
+    enable = lib.mkEnableOption "aszlig's build helpers for remote builds";
+  };
+  config = lib.mkIf config.vuizvui.user.aszlig.programs.taalo-build.enable {
+    environment.systemPackages = [ taalo-realize taalo-build ];
   };
 }