-
-
Notifications
You must be signed in to change notification settings - Fork 304
/
NixExprs.pm
114 lines (92 loc) · 3.48 KB
/
NixExprs.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package Hydra::View::NixExprs;
use strict;
use warnings;
use base qw/Catalyst::View/;
use Hydra::Helper::Nix;
use Hydra::Helper::Escape;
use Hydra::Helper::AttributeSet;
use Archive::Tar;
use IO::Compress::Bzip2 qw(bzip2);
use Encode;
use Data::Dumper;
sub process {
my ($self, $c) = @_;
my %perSystem;
foreach my $pkg (@{$c->stash->{nixPkgs}}) {
my $build = $pkg->{build};
$perSystem{$build->system}->{$build->get_column('job')} = $pkg;
}
my $res = <<EOF;
{ system ? builtins.currentSystem }:
let
maybeStorePath = if builtins ? langVersion && builtins.lessThan 1 builtins.langVersion
then builtins.storePath
else x: x;
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 = maybeStorePath (builtins.getAttr outputName outputs);
};
};
outputsList = map outputToAttrListElement outputNames;
outputsSet = builtins.listToAttrs outputsList;
in outputsSet;
in
EOF
my $first = 1;
foreach my $system (keys %perSystem) {
$res .= "else " if !$first;
$res .= "if system == ${\escapeString $system} then {\n\n";
my $attrsets = Hydra::Helper::AttributeSet->new();
foreach my $job (keys %{$perSystem{$system}}) {
my $pkg = $perSystem{$system}->{$job};
my $build = $pkg->{build};
my $attr = $build->get_column('job');
$attrsets->registerValue($attr);
$res .= " # Hydra build ${\$build->id}\n";
$res .= " ${\escapeAttributePath $attr} = (mkFakeDerivation {\n";
$res .= " type = \"derivation\";\n";
$res .= " name = ${\escapeString ($build->get_column('releasename') or $build->nixname)};\n";
$res .= " system = ${\escapeString $build->system};\n";
$res .= " meta = {\n";
$res .= " description = ${\escapeString $build->description};\n"
if $build->description;
$res .= " license = ${\escapeString $build->license};\n"
if $build->license;
$res .= " maintainers = ${\escapeString $build->maintainers};\n"
if $build->maintainers;
$res .= " };\n";
$res .= " } {\n";
my @outputNames = sort (keys %{$pkg->{outputs}});
$res .= " ${\escapeString $_} = ${\escapeString $pkg->{outputs}->{$_}};\n" foreach @outputNames;
my $out = defined $pkg->{outputs}->{"out"} ? "out" : $outputNames[0];
$res .= " }).$out;\n\n";
}
for my $attrset ($attrsets->enumerate()) {
$res .= " ${\escapeAttributePath $attrset}.recurseForDerivations = true;\n\n";
}
$res .= "}\n\n";
$first = 0;
}
$res .= "else " if !$first;
$res .= "{}\n";
my $tar = Archive::Tar->new;
$tar->add_data("channel/channel-name", ($c->stash->{channelName} or "unnamed-channel"), {mtime => 1});
$tar->add_data("channel/default.nix", encode('utf8',$res), {mtime => 1});
my $tardata = $tar->write;
my $bzip2data;
bzip2(\$tardata => \$bzip2data);
$c->response->content_type('application/x-bzip2');
$c->response->body($bzip2data);
return 1;
}
1;