From c613b885f2a741f892dc1ad547218bb608aa6fdb Mon Sep 17 00:00:00 2001
From: Eelco Dolstra <e.dolstra@tudelft.nl>
Date: Wed, 30 Nov 2011 15:25:28 +0100
Subject: [PATCH] Use the new Nix Perl bindings

---
 deps.nix                               | 2 +-
 src/lib/Hydra/Controller/Build.pm      | 4 ++--
 src/lib/Hydra/Helper/AddBuilds.pm      | 1 +
 src/lib/Hydra/Helper/CatalystUtils.pm  | 5 +++--
 src/lib/Hydra/Helper/Nix.pm            | 8 --------
 src/lib/Hydra/View/NixManifest.pm      | 6 +++---
 src/script/hydra_queue_runner.pl.in    | 2 +-
 src/script/hydra_update_gc_roots.pl.in | 1 +
 8 files changed, 12 insertions(+), 17 deletions(-)

diff --git a/deps.nix b/deps.nix
index a1157d00..18c1f1d3 100644
--- a/deps.nix
+++ b/deps.nix
@@ -33,5 +33,5 @@ with pkgs;
   perlPackages.TestMore
   perlPackages.SysHostnameLong
   perlPackages.Starman
-  perlPackages.nixPerl
+  nixUnstable
 ]
diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm
index c799d0c0..226e9724 100644
--- a/src/lib/Hydra/Controller/Build.pm
+++ b/src/lib/Hydra/Controller/Build.pm
@@ -8,7 +8,7 @@ use Hydra::Helper::CatalystUtils;
 use Hydra::Helper::AddBuilds;
 use File::stat;
 use Data::Dump qw(dump);
-use Nix;
+use Nix::Store;
 
 
 sub build : Chained('/') PathPart CaptureArgs(1) {
@@ -41,7 +41,7 @@ sub view_build : Chained('build') PathPart('') Args(0) {
     $c->stash->{drvAvailable} = isValidPath $build->drvpath;
     $c->stash->{flashMsg} = $c->flash->{buildMsg};
 
-    my $pathHash = $c->stash->{available} ? Nix::queryPathHash($build->outpath) : "Not available";
+    my $pathHash = $c->stash->{available} ? queryPathHash($build->outpath) : "Not available";
     $c->stash->{pathHash} = $pathHash;
 
     if (!$build->finished && $build->schedulingInfo->busy) {
diff --git a/src/lib/Hydra/Helper/AddBuilds.pm b/src/lib/Hydra/Helper/AddBuilds.pm
index 7bf587d8..df74b8ab 100644
--- a/src/lib/Hydra/Helper/AddBuilds.pm
+++ b/src/lib/Hydra/Helper/AddBuilds.pm
@@ -5,6 +5,7 @@ use feature 'switch';
 use XML::Simple;
 use POSIX qw(strftime);
 use IPC::Run;
+use Nix::Store;
 use Hydra::Helper::Nix;
 use Digest::SHA qw(sha256_hex);
 use File::Basename;
diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm
index 154dbf4e..2379386d 100644
--- a/src/lib/Hydra/Helper/CatalystUtils.pm
+++ b/src/lib/Hydra/Helper/CatalystUtils.pm
@@ -3,6 +3,7 @@ package Hydra::Helper::CatalystUtils;
 use strict;
 use Exporter;
 use Readonly;
+use Nix::Store;
 use Hydra::Helper::Nix;
 
 our @ISA = qw(Exporter);
@@ -117,8 +118,8 @@ sub getChannelData {
     
     my @storePaths = ();
     foreach my $build (@builds2) {
-        next unless Hydra::Helper::Nix::isValidPath($build->outpath);
-        if (Hydra::Helper::Nix::isValidPath($build->drvpath)) {
+        next unless isValidPath($build->outpath);
+        if (isValidPath($build->drvpath)) {
             # Adding `drvpath' implies adding `outpath' because of the
             # `--include-outputs' flag passed to `nix-store'.
             push @storePaths, $build->drvpath;
diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm
index 6e711408..d230bce3 100644
--- a/src/lib/Hydra/Helper/Nix.pm
+++ b/src/lib/Hydra/Helper/Nix.pm
@@ -4,12 +4,10 @@ use strict;
 use Exporter;
 use File::Path;
 use File::Basename;
-use Nix;
 use Hydra::Helper::CatalystUtils;
 
 our @ISA = qw(Exporter);
 our @EXPORT = qw(
-    isValidPath
     getHydraPath getHydraDBPath openHydraDB getHydraConf txn_do
     registerRoot getGCRootsDir gcRootFor
     getPrimaryBuildsForView
@@ -17,12 +15,6 @@ our @EXPORT = qw(
     getViewResult getLatestSuccessfulViewResult jobsetOverview removeAsciiEscapes);
 
 
-sub isValidPath {
-    my $path = shift;
-    return Nix::isValidPath($path);
-}
-
-
 sub getHydraPath {
     my $dir = $ENV{"HYDRA_DATA"} || "/var/lib/hydra";
     die "The HYDRA_DATA directory ($dir) does not exist!\n" unless -d $dir;
diff --git a/src/lib/Hydra/View/NixManifest.pm b/src/lib/Hydra/View/NixManifest.pm
index 94301119..466fd28d 100644
--- a/src/lib/Hydra/View/NixManifest.pm
+++ b/src/lib/Hydra/View/NixManifest.pm
@@ -3,7 +3,7 @@ package Hydra::View::NixManifest;
 use strict;
 use base qw/Catalyst::View/;
 use Hydra::Helper::Nix;
-use Nix;
+use Nix::Store;
 
 
 sub process {
@@ -13,7 +13,7 @@ sub process {
     
     $c->response->content_type('text/x-nix-manifest');
 
-    my @paths = Nix::computeFSClosure(0, 1, @storePaths);
+    my @paths = computeFSClosure(0, 1, @storePaths);
 
     my $manifest =
         "version {\n" .
@@ -21,7 +21,7 @@ sub process {
         "}\n";
     
     foreach my $path (@paths) {
-        my ($deriver, $hash, $time, $narSize, $refs) = Nix::queryPathInfo $path;
+        my ($deriver, $hash, $time, $narSize, $refs) = queryPathInfo $path;
 
         # Escape the characters that are allowed to appear in a Nix
         # path name but have special meaning in a URI.
diff --git a/src/script/hydra_queue_runner.pl.in b/src/script/hydra_queue_runner.pl.in
index 39cdc347..a4a6c45d 100755
--- a/src/script/hydra_queue_runner.pl.in
+++ b/src/script/hydra_queue_runner.pl.in
@@ -7,7 +7,7 @@ use POSIX qw(dup2 :sys_wait_h);
 use Hydra::Schema;
 use Hydra::Helper::Nix;
 use IO::Handle;
-use Nix;
+use Nix::Store;
 
 chdir getHydraPath or die;
 my $db = openHydraDB;
diff --git a/src/script/hydra_update_gc_roots.pl.in b/src/script/hydra_update_gc_roots.pl.in
index ef049b89..25572ac7 100755
--- a/src/script/hydra_update_gc_roots.pl.in
+++ b/src/script/hydra_update_gc_roots.pl.in
@@ -3,6 +3,7 @@
 use strict;
 use File::Path;
 use File::Basename;
+use Nix::Store;
 use Hydra::Schema;
 use Hydra::Helper::Nix;
 use POSIX qw(strftime);