Skip to content

Commit 24d0dc1

Browse files
authored
Merge pull request #76 from emilylange/lockable-tarball-flakes
mirror-nixos-branch: add header for "Lockable HTTP Tarball Protocol" (Flakes)
2 parents 6192f53 + 61651de commit 24d0dc1

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

mirror-nixos-branch.pl

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,16 +342,25 @@ sub fetch {
342342
my $cache_control = "maxage=600,stale-while-revalidate=1800,public";
343343

344344
sub redirect {
345-
my ($from, $to) = @_;
345+
my ($from, $to, $immutable_flake_tarball) = @_;
346346
$to = "https://releases.nixos.org/" . $to;
347347
print STDERR "redirect $from -> $to\n";
348-
$bucketChannels->add_key($from, "", { "x-amz-website-redirect-location" => $to, "cache-control" => $cache_control })
348+
my $object_metadata = { "x-amz-website-redirect-location" => $to, "cache-control" => $cache_control };
349+
if ($immutable_flake_tarball // 0) {
350+
# Optionally sets a header for the "Lockable HTTP Tarball Protocol".
351+
# See <https://github.com/NixOS/nix/blob/61f49de7ae0b3899abdcc102832523153dd40d35/doc/manual/source/protocols/tarball-fetcher.md>.
352+
# AWS S3 does not not allow setting the "Link" header directly.
353+
# Instead, we prefix the header with "x-amz-meta" and let Fastly
354+
# rename the header for us.
355+
$object_metadata->{'x-amz-meta-link'} = "<$to?rev=$rev>; rel=\"immutable\"";
356+
}
357+
$bucketChannels->add_key($from, "", $object_metadata)
349358
or die $bucketChannels->err . ": " . $bucketChannels->errstr;
350359
}
351360

352361
# Update channels on channels.nixos.org.
353362
redirect($channelName, $releasePrefix);
354-
redirect("$channelName/nixexprs.tar.xz", "$releasePrefix/nixexprs.tar.xz");
363+
redirect("$channelName/nixexprs.tar.xz", "$releasePrefix/nixexprs.tar.xz", 1);
355364
redirect("$channelName/git-revision", "$releasePrefix/git-revision");
356365
redirect("$channelName/packages.json.br", "$releasePrefix/packages.json.br");
357366
redirect("$channelName/store-paths.xz", "$releasePrefix/store-paths.xz");

0 commit comments

Comments
 (0)