2009-02-13 17:35:54 +00:00
|
|
|
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;
|
2009-02-13 17:35:54 +00:00
|
|
|
|
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}};
|
2013-01-22 14:41:02 +01:00
|
|
|
|
2009-02-13 17:35:54 +00:00
|
|
|
$c->response->content_type('text/x-nix-manifest');
|
|
|
|
|
2011-11-30 15:25:28 +01:00
|
|
|
my @paths = computeFSClosure(0, 1, @storePaths);
|
2009-02-13 17:35:54 +00:00
|
|
|
|
|
|
|
my $manifest =
|
|
|
|
"version {\n" .
|
2009-02-27 14:57:06 +00:00
|
|
|
" ManifestVersion: 4\n" .
|
2009-02-13 17:35:54 +00:00
|
|
|
"}\n";
|
2013-01-22 14:41:02 +01:00
|
|
|
|
2009-02-13 17:35:54 +00:00
|
|
|
foreach my $path (@paths) {
|
2015-02-19 12:44:52 +01:00
|
|
|
my ($deriver, $hash, $time, $narSize, $refs) = queryPathInfo($path, 1);
|
2010-02-09 16:11:35 +00:00
|
|
|
|
|
|
|
# Escape the characters that are allowed to appear in a Nix
|
|
|
|
# path name but have special meaning in a URI.
|
|
|
|
my $escaped = $path;
|
2010-06-22 12:00:19 +00:00
|
|
|
$escaped =~ s/^.*\///; # remove /nix/store/
|
2010-02-09 16:11:35 +00:00
|
|
|
$escaped =~ s/\+/%2b/g;
|
|
|
|
$escaped =~ s/\=/%3d/g;
|
|
|
|
$escaped =~ s/\?/%3f/g;
|
2013-01-22 14:41:02 +01:00
|
|
|
|
2010-06-22 12:00:19 +00:00
|
|
|
my $url = $c->stash->{narBase} . "/" . $escaped;
|
2009-02-23 13:23:55 +00:00
|
|
|
|
2010-11-26 14:34:58 +00:00
|
|
|
my $system = $c->stash->{systemForPath}->{$path};
|
|
|
|
|
2009-02-13 17:35:54 +00:00
|
|
|
$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" : "") .
|
2009-02-13 17:35:54 +00:00
|
|
|
" NarURL: $url\n" .
|
2009-02-19 23:43:08 +00:00
|
|
|
" NarHash: $hash\n" .
|
2010-11-19 15:44:20 +00:00
|
|
|
($narSize != 0 ? " NarSize: $narSize\n" : "") .
|
2010-11-26 14:34:58 +00:00
|
|
|
(defined $system ? " System: $system\n" : "") .
|
2009-02-13 17:35:54 +00:00
|
|
|
"}\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
$c->response->body($manifest);
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2010-02-09 12:35:20 +00:00
|
|
|
|
2009-02-13 17:35:54 +00:00
|
|
|
1;
|