diff --git a/mirror-nixos-branch.pl b/mirror-nixos-branch.pl index 18e318c..122969e 100755 --- a/mirror-nixos-branch.pl +++ b/mirror-nixos-branch.pl @@ -50,31 +50,37 @@ my $TMPDIR = $ENV{'TMPDIR'} // "/tmp"; my $filesCache = "${TMPDIR}/nixos-files.sqlite"; my $bucketReleasesName = "nix-releases"; my $bucketChannelsName = "nix-channels"; +my $dryRun = $ENV{'DRY_RUN'} // 0; $ENV{'GIT_DIR'} = "/home/hydra-mirror/nixpkgs-channels"; +my $bucketReleases; +my $bucketChannels; -# S3 setup. -my $aws_access_key_id = $ENV{'AWS_ACCESS_KEY_ID'} or die; -my $aws_secret_access_key = $ENV{'AWS_SECRET_ACCESS_KEY'} or die; +unless ($dryRun) { + # 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 $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 $bucketReleases = $s3->bucket($bucketReleasesName) or die; + $bucketReleases = $s3->bucket($bucketReleasesName) 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, - }); - -my $bucketChannels = $s3_us->bucket($bucketChannelsName) 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, + }); + $bucketChannels = $s3_us->bucket($bucketChannelsName) or die; +} else { + print STDERR "WARNING: Running in dry-run.\n"; +} sub fetch { my ($url, $type) = @_; @@ -103,25 +109,27 @@ my $rev = $evalInfo->{jobsetevalinputs}->{nixpkgs}->{revision} or die; print STDERR "release is $releaseName (build $releaseId), eval is $evalId, prefix is $releasePrefix, Git commit is $rev\n"; -# Guard against the channel going back in time. -my $curRelease = $bucketChannels->get_key($channelName)->{'x-amz-website-redirect-location'} // ""; -if (!defined $ENV{'FORCE'}) { - print STDERR "previous release is $curRelease\n"; - $! = 0; # Clear errno to avoid reporting non-fork/exec-related issues - my $d = `NIX_PATH= nix-instantiate --eval -E "builtins.compareVersions (builtins.parseDrvName \\"$curRelease\\").version (builtins.parseDrvName \\"$releaseName\\").version"`; - if ($? != 0) { - warn "Could not execute nix-instantiate: exit $?; errno $!\n"; - exit 1; +if ($bucketChannels) { + # Guard against the channel going back in time. + my $curRelease = $bucketChannels->get_key($channelName)->{'x-amz-website-redirect-location'} // ""; + if (!defined $ENV{'FORCE'}) { + print STDERR "previous release is $curRelease\n"; + $! = 0; # Clear errno to avoid reporting non-fork/exec-related issues + my $d = `NIX_PATH= nix-instantiate --eval -E "builtins.compareVersions (builtins.parseDrvName \\"$curRelease\\").version (builtins.parseDrvName \\"$releaseName\\").version"`; + if ($? != 0) { + warn "Could not execute nix-instantiate: exit $?; errno $!\n"; + exit 1; + } + chomp $d; + if ($d == 1) { + warn("channel would go back in time from $curRelease to $releaseName, bailing out\n"); + exit; + } + exit if $d == 0; } - chomp $d; - if ($d == 1) { - warn("channel would go back in time from $curRelease to $releaseName, bailing out\n"); - exit; - } - exit if $d == 0; } -if ($bucketReleases->head_key("$releasePrefix")) { +if ($bucketReleases && $bucketReleases->head_key("$releasePrefix")) { print STDERR "release already exists\n"; } else { my $tmpDir = "$TMPDIR/release-$channelName/$releaseName"; @@ -217,39 +225,46 @@ if ($bucketReleases->head_key("$releasePrefix")) { $html .= "via Hydra evaluation $evalId.
"; $html .= "File name | Size | SHA-256 hash |
---|---|---|
$basename | "; + $html .= "$size | "; + $html .= "$sha256 | "; + $html .= "