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);
|
2017-04-01 04:18:51 -05:00
|
|
|
use Encode;
|
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 17:06:17 +02:00
|
|
|
$perSystem{$build->system}->{$build->get_column('job')} = $pkg;
|
2009-03-02 17:17:36 +00:00
|
|
|
}
|
|
|
|
|
2013-10-07 17:06:17 +02:00
|
|
|
my $res = <<EOF;
|
|
|
|
{ system ? builtins.currentSystem }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
mkFakeDerivation = attrs: outputs:
|
|
|
|
let
|
|
|
|
outputNames = builtins.attrNames outputs;
|
|
|
|
common = attrs // outputsSet //
|
|
|
|
{ type = "derivation";
|
|
|
|
outputs = outputNames;
|
|
|
|
all = outputsList;
|
|
|
|
};
|
|
|
|
outputToAttrListElement = outputName:
|
|
|
|
{ name = outputName;
|
|
|
|
value = common // {
|
|
|
|
inherit outputName;
|
|
|
|
outPath = builtins.getAttr outputName outputs;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
outputsList = map outputToAttrListElement outputNames;
|
|
|
|
outputsSet = builtins.listToAttrs outputsList;
|
|
|
|
in outputsSet;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
EOF
|
2013-10-07 14:53:27 +02:00
|
|
|
|
|
|
|
my $first = 1;
|
|
|
|
foreach my $system (keys %perSystem) {
|
|
|
|
$res .= "else " if !$first;
|
|
|
|
$res .= "if system == ${\escape $system} then {\n\n";
|
2013-10-07 17:06:17 +02:00
|
|
|
|
2014-11-25 00:27:52 +01:00
|
|
|
foreach my $job (keys %{$perSystem{$system}}) {
|
2013-10-07 17:06:17 +02:00
|
|
|
my $pkg = $perSystem{$system}->{$job};
|
|
|
|
my $build = $pkg->{build};
|
|
|
|
$res .= " # Hydra build ${\$build->id}\n";
|
|
|
|
my $attr = $build->get_column('job');
|
|
|
|
$attr =~ s/\./-/g;
|
|
|
|
$res .= " ${\escape $attr} = (mkFakeDerivation {\n";
|
|
|
|
$res .= " type = \"derivation\";\n";
|
|
|
|
$res .= " name = ${\escape ($build->get_column('releasename') or $build->nixname)};\n";
|
|
|
|
$res .= " system = ${\escape $build->system};\n";
|
|
|
|
$res .= " meta = {\n";
|
|
|
|
$res .= " description = ${\escape $build->description};\n"
|
|
|
|
if $build->description;
|
|
|
|
$res .= " license = ${\escape $build->license};\n"
|
|
|
|
if $build->license;
|
|
|
|
$res .= " maintainers = ${\escape $build->maintainers};\n"
|
|
|
|
if $build->maintainers;
|
|
|
|
$res .= " };\n";
|
|
|
|
$res .= " } {\n";
|
2014-11-25 00:27:52 +01:00
|
|
|
my @outputNames = sort (keys %{$pkg->{outputs}});
|
2013-10-07 17:06:17 +02:00
|
|
|
$res .= " ${\escape $_} = ${\escape $pkg->{outputs}->{$_}};\n" foreach @outputNames;
|
|
|
|
my $out = defined $pkg->{outputs}->{"out"} ? "out" : $outputNames[0];
|
|
|
|
$res .= " }).$out;\n\n";
|
|
|
|
}
|
|
|
|
|
2013-10-07 14:53:27 +02:00
|
|
|
$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});
|
2017-04-01 04:18:51 -05:00
|
|
|
$tar->add_data("channel/default.nix", encode('utf8',$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;
|