Hackery to make downloads work when using a binary cache

[?]
Feb 26, 2016, 4:28 PM
V2YFPM72UMEDEZVWBQT42KSVDALD5PPJXTBZALKH26SR5PKGC42AC

Dependencies

  • [2] 3TZGWQHO Allow downloading file by filename
  • [3] GJFYEU3S * Nix now stores logs by default as bzip2, make sure the build page uncompresses before showing.
  • [4] 7UHHF564 Security: Also check paths in the web server
  • [5] OD5FSS5A * Quick hack to allow viewing of dependency graphs (via nix-store -q
  • [6] MAOFG2TD * Allow omitting the product number if there is only one product in a
  • [7] LBNVQXUB * Build the /build stuff in a separate controller.
  • [8] EFWN7JBV * Added a status page that shows all the currently executing build steps.
  • [9] PMNWRTGJ Add multiple output support
  • [10] 5NO7NCKT * Refactoring.

Change contents

  • replacement in src/lib/Hydra/Controller/Build.pm at line 67
    [3.850][3.2125:2211]()
    $c->stash->{available} = all { isValidPath($_->path) } $build->buildoutputs->all;
    [3.850]
    [3.0]
    $c->stash->{available} =
    ($c->config->{store_mode} // "direct") eq "direct"
    ? all { isValidPath($_->path) } $build->buildoutputs->all
    : 1; # FIXME
  • edit in src/lib/Hydra/Controller/Build.pm at line 224
    [2.458]
    [3.2572]
    if ($product->path !~ /^($Nix::Config::storeDir\/[^\/]+)/) {
    die "Invalid store path " . $product->path . ".\n";
    }
    my $storePath = $1;
  • replacement in src/lib/Hydra/Controller/Build.pm at line 230
    [3.2573][3.250:350]()
    notFound($c, "Build product " . $product->path . " has disappeared.") unless -e $product->path;
    [3.2573]
    [3.2671]
    # 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 =
    defined $c->config->{binary_cache_public_key_file}
    ? "--option binary-cache-public-keys " . read_file($c->config->{binary_cache_public_key_file}) . "\n"
    : "";
    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;