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;
2011-11-30 15:25:28 +01:00
use Nix::Store;
sub process {
my ($self, $c) = @_;
2009-02-25 14:34:29 +00:00
my @storePaths = @{$c->stash->{storePaths}};
2013-01-22 14:41:02 +01:00
$c->response->content_type('text/x-nix-manifest');
2011-11-30 15:25:28 +01:00
my @paths = computeFSClosure(0, 1, @storePaths);
my $manifest =
"version {\n" .
" ManifestVersion: 4\n" .
"}\n";
2013-01-22 14:41:02 +01:00
foreach my $path (@paths) {
my ($deriver, $hash, $time, $narSize, $refs) = queryPathInfo($path, 1);
# 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;
2013-01-22 14:41:02 +01:00
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;