From 9013e9753416854d3ef4b7167229652914eda60f Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 19 Feb 2009 23:43:08 +0000 Subject: [PATCH] * Generate NAR archives on the fly. Necessary for producing channels / one-click installs on demand. --- src/Hydra/lib/Hydra/Controller/Root.pm | 15 ++++++++++++++- src/Hydra/lib/Hydra/View/NixClosure.pm | 1 - src/Hydra/lib/Hydra/View/NixManifest.pm | 6 +++--- src/Hydra/lib/Hydra/View/NixNAR.pm | 25 +++++++++++++++++++++++++ 4 files changed, 42 insertions(+), 5 deletions(-) create mode 100644 src/Hydra/lib/Hydra/View/NixNAR.pm diff --git a/src/Hydra/lib/Hydra/Controller/Root.pm b/src/Hydra/lib/Hydra/Controller/Root.pm index a5b2fcaa..cd903dd3 100644 --- a/src/Hydra/lib/Hydra/Controller/Root.pm +++ b/src/Hydra/lib/Hydra/Controller/Root.pm @@ -712,12 +712,25 @@ sub manifest :Local { my $build = getBuild($c, $buildId); return error($c, "Build with ID $buildId doesn't exist.") if !defined $build; - + return error($c, "Path " . $build->outpath . " is no longer available.") unless isValidPath($build->outpath); + $c->stash->{current_view} = 'Hydra::View::NixManifest'; $c->stash->{storePath} = $build->outpath; } +sub nar :Local { + my ($self, $c, @rest) = @_; + + my $path .= "/" . join("/", @rest); + + return error($c, "Path " . $path . " is no longer available.") unless isValidPath($path); + + $c->stash->{current_view} = 'Hydra::View::NixNAR'; + $c->stash->{storePath} = $path; +} + + sub end : ActionClass('RenderView') {} diff --git a/src/Hydra/lib/Hydra/View/NixClosure.pm b/src/Hydra/lib/Hydra/View/NixClosure.pm index 7b49057c..3d69d7ee 100644 --- a/src/Hydra/lib/Hydra/View/NixClosure.pm +++ b/src/Hydra/lib/Hydra/View/NixClosure.pm @@ -3,7 +3,6 @@ package Hydra::View::NixClosure; use strict; use base qw/Catalyst::View/; use IO::Pipe; -use POSIX qw(dup2); sub process { my ( $self, $c ) = @_; diff --git a/src/Hydra/lib/Hydra/View/NixManifest.pm b/src/Hydra/lib/Hydra/View/NixManifest.pm index 7f41953b..6796470f 100644 --- a/src/Hydra/lib/Hydra/View/NixManifest.pm +++ b/src/Hydra/lib/Hydra/View/NixManifest.pm @@ -12,7 +12,7 @@ sub captureStdoutStderr { return ($res, $stdout, $stderr); } - + sub process { my ($self, $c) = @_; @@ -41,10 +41,10 @@ sub process { $manifest .= "{\n" . - " StorePath: $path\n" . + " StorePath: ${path}y\n" . " NarURL: $url\n" . " References: @refs\n" . - " Hash: $hash\n" . + " NarHash: $hash\n" . "}\n"; } diff --git a/src/Hydra/lib/Hydra/View/NixNAR.pm b/src/Hydra/lib/Hydra/View/NixNAR.pm new file mode 100644 index 00000000..4022431d --- /dev/null +++ b/src/Hydra/lib/Hydra/View/NixNAR.pm @@ -0,0 +1,25 @@ +package Hydra::View::NixNAR; + +use strict; +use base qw/Catalyst::View/; + +sub process { + my ($self, $c) = @_; + + my $storePath = $c->stash->{storePath}; + + $c->response->content_type('application/x-nix-archive'); # !!! check MIME type + + open(OUTPUT, "nix-store --dump '$storePath' | bzip2 |"); + + my $fh = new IO::Handle; + $fh->fdopen(fileno(OUTPUT), "r") or die; + + $c->response->body($fh); + + undef $fh; + + return 1; +} + +1;