hydra/src/lib/Hydra/View/NixManifest.pm

57 lines
1.4 KiB
Perl
Raw Normal View History

package Hydra::View::NixManifest;
use strict;
use base qw/Catalyst::View/;
2009-02-26 16:57:05 +00:00
use Hydra::Helper::Nix;
2010-03-04 14:15:13 +00:00
use Nix;
sub process {
my ($self, $c) = @_;
2009-02-25 14:34:29 +00:00
my @storePaths = @{$c->stash->{storePaths}};
$c->response->content_type('text/x-nix-manifest');
2010-03-04 14:15:13 +00:00
my @paths = Nix::computeFSClosure(0, 1, @storePaths);
my $manifest =
"version {\n" .
" ManifestVersion: 4\n" .
"}\n";
foreach my $path (@paths) {
my ($deriver, $hash, $time, $narSize, $refs) = Nix::queryPathInfo $path;
# Escape the characters that are allowed to appear in a Nix
# path name but have special meaning in a URI.
my $escaped = $path;
$escaped =~ s/^.*\///; # remove /nix/store/
$escaped =~ s/\+/%2b/g;
$escaped =~ s/\=/%3d/g;
$escaped =~ s/\?/%3f/g;
my $url = $c->stash->{narBase} . "/" . $escaped;
2009-02-23 13:23:55 +00:00
my $system = $c->stash->{systemForPath}->{$path};
$manifest .=
"{\n" .
2009-02-23 13:23:55 +00:00
" StorePath: $path\n" .
2009-02-26 16:57:05 +00:00
(scalar @{$refs} > 0 ? " References: @{$refs}\n" : "") .
(defined $deriver ? " Deriver: $deriver\n" : "") .
" NarURL: $url\n" .
" NarHash: $hash\n" .
($narSize != 0 ? " NarSize: $narSize\n" : "") .
(defined $system ? " System: $system\n" : "") .
"}\n";
}
$c->response->body($manifest);
return 1;
}
1;