2009-02-13 17:35:54 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-02-19 23:43:08 +00:00
|
|
|
|
2009-02-13 17:35:54 +00:00
|
|
|
sub process {
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
2009-02-25 14:34:29 +00:00
|
|
|
my @storePaths = @{$c->stash->{storePaths}};
|
2009-02-13 17:35:54 +00:00
|
|
|
|
|
|
|
$c->response->content_type('text/x-nix-manifest');
|
|
|
|
|
2009-02-25 14:34:29 +00:00
|
|
|
my @paths = split '\n', `nix-store --query --requisites @storePaths`
|
|
|
|
or die "cannot query dependencies of path(s) @storePaths: $?";
|
2009-02-13 17:35:54 +00:00
|
|
|
|
|
|
|
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);
|
2009-02-23 13:23:55 +00:00
|
|
|
|
|
|
|
my $deriver = `nix-store --query --deriver $path`
|
|
|
|
or die "cannot query deriver of `$path': $?";
|
|
|
|
chomp $deriver;
|
2009-02-13 17:35:54 +00:00
|
|
|
|
|
|
|
$manifest .=
|
|
|
|
"{\n" .
|
2009-02-23 13:23:55 +00:00
|
|
|
" StorePath: $path\n" .
|
|
|
|
(scalar @refs > 0 ? " References: @refs\n" : "") .
|
|
|
|
($deriver ne "unknown-deriver" ? " Deriver: $deriver\n" : "") .
|
2009-02-13 17:35:54 +00:00
|
|
|
" NarURL: $url\n" .
|
2009-02-19 23:43:08 +00:00
|
|
|
" NarHash: $hash\n" .
|
2009-02-13 17:35:54 +00:00
|
|
|
"}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->response->body($manifest);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
1;
|