forked from lix-project/hydra
* Generate manifests on demand. Next step: generate NAR archives on
demand, then we can have channel support and one-click installs in Hydra.
This commit is contained in:
parent
95f2362c11
commit
5a49cc5916
|
@ -707,6 +707,17 @@ sub closure :Local {
|
|||
}
|
||||
|
||||
|
||||
sub manifest :Local {
|
||||
my ($self, $c, $buildId) = @_;
|
||||
|
||||
my $build = getBuild($c, $buildId);
|
||||
return error($c, "Build with ID $buildId doesn't exist.") if !defined $build;
|
||||
|
||||
$c->stash->{current_view} = 'Hydra::View::NixManifest';
|
||||
$c->stash->{storePath} = $build->outpath;
|
||||
}
|
||||
|
||||
|
||||
sub end : ActionClass('RenderView') {}
|
||||
|
||||
|
||||
|
|
56
src/Hydra/lib/Hydra/View/NixManifest.pm
Normal file
56
src/Hydra/lib/Hydra/View/NixManifest.pm
Normal file
|
@ -0,0 +1,56 @@
|
|||
package Hydra::View::NixManifest;
|
||||
|
||||
use strict;
|
||||
use base qw/Catalyst::View/;
|
||||
use IO::Pipe;
|
||||
use IPC::Run;
|
||||
use POSIX qw(dup2);
|
||||
|
||||
sub captureStdoutStderr {
|
||||
my $stdin = ""; my $stdout; my $stderr;
|
||||
my $res = IPC::Run::run(\@_, \$stdin, \$stdout, \$stderr);
|
||||
return ($res, $stdout, $stderr);
|
||||
}
|
||||
|
||||
|
||||
sub process {
|
||||
my ($self, $c) = @_;
|
||||
|
||||
my $storePath = $c->stash->{storePath};
|
||||
|
||||
$c->response->content_type('text/x-nix-manifest');
|
||||
|
||||
my @paths = split '\n', `nix-store --query --requisites $storePath`
|
||||
or die "cannot query dependencies of `$storePath': $?";
|
||||
|
||||
my $manifest =
|
||||
"version {\n" .
|
||||
" ManifestVersion: 3\n" .
|
||||
"}\n";
|
||||
|
||||
foreach my $path (@paths) {
|
||||
my ($res, $out, $err) = captureStdoutStderr(qw(nix-store --query --references), $path);
|
||||
die "cannot query references of `$path':\n$err" unless $res;
|
||||
my @refs = split '\n', $out;
|
||||
|
||||
my $hash = `nix-store --query --hash $path`
|
||||
or die "cannot query hash of `$path': $?";
|
||||
chomp $hash;
|
||||
|
||||
my $url = $c->uri_for('/nar' . $path);
|
||||
|
||||
$manifest .=
|
||||
"{\n" .
|
||||
" StorePath: $path\n" .
|
||||
" NarURL: $url\n" .
|
||||
" References: @refs\n" .
|
||||
" Hash: $hash\n" .
|
||||
"}\n";
|
||||
}
|
||||
|
||||
$c->response->body($manifest);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
1;
|
Loading…
Reference in a new issue