2016-08-29 19:42:11 +00:00
|
|
|
#! /usr/bin/env nix-shell
|
2020-04-10 15:27:35 +00:00
|
|
|
#! nix-shell -i perl -p perl perlPackages.LWPUserAgent perlPackages.LWPProtocolHttps perlPackages.FileSlurp perlPackages.NetAmazonS3 gnupg1
|
2016-08-29 19:42:11 +00:00
|
|
|
|
|
|
|
use strict;
|
|
|
|
use Data::Dumper;
|
|
|
|
use File::Basename;
|
|
|
|
use File::Path;
|
|
|
|
use File::Slurp;
|
2018-02-22 16:11:17 +00:00
|
|
|
use File::Copy;
|
2016-08-29 19:42:11 +00:00
|
|
|
use JSON::PP;
|
|
|
|
use LWP::UserAgent;
|
2020-04-10 15:27:35 +00:00
|
|
|
use Net::Amazon::S3;
|
2016-08-29 19:42:11 +00:00
|
|
|
|
|
|
|
my $evalId = $ARGV[0] or die "Usage: $0 EVAL-ID\n";
|
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
my $releasesBucketName = "nix-releases";
|
|
|
|
my $channelsBucketName = "nix-channels";
|
2016-09-07 13:34:54 +00:00
|
|
|
my $nixpkgsDir = "/home/eelco/Dev/nixpkgs-pristine";
|
2016-08-29 19:42:11 +00:00
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
my $TMPDIR = $ENV{'TMPDIR'} // "/tmp";
|
|
|
|
|
2016-08-29 19:42:11 +00:00
|
|
|
# FIXME: cut&paste from nixos-channel-scripts.
|
|
|
|
sub fetch {
|
|
|
|
my ($url, $type) = @_;
|
|
|
|
|
|
|
|
my $ua = LWP::UserAgent->new;
|
|
|
|
$ua->default_header('Accept', $type) if defined $type;
|
|
|
|
|
|
|
|
my $response = $ua->get($url);
|
|
|
|
die "could not download $url: ", $response->status_line, "\n" unless $response->is_success;
|
|
|
|
|
|
|
|
return $response->decoded_content;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $evalUrl = "https://hydra.nixos.org/eval/$evalId";
|
|
|
|
my $evalInfo = decode_json(fetch($evalUrl, 'application/json'));
|
|
|
|
#print Dumper($evalInfo);
|
|
|
|
|
|
|
|
my $nixRev = $evalInfo->{jobsetevalinputs}->{nix}->{revision} or die;
|
|
|
|
|
|
|
|
my $tarballInfo = decode_json(fetch("$evalUrl/job/tarball", 'application/json'));
|
|
|
|
|
|
|
|
my $releaseName = $tarballInfo->{releasename};
|
|
|
|
$releaseName =~ /nix-(.*)$/ or die;
|
|
|
|
my $version = $1;
|
|
|
|
|
|
|
|
print STDERR "Nix revision is $nixRev, version is $version\n";
|
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
my $releaseDir = "nix/$releaseName";
|
|
|
|
|
|
|
|
my $tmpDir = "$TMPDIR/nix-release/$releaseName";
|
|
|
|
File::Path::make_path($tmpDir);
|
|
|
|
|
|
|
|
# S3 setup.
|
|
|
|
my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'} or die "No AWS_ACCESS_KEY_ID given.";
|
|
|
|
my $aws_secret_access_key = $ENV{'AWS_SECRET_ACCESS_KEY'} or die "No AWS_SECRET_ACCESS_KEY given.";
|
|
|
|
|
|
|
|
my $s3 = Net::Amazon::S3->new(
|
|
|
|
{ aws_access_key_id => $aws_access_key_id,
|
|
|
|
aws_secret_access_key => $aws_secret_access_key,
|
|
|
|
retry => 1,
|
|
|
|
host => "s3-eu-west-1.amazonaws.com",
|
|
|
|
});
|
|
|
|
|
|
|
|
my $releasesBucket = $s3->bucket($releasesBucketName) or die;
|
|
|
|
|
|
|
|
my $s3_us = Net::Amazon::S3->new(
|
|
|
|
{ aws_access_key_id => $aws_access_key_id,
|
|
|
|
aws_secret_access_key => $aws_secret_access_key,
|
|
|
|
retry => 1,
|
|
|
|
});
|
2016-08-29 19:42:11 +00:00
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
my $channelsBucket = $s3_us->bucket($channelsBucketName) or die;
|
2016-08-29 19:42:11 +00:00
|
|
|
|
|
|
|
sub downloadFile {
|
|
|
|
my ($jobName, $productNr, $dstName) = @_;
|
|
|
|
|
|
|
|
my $buildInfo = decode_json(fetch("$evalUrl/job/$jobName", 'application/json'));
|
|
|
|
|
2018-02-22 16:11:17 +00:00
|
|
|
my $srcFile = $buildInfo->{buildproducts}->{$productNr}->{path} or die "job '$jobName' lacks product $productNr\n";
|
2016-08-29 19:42:11 +00:00
|
|
|
$dstName //= basename($srcFile);
|
2020-04-10 15:27:35 +00:00
|
|
|
my $tmpFile = "$tmpDir/$dstName";
|
2016-08-29 19:42:11 +00:00
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
if (!-e $tmpFile) {
|
|
|
|
print STDERR "downloading $srcFile to $tmpFile...\n";
|
|
|
|
system("NIX_REMOTE=https://cache.nixos.org/ nix cat-store '$srcFile' > '$tmpFile'") == 0
|
2016-08-29 19:42:11 +00:00
|
|
|
or die "unable to fetch $srcFile\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
my $sha256_expected = $buildInfo->{buildproducts}->{$productNr}->{sha256hash} or die;
|
2020-04-10 15:27:35 +00:00
|
|
|
my $sha256_actual = `nix hash-file --base16 --type sha256 '$tmpFile'`;
|
2016-08-29 19:42:11 +00:00
|
|
|
chomp $sha256_actual;
|
|
|
|
if ($sha256_expected ne $sha256_actual) {
|
2020-04-10 15:27:35 +00:00
|
|
|
print STDERR "file $tmpFile is corrupt, got $sha256_actual, expected $sha256_expected\n";
|
2016-08-29 19:42:11 +00:00
|
|
|
exit 1;
|
|
|
|
}
|
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
write_file("$tmpFile.sha256", $sha256_expected);
|
2016-08-29 19:42:11 +00:00
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
if (! -e "$tmpFile.asc") {
|
|
|
|
system("gpg2 --detach-sign --armor $tmpFile") == 0 or die "unable to sign $tmpFile\n";
|
2018-05-31 09:54:32 +00:00
|
|
|
}
|
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
return $sha256_expected;
|
2016-08-29 19:42:11 +00:00
|
|
|
}
|
|
|
|
|
2018-02-22 16:11:17 +00:00
|
|
|
downloadFile("tarball", "2"); # .tar.bz2
|
2020-04-10 15:27:35 +00:00
|
|
|
my $tarballHash = downloadFile("tarball", "3"); # .tar.xz
|
2018-05-31 09:54:32 +00:00
|
|
|
downloadFile("binaryTarball.i686-linux", "1");
|
|
|
|
downloadFile("binaryTarball.x86_64-linux", "1");
|
|
|
|
downloadFile("binaryTarball.aarch64-linux", "1");
|
|
|
|
downloadFile("binaryTarball.x86_64-darwin", "1");
|
|
|
|
downloadFile("installerScript", "1");
|
2016-08-29 19:42:11 +00:00
|
|
|
|
2020-04-10 15:27:35 +00:00
|
|
|
for my $fn (glob "$tmpDir/*") {
|
|
|
|
my $name = basename($fn);
|
|
|
|
my $dstKey = "$releaseDir/" . $name;
|
|
|
|
unless (defined $releasesBucket->head_key($dstKey)) {
|
|
|
|
print STDERR "uploading $fn to s3://$releasesBucketName/$dstKey...\n";
|
2020-08-20 11:21:22 +00:00
|
|
|
|
|
|
|
my $configuration = ();
|
|
|
|
$configuration->{content_type} = "application/octet-stream";
|
|
|
|
|
|
|
|
if ($fn =~ /.sha256|.asc|install/) {
|
|
|
|
# Text files
|
|
|
|
$configuration->{content_type} = "text/plain";
|
|
|
|
}
|
|
|
|
|
|
|
|
$releasesBucket->add_key_filename($dstKey, $fn, $configuration)
|
2020-04-10 15:27:35 +00:00
|
|
|
or die $releasesBucket->err . ": " . $releasesBucket->errstr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-08-30 13:21:58 +00:00
|
|
|
exit if $version =~ /pre/;
|
|
|
|
|
2021-05-14 12:03:53 +00:00
|
|
|
# Update nix-fallback-paths.nix.
|
2017-01-03 10:42:56 +00:00
|
|
|
system("cd $nixpkgsDir && git pull") == 0 or die;
|
2016-09-07 13:34:54 +00:00
|
|
|
|
|
|
|
sub getStorePath {
|
|
|
|
my ($jobName) = @_;
|
|
|
|
my $buildInfo = decode_json(fetch("$evalUrl/job/$jobName", 'application/json'));
|
2020-06-03 12:57:24 +00:00
|
|
|
for my $product (values %{$buildInfo->{buildproducts}}) {
|
|
|
|
next unless $product->{type} eq "nix-build";
|
|
|
|
next if $product->{path} =~ /[a-z]+$/;
|
|
|
|
return $product->{path};
|
|
|
|
}
|
|
|
|
die;
|
2016-09-07 13:34:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
write_file("$nixpkgsDir/nixos/modules/installer/tools/nix-fallback-paths.nix",
|
|
|
|
"{\n" .
|
|
|
|
" x86_64-linux = \"" . getStorePath("build.x86_64-linux") . "\";\n" .
|
|
|
|
" i686-linux = \"" . getStorePath("build.i686-linux") . "\";\n" .
|
2017-12-08 00:02:35 +00:00
|
|
|
" aarch64-linux = \"" . getStorePath("build.aarch64-linux") . "\";\n" .
|
2016-09-07 13:34:54 +00:00
|
|
|
" x86_64-darwin = \"" . getStorePath("build.x86_64-darwin") . "\";\n" .
|
|
|
|
"}\n");
|
|
|
|
|
2021-05-14 12:03:53 +00:00
|
|
|
system("cd $nixpkgsDir && git commit -a -m 'nix-fallback-paths.nix: Update to $version'") == 0 or die;
|
2016-09-07 13:34:54 +00:00
|
|
|
|
2016-08-29 19:42:11 +00:00
|
|
|
# Update the "latest" symlink.
|
2020-04-10 15:27:35 +00:00
|
|
|
$channelsBucket->add_key(
|
|
|
|
"nix-latest/install", "",
|
|
|
|
{ "x-amz-website-redirect-location" => "https://releases.nixos.org/$releaseDir/install" })
|
|
|
|
or die $channelsBucket->err . ": " . $channelsBucket->errstr;
|
2016-08-29 19:42:11 +00:00
|
|
|
|
|
|
|
# Tag the release in Git.
|
|
|
|
chdir("/home/eelco/Dev/nix-pristine") or die;
|
|
|
|
system("git remote update origin") == 0 or die;
|
|
|
|
system("git tag --force --sign $version $nixRev -m 'Tagging release $version'") == 0 or die;
|
2020-07-08 15:01:20 +00:00
|
|
|
system("git push --tags") == 0 or die;
|
|
|
|
system("git push --force-with-lease origin $nixRev:refs/heads/latest-release") == 0 or die;
|