2009-03-02 17:17:36 +00:00
|
|
|
package Hydra::View::NixExprs;
|
|
|
|
|
|
|
|
use strict;
|
|
|
|
use base qw/Catalyst::View/;
|
|
|
|
use Hydra::Helper::Nix;
|
2009-03-03 10:44:54 +00:00
|
|
|
use Archive::Tar;
|
|
|
|
use IO::Compress::Bzip2 qw(bzip2);
|
2009-03-02 17:17:36 +00:00
|
|
|
|
|
|
|
|
2009-03-03 09:37:16 +00:00
|
|
|
sub escape {
|
|
|
|
my ($s) = @_;
|
|
|
|
$s =~ s|\\|\\\\|g;
|
|
|
|
$s =~ s|\"|\\\"|g;
|
|
|
|
$s =~ s|\$|\\\$|g;
|
|
|
|
return "\"" . $s . "\"";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-03-02 17:17:36 +00:00
|
|
|
sub process {
|
|
|
|
my ($self, $c) = @_;
|
|
|
|
|
2013-10-07 14:53:27 +02:00
|
|
|
my %perSystem;
|
2009-03-02 17:17:36 +00:00
|
|
|
|
2013-02-13 16:49:28 +00:00
|
|
|
foreach my $pkg (@{$c->stash->{nixPkgs}}) {
|
|
|
|
my $build = $pkg->{build};
|
2013-10-07 14:53:27 +02:00
|
|
|
my $s = "";
|
|
|
|
$s .= " # $pkg->{name}\n";
|
|
|
|
$s .= " ${\escape $build->get_column('job')} = {\n";
|
|
|
|
$s .= " type = \"derivation\";\n";
|
|
|
|
$s .= " name = ${\escape ($build->get_column('releasename') or $build->nixname)};\n";
|
|
|
|
$s .= " system = ${\escape $build->system};\n";
|
|
|
|
$s .= " outPath = ${\escape $pkg->{outPath}};\n";
|
|
|
|
$s .= " meta = {\n";
|
|
|
|
$s .= " description = ${\escape $build->description};\n"
|
2009-03-02 17:17:36 +00:00
|
|
|
if $build->description;
|
2013-10-07 14:53:27 +02:00
|
|
|
$s .= " longDescription = ${\escape $build->longdescription};\n"
|
2009-03-02 17:17:36 +00:00
|
|
|
if $build->longdescription;
|
2013-10-07 14:53:27 +02:00
|
|
|
$s .= " license = ${\escape $build->license};\n"
|
2009-03-02 17:17:36 +00:00
|
|
|
if $build->license;
|
2013-10-07 14:53:27 +02:00
|
|
|
$s .= " maintainers = ${\escape $build->maintainers};\n"
|
|
|
|
if $build->maintainers;
|
|
|
|
$s .= " };\n";
|
|
|
|
$s .= " };\n\n";
|
|
|
|
$perSystem{$build->system} .= $s;
|
2009-03-02 17:17:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 14:53:27 +02:00
|
|
|
my $res = "{ system ? builtins.currentSystem }:\n\n";
|
|
|
|
|
|
|
|
my $first = 1;
|
|
|
|
foreach my $system (keys %perSystem) {
|
|
|
|
$res .= "else " if !$first;
|
|
|
|
$res .= "if system == ${\escape $system} then {\n\n";
|
|
|
|
$res .= $perSystem{$system};
|
|
|
|
$res .= "}\n\n";
|
|
|
|
$first = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$res .= "else " if !$first;
|
|
|
|
$res .= "{}\n";
|
2009-03-03 10:44:54 +00:00
|
|
|
|
|
|
|
my $tar = Archive::Tar->new;
|
2013-10-07 14:53:27 +02:00
|
|
|
$tar->add_data("channel/channel-name", ($c->stash->{channelName} or "unnamed-channel"), {mtime => 1});
|
|
|
|
$tar->add_data("channel/default.nix", $res, {mtime => 1});
|
2009-03-03 10:44:54 +00:00
|
|
|
|
|
|
|
my $tardata = $tar->write;
|
|
|
|
my $bzip2data;
|
|
|
|
bzip2(\$tardata => \$bzip2data);
|
|
|
|
|
|
|
|
$c->response->content_type('application/x-bzip2');
|
|
|
|
$c->response->body($bzip2data);
|
2009-03-02 17:17:36 +00:00
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
1;
|