Proxy local binary caches via hydra-server

[?]
Feb 26, 2016, 4:27 PM
YAD7524SVEXNAZROAJNCWGU6IDYZKMANLW7UD6IVT64LJVSHZNIAC

Dependencies

  • [2] MT5HGXFP Hydra/62 fix, broken nar download
  • [3] CJRWFVKZ Add a ‘latest-finished’ action
  • [4] MNKXBLNC Return 410 Gone (rather than 500) if an output is no longer available
  • [5] IAYKPDXX Honor $NIX_STORE_DIR.
  • [6] 2N6GLXDM Don't cache nix-cache-info very long
  • [7] IDT3SO3P Generate *.narinfo files on the fly to support the binary cache substituter
  • [8] IHUZXOK2 Reply 404 for requests for non-existent .narinfo.
  • [9] AFNDUSGD Set Expires headers for Hydra's binary cache
  • [10] CQTN62OH Die tabs die
  • [11] MVB7RRLT * Move NARs from the NixChannel controller to the Root controller and
  • [12] 5OXBTB3L Don't fall thru to Hydra::View::NARInfo
  • [13] XE6HD7BP Provide the nix-cache-info file required by the binary cache substituter
  • [14] 3PNG7NIB Remove trailing whitespace
  • [15] EWRCO2ND Give Hydra binary caches a low priority
  • [16] NHBGHO57 Set the Content-Type properly
  • [17] SMM4HQTP * Put actions related to builds under /build (e.g. /log/<buildid>
  • [18] J5UVLXOK * Start of a basic Catalyst web interface.
  • [19] ZE23JEJT Add a binary-cache-url file to channels to advertise the binary cache URL
  • [20] HAI5TY47 Make negative narinfo responses much smaller
  • [21] AFEKITYD Fix some warnings about undefined values
  • [22] PRDDAI6W Minor tweak
  • [23] UD2WKDUV Use queryPathFromHashPart to look up binary cache requests efficiently
  • [24] W3HI52QV use NIX_*_DIR env vars when defined

Change contents

  • replacement in src/lib/Hydra/Controller/Root.pm at line 260
    [7.2637][2.0:60]()
    $path = ($ENV{NIX_STORE_DIR} || "/nix/store")."/$path";
    [7.2637]
    [7.2637]
    die if $path =~ /\//;
  • replacement in src/lib/Hydra/Controller/Root.pm at line 262
    [7.2638][4.244:330]()
    gone($c, "Path " . $path . " is no longer available.") unless isValidPath($path);
    [7.2638]
    [7.602]
    my $storeMode = $c->config->{store_mode} // "direct";
  • replacement in src/lib/Hydra/Controller/Root.pm at line 264
    [7.603][7.603:681]()
    $c->stash->{current_view} = 'NixNAR';
    $c->stash->{storePath} = $path;
    [7.603]
    [7.18]
    if ($storeMode eq "s3-binary-cache") {
    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";
    gone($c, "Path " . $path . " is no longer available.") unless isValidPath($path);
    $c->stash->{current_view} = 'NixNAR';
    $c->stash->{storePath} = $path;
    }
  • replacement in src/lib/Hydra/Controller/Root.pm at line 286
    [7.101][7.47:93](),[7.93][7.0:33](),[7.33][7.139:195](),[7.2332][7.139:195](),[7.139][7.139:195](),[7.195][5.0:70](),[5.70][7.2722:2753](),[7.230][7.2722:2753](),[7.2753][7.24:157](),[7.24][7.24:157](),[7.157][7.34:61](),[7.61][6.0:39](),[6.39][7.259:298](),[7.45][7.259:298](),[7.61][7.259:298](),[7.259][7.259:298]()
    $c->response->content_type('text/plain');
    $c->stash->{plain}->{data} =
    #"StoreDir: $Nix::Config::storeDir\n" . # FIXME
    "StoreDir: " . ($ENV{NIX_STORE_DIR} || "/nix/store") . "\n" .
    "WantMassQuery: 0\n" .
    # Give Hydra binary caches a very low priority (lower than the
    # static binary cache http://nixos.org/binary-cache).
    "Priority: 100\n";
    setCacheHeaders($c, 24 * 60 * 60);
    $c->forward('Hydra::View::Plain');
    [7.101]
    [7.681]
    my $storeMode = $c->config->{store_mode} // "direct";
    if ($storeMode eq "s3-binary-cache") {
    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} =
    "StoreDir: $Nix::Config::storeDir\n" .
    "WantMassQuery: 0\n" .
    # Give Hydra binary caches a very low priority (lower than the
    # static binary cache http://nixos.org/binary-cache).
    "Priority: 100\n";
    setCacheHeaders($c, 24 * 60 * 60);
    $c->forward('Hydra::View::Plain');
    }
  • edit in src/lib/Hydra/Controller/Root.pm at line 314
    [7.85][7.85:124]()
    my $hash = $c->req->captures->[0];
  • replacement in src/lib/Hydra/Controller/Root.pm at line 315
    [7.125][7.42:74](),[7.42][7.42:74](),[7.74][7.0:45]()
    die if length($hash) != 32;
    my $path = queryPathFromHashPart($hash);
    [7.125]
    [7.470]
    my $storeMode = $c->config->{store_mode} // "direct";
  • replacement in src/lib/Hydra/Controller/Root.pm at line 317
    [7.471][7.126:144](),[7.144][3.784:819](),[7.28][7.144:194](),[3.819][7.144:194](),[7.144][7.144:194](),[7.194][7.62:119](),[7.119][7.255:298](),[7.255][7.255:298](),[7.298][7.46:84](),[7.84][7.0:16](),[7.298][7.0:16]()
    if (!$path) {
    $c->response->status(404);
    $c->response->content_type('text/plain');
    $c->stash->{plain}->{data} = "does not exist\n";
    $c->forward('Hydra::View::Plain');
    setCacheHeaders($c, 60 * 60);
    return;
    [7.471]
    [7.298]
    if ($storeMode eq "s3-binary-cache") {
    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");
  • edit in src/lib/Hydra/Controller/Root.pm at line 325
    [7.304]
    [7.17]
    else {
    my $hash = $c->req->captures->[0];
    die if length($hash) != 32;
    my $path = queryPathFromHashPart($hash);
  • replacement in src/lib/Hydra/Controller/Root.pm at line 332
    [7.18][7.309:345](),[7.309][7.309:345](),[7.345][7.120:161]()
    $c->stash->{storePath} = $path;
    $c->forward('Hydra::View::NARInfo');
    [7.18]
    [7.261]
    if (!$path) {
    $c->response->status(404);
    $c->response->content_type('text/plain');
    $c->stash->{plain}->{data} = "does not exist\n";
    $c->forward('Hydra::View::Plain');
    setCacheHeaders($c, 60 * 60);
    return;
    }
    $c->stash->{storePath} = $path;
    $c->forward('Hydra::View::NARInfo');
    }