From 3ec88541b2526ca4ca96b3105660ba1d1a77c985 Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Fri, 28 Nov 2008 16:13:06 +0000
Subject: [PATCH] * Nix expression for building Hydra.

---
 release.nix                            | 76 ++++++++++++++++++++++++++
 src/Hydra/script/hydra_build.pl        |  2 +-
 src/Hydra/script/hydra_queue_runner.pl |  4 +-
 src/Hydra/script/hydra_scheduler.pl    |  2 +-
 4 files changed, 80 insertions(+), 4 deletions(-)
 create mode 100644 release.nix
 mode change 100644 => 100755 src/Hydra/script/hydra_build.pl
 mode change 100644 => 100755 src/Hydra/script/hydra_queue_runner.pl
 mode change 100644 => 100755 src/Hydra/script/hydra_scheduler.pl

diff --git a/release.nix b/release.nix
new file mode 100644
index 00000000..bd443898
--- /dev/null
+++ b/release.nix
@@ -0,0 +1,76 @@
+let
+
+
+  jobs = rec {
+
+
+    tarball =
+      { hydraSrc ? {path = ./.; rev = 1234;}
+      , nixpkgs ? {path = ../nixpkgs;}
+      , officialRelease ? false
+      }:
+
+      with import nixpkgs.path {};
+
+      releaseTools.makeSourceTarball {
+        name = "hydra-tarball";
+        src = hydraSrc;
+        inherit officialRelease;
+
+        # Since we don't have a `make dist', just tar everything.
+        distPhase = ''
+          releaseName=hydra-0.1$VERSION_SUFFIX;
+          ensureDir $out/tarballs
+          mkdir ../$releaseName
+          cp -prd . ../$releaseName
+          cd ..
+          tar cfj $out/tarballs/$releaseName.tar.bz2 $releaseName
+          tar cfz $out/tarballs/$releaseName.tar.gz $releaseName
+        '';
+      };
+
+
+    build = 
+      { tarball ? {path = jobs.tarball {};}
+      , nixpkgs ? {path = ../nixpkgs;}
+      , system ? "i686-linux"
+      }:
+
+      with import nixpkgs.path {inherit system;};
+
+      stdenvNew.mkDerivation {
+        name = "hydra-build";
+
+        buildInputs = [
+          perl makeWrapper
+          perlCatalystDevel
+          perlCatalystPluginAuthenticationStoreDBIC
+          perlCatalystPluginSessionStoreFastMmap
+          perlCatalystPluginStackTrace
+          perlCatalystPluginAuthenticationStoreDBIxClass
+          perlCatalystViewTT
+        ];
+
+        preUnpack = ''
+          src=$(ls ${tarball.path}/tarballs/*.tar.bz2)
+        ''; # */
+
+        installPhase = ''
+          ensureDir $out/libexec
+          cp -prd src/Hydra $out/libexec/hydra
+
+          mv $out/libexec/hydra/script $out/bin
+
+          for i in $out/bin/*; do
+              wrapProgram $i \
+                  --prefix PERL5LIB ':' $out/libexec/hydra/lib:$PERL5LIB \
+                  --prefix PATH ':' $out/bin \
+                  --set HYDRA_HOME $out/libexec/hydra
+          done
+        ''; # */
+      };
+
+  };
+
+
+in jobs
diff --git a/src/Hydra/script/hydra_build.pl b/src/Hydra/script/hydra_build.pl
old mode 100644
new mode 100755
index 0a13239b..1da02970
--- a/src/Hydra/script/hydra_build.pl
+++ b/src/Hydra/script/hydra_build.pl
@@ -1,4 +1,4 @@
-#! @perl@ -w
+#! /var/run/current-system/sw/bin/perl -w
 
 use strict;
 use File::Basename;
diff --git a/src/Hydra/script/hydra_queue_runner.pl b/src/Hydra/script/hydra_queue_runner.pl
old mode 100644
new mode 100755
index 429ff109..43b1e6cf
--- a/src/Hydra/script/hydra_queue_runner.pl
+++ b/src/Hydra/script/hydra_queue_runner.pl
@@ -1,4 +1,4 @@
-#! @perl@ -w
+#! /var/run/current-system/sw/bin/perl -w
 
 use strict;
 use Cwd;
@@ -100,7 +100,7 @@ sub checkBuilds {
                     open LOG, ">$logfile" or die "cannot create logfile $logfile";
                     POSIX::dup2(fileno(LOG), 1) or die;
                     POSIX::dup2(fileno(LOG), 2) or die;
-                    exec("perl", "-I$hydraHome/lib", "-w", "$ENV{'HYDRA_HOME'}/programs/Build.pl", $id);
+                    exec("hydra_build.pl", $id);
                 };
                 warn "cannot start build $id: $@";
                 POSIX::_exit(1);
diff --git a/src/Hydra/script/hydra_scheduler.pl b/src/Hydra/script/hydra_scheduler.pl
old mode 100644
new mode 100755
index 146df3b2..7f88aa94
--- a/src/Hydra/script/hydra_scheduler.pl
+++ b/src/Hydra/script/hydra_scheduler.pl
@@ -1,4 +1,4 @@
-#! @perl@ -w
+#! /var/run/current-system/sw/bin/perl -w
 
 use strict;
 use XML::Simple;