From bc60fccf7835581d5971d3811f083b48cb1bb076 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 18 Oct 2017 12:23:07 +0200 Subject: [PATCH] Remove remaining references to store_mode etc. --- src/lib/Hydra/Base/Controller/NixChannel.pm | 8 ++++++ src/lib/Hydra/Controller/Build.pm | 25 ++----------------- src/lib/Hydra/Controller/Root.pm | 27 +++------------------ src/lib/Hydra/Helper/CatalystUtils.pm | 3 +-- src/lib/Hydra/Helper/Nix.pm | 21 +++++++++++++--- src/lib/Hydra/View/NixPkg.pm | 10 +++----- src/script/hydra-update-gc-roots | 2 +- 7 files changed, 36 insertions(+), 60 deletions(-) diff --git a/src/lib/Hydra/Base/Controller/NixChannel.pm b/src/lib/Hydra/Base/Controller/NixChannel.pm index 508043f2..6a73bdb3 100644 --- a/src/lib/Hydra/Base/Controller/NixChannel.pm +++ b/src/lib/Hydra/Base/Controller/NixChannel.pm @@ -53,6 +53,9 @@ sub getChannelData { sub closure : Chained('nix') PathPart { my ($self, $c) = @_; + + requireLocalStore($c); + $c->stash->{current_view} = 'NixClosure'; getChannelData($c, 1); @@ -68,6 +71,7 @@ sub closure : Chained('nix') PathPart { sub manifest : Chained('nix') PathPart("MANIFEST") Args(0) { my ($self, $c) = @_; + requireLocalStore($c); $c->stash->{current_view} = 'NixManifest'; $c->stash->{narBase} = $c->uri_for($c->controller('Root')->action_for("nar")); getChannelData($c, 1); @@ -86,6 +90,8 @@ sub pkg : Chained('nix') PathPart Args(1) { || notFound($c, "No such package in this channel."); } + requireLocalStore($c); + gone($c, "Build " . $c->stash->{build}->id . " is no longer available.") unless all { isValidPath($_->path) } $c->stash->{build}->buildoutputs->all; @@ -97,6 +103,7 @@ sub pkg : Chained('nix') PathPart Args(1) { sub nixexprs : Chained('nix') PathPart('nixexprs.tar.bz2') Args(0) { my ($self, $c) = @_; + requireLocalStore($c); $c->stash->{current_view} = 'NixExprs'; getChannelData($c, 1); } @@ -126,6 +133,7 @@ sub sortPkgs { sub channel_contents : Chained('nix') PathPart('') Args(0) { my ($self, $c) = @_; + requireLocalStore($c); # Optimistically assume that none of the packages have been # garbage-collected. That should be true for the "latest" # channel. diff --git a/src/lib/Hydra/Controller/Build.pm b/src/lib/Hydra/Controller/Build.pm index 047d0d8e..f3b6f49f 100644 --- a/src/lib/Hydra/Controller/Build.pm +++ b/src/lib/Hydra/Controller/Build.pm @@ -65,9 +65,9 @@ sub build_GET { $c->stash->{template} = 'build.tt'; $c->stash->{available} = - ($c->config->{store_mode} // "direct") eq "direct" + isLocalStore ? all { isValidPath($_->path) } $build->buildoutputs->all - : 1; # FIXME + : 1; $c->stash->{drvAvailable} = isValidPath $build->drvpath; if ($build->finished && $build->iscachedbuild) { @@ -204,27 +204,6 @@ sub download : Chained('buildChain') PathPart { } my $storePath = $1; - # Hack to get downloads to work on binary cache stores: if the - # store path is not available locally, then import it into the - # local store. FIXME: find a better way; this can require an - # unbounded amount of space. - if (!isValidPath($storePath)) { - my $storeMode = $c->config->{store_mode} // "direct"; - notFound($c, "File " . $product->path . " has disappeared.") - if $storeMode eq "direct"; - my $url = - $storeMode eq "local-binary-cache" ? "file://" . $c->config->{binary_cache_dir} : - $storeMode eq "s3-binary-cache" ? "https://" . $c->config->{binary_cache_s3_bucket} . ".s3.amazonaws.com/" : - die; - my $args = ""; - if (defined $c->config->{binary_cache_public_key_file} - && -r $c->config->{binary_cache_public_key_file}) - { - $args = "--option binary-cache-public-keys " . read_file($c->config->{binary_cache_public_key_file}); - } - system("nix-store --realise '$storePath' --option extra-binary-caches '$url' $args>/dev/null"); - } - notFound($c, "File " . $product->path . " does not exist.") unless -e $product->path; return $c->res->redirect(defaultUriForProduct($self, $c, $product, @path)) diff --git a/src/lib/Hydra/Controller/Root.pm b/src/lib/Hydra/Controller/Root.pm index 2e9718f7..e6a503a1 100644 --- a/src/lib/Hydra/Controller/Root.pm +++ b/src/lib/Hydra/Controller/Root.pm @@ -258,17 +258,10 @@ sub nar :Local :Args(1) { die if $path =~ /\//; - my $storeMode = $c->config->{store_mode} // "direct"; - - if ($storeMode eq "s3-binary-cache") { + if (!isLocalStore) { notFound($c, "There is no binary cache here."); } - elsif ($storeMode eq "local-binary-cache") { - my $dir = $c->config->{binary_cache_dir}; - $c->serve_static_file($dir . "/nar/" . $path); - } - else { $path = $Nix::Config::storeDir . "/$path"; @@ -283,17 +276,10 @@ sub nar :Local :Args(1) { sub nix_cache_info :Path('nix-cache-info') :Args(0) { my ($self, $c) = @_; - my $storeMode = $c->config->{store_mode} // "direct"; - - if ($storeMode eq "s3-binary-cache") { + if (!isLocalStore) { notFound($c, "There is no binary cache here."); } - elsif ($storeMode eq "local-binary-cache") { - my $dir = $c->config->{binary_cache_dir}; - $c->serve_static_file($dir . "/nix-cache-info"); - } - else { $c->response->content_type('text/plain'); $c->stash->{plain}->{data} = @@ -311,17 +297,10 @@ sub nix_cache_info :Path('nix-cache-info') :Args(0) { sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) { my ($self, $c) = @_; - my $storeMode = $c->config->{store_mode} // "direct"; - - if ($storeMode eq "s3-binary-cache") { + if (!isLocalStore) { notFound($c, "There is no binary cache here."); } - elsif ($storeMode eq "local-binary-cache") { - my $dir = $c->config->{binary_cache_dir}; - $c->serve_static_file($dir . "/" . $c->req->captures->[0] . ".narinfo"); - } - else { my $hash = $c->req->captures->[0]; diff --git a/src/lib/Hydra/Helper/CatalystUtils.pm b/src/lib/Hydra/Helper/CatalystUtils.pm index 019c07b7..76fa6a7d 100644 --- a/src/lib/Hydra/Helper/CatalystUtils.pm +++ b/src/lib/Hydra/Helper/CatalystUtils.pm @@ -347,8 +347,7 @@ sub approxTableSize { sub requireLocalStore { my ($c) = @_; - notFound($c, "Nix channels are not supported by this Hydra server.") - if ($c->config->{store_mode} // "direct") ne "direct"; + notFound($c, "Nix channels are not supported by this Hydra server.") if !Hydra::Helper::Nix::isLocalStore(); } diff --git a/src/lib/Hydra/Helper/Nix.pm b/src/lib/Hydra/Helper/Nix.pm index 67d536f6..f4c66f92 100644 --- a/src/lib/Hydra/Helper/Nix.pm +++ b/src/lib/Hydra/Helper/Nix.pm @@ -23,7 +23,10 @@ our @EXPORT = qw( getEvals getMachines pathIsInsidePrefix captureStdoutStderr run grab - getTotalShares readNixFile + getTotalShares + getStoreUri + readNixFile + isLocalStore cancelBuilds restartBuilds); @@ -491,12 +494,22 @@ sub restartBuilds($$) { } +sub getStoreUri { + my $config = getHydraConfig(); + return $config->{'store_uri'} // "auto"; +} + + # Read a file from the (possibly remote) nix store sub readNixFile { my ($path) = @_; - my $config = getHydraConfig(); - my $storeUri = $config->{'store_uri'} // ""; - return grab(cmd => ["nix", "cat-store", "$path"], env => { NIX_REMOTE => "$storeUri" }); + return grab(cmd => ["nix", "cat-store", "--store", getStoreUri(), "$path"]); +} + + +sub isLocalStore { + my $uri = getStoreUri(); + return $uri =~ "^(local|daemon|auto)"; } diff --git a/src/lib/Hydra/View/NixPkg.pm b/src/lib/Hydra/View/NixPkg.pm index 1209c882..b8a46571 100644 --- a/src/lib/Hydra/View/NixPkg.pm +++ b/src/lib/Hydra/View/NixPkg.pm @@ -2,6 +2,7 @@ package Hydra::View::NixPkg; use strict; use base qw/Catalyst::View/; +use Hydra::Helper::CatalystUtils; sub process { my ($self, $c) = @_; @@ -10,12 +11,9 @@ sub process { my $build = $c->stash->{build}; - my $storeMode = $c->config->{store_mode} // "direct"; - my $channelUri = - $storeMode eq "direct" ? $c->uri_for('/') - : $storeMode eq "s3-binary-cache" ? - ($c->config->{binary_cache_public_uri} // ("https://" . $c->config->{binary_cache_s3_bucket} . ".s3.amazonaws.com/")) - : die "Not supported.\n"; + requireLocalStore($c); + + my $channelUri = $c->uri_for('/'); # FIXME: add multiple output support my $s = "NIXPKG1 http://invalid.org/" diff --git a/src/script/hydra-update-gc-roots b/src/script/hydra-update-gc-roots index 5877a635..073e2f76 100755 --- a/src/script/hydra-update-gc-roots +++ b/src/script/hydra-update-gc-roots @@ -38,7 +38,7 @@ sub keepBuild { $build->get_column('project'), ":", $build->get_column('jobset'), ":", $build->get_column('job'), "; ", $build->system, "; ", strftime("%Y-%m-%d %H:%M:%S", localtime($build->timestamp)), ")\n"; - if (($config->{store_mode} // "direct") eq "direct" && + if (isLocalStore && $build->finished && ($build->buildstatus == 0 || $build->buildstatus == 6)) { foreach my $path (split / /, $build->get_column('outpaths')) {