Generate *.narinfo files on the fly to support the binary cache substituter

[?]
Jul 2, 2012, 6:09 PM
IDT3SO3P52TCB4IWV3LYZJ5JLJACNQ26X65VXUTUD227PRE2UZUAC

Dependencies

  • [2] AFEKITYD Fix some warnings about undefined values
  • [3] MVB7RRLT * Move NARs from the NixChannel controller to the Root controller and
  • [4] SZYDW2DG hydra: added some user admin
  • [*] J5UVLXOK * Start of a basic Catalyst web interface.
  • [*] D5QIOJGP * Move everything up one directory.

Change contents

  • replacement in src/lib/Hydra/Controller/Root.pm at line 198
    [3.684][2.160:193]()
    sub narinfo :Path('*.narinfo') {
    [3.684]
    [2.193]
    sub hashToPath {
    my ($c, $hash) = @_;
    die if length($hash) != 32;
    # FIXME: doing a glob is very inefficient. Should do a database
    # lookup.
    my @glob = glob("/nix/store/$hash*");
    foreach my $storePath (@glob) {
    if (isValidPath($storePath)) {
    print STDERR "FOUND: $hash -> $storePath\n";
    return $storePath;
    }
    #return $storePath if isValidPath($storePath);
    }
    notFound($c, "Store path with hash ‘$hash’ does not exist.");
    }
    sub narinfo :LocalRegex('^([a-z0-9]+).narinfo$') :Args(0) {
  • replacement in src/lib/Hydra/Controller/Root.pm at line 217
    [2.218][2.218:261]()
    $c->stash->{current_view} = 'NixInfo';
    [2.218]
    [2.261]
    my $hash = $c->req->captures->[0];
    $c->stash->{storePath} = hashToPath($c, $hash);
    $c->stash->{current_view} = 'NARInfo';
  • file addition: NARInfo.pm (----------)
    [7.1193]
    package Hydra::View::NARInfo;
    use strict;
    use base qw/Catalyst::View/;
    use File::Basename;
    use Nix::Store;
    sub process {
    my ($self, $c) = @_;
    my $storePath = $c->stash->{storePath};
    $c->response->content_type('text/x-nix-narinfo'); # !!! check MIME type
    my ($deriver, $narHash, $time, $narSize, $refs) = queryPathInfo($storePath);
    my $info;
    $info .= "StorePath: $storePath\n";
    $info .= "URL: nar/" . basename $storePath. "\n";
    $info .= "Compression: bzip2\n";
    #$info .= "FileHash: sha256:$compressedHash\n";
    #$info .= "FileSize: $compressedSize\n";
    $info .= "NarHash: $narHash\n";
    $info .= "NarSize: $narSize\n";
    $info .= "References: " . join(" ", map { basename $_ } @{$refs}) . "\n";
    if (defined $deriver) {
    $info .= "Deriver: " . basename $deriver . "\n";
    if (isValidPath($deriver)) {
    my $drv = derivationFromPath($deriver);
    $info .= "System: $drv->{platform}\n";
    }
    }
    $c->response->body($info);
    return 1;
    }
    1;