Skip to content

Commit

Permalink
Merge pull request #60 from fabianhjr/support-recent-nix-versions
Browse files Browse the repository at this point in the history
Support Nix::Store from 2.21 onwards
  • Loading branch information
edolstra authored Sep 18, 2024
2 parents 4a12660 + 14480c0 commit 77ffa33
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 12 deletions.
8 changes: 4 additions & 4 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
inputs.nixpkgs.url = "nixpkgs/nixos-20.09";
inputs.nixpkgs.url = "nixpkgs/nixos-24.05";

outputs = { self, nixpkgs }:

Expand All @@ -13,7 +13,7 @@
nix-serve = with final; stdenv.mkDerivation {
name = "nix-serve-${self.lastModifiedDate}";

buildInputs = [ perl nix.perl-bindings perlPackages.Plack perlPackages.Starman perlPackages.DBDSQLite ];
buildInputs = [ perl nixVersions.latest.perl-bindings perlPackages.Plack perlPackages.Starman perlPackages.DBDSQLite ];

unpackPhase = "true";

Expand Down
13 changes: 7 additions & 6 deletions nix-serve.psgi
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,17 @@ BEGIN {
my $app = sub {
my $env = shift;
my $path = $env->{PATH_INFO};
my $store = Nix::Store->new();

if ($path eq "/nix-cache-info") {
return [200, ['Content-Type' => 'text/plain'], ["StoreDir: $Nix::Config::storeDir\nWantMassQuery: 1\nPriority: 30\n"]];
}

elsif ($path =~ /^\/([0-9a-z]+)\.narinfo$/) {
my $hashPart = $1;
my $storePath = queryPathFromHashPart($hashPart);
my $storePath = $store->queryPathFromHashPart($hashPart);
return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
my ($deriver, $narHash, $time, $narSize, $refs, $sigs) = queryPathInfo($storePath, 1) or die;
my ($deriver, $narHash, $time, $narSize, $refs, $sigs) = $store->queryPathInfo($storePath, 1) or die;
$narHash =~ /^sha256:(.*)/ or die;
my $narHash2 = $1;
die unless length($narHash2) == 52;
Expand All @@ -57,9 +58,9 @@ my $app = sub {
elsif ($path =~ /^\/nar\/([0-9a-z]+)-([0-9a-z]+)\.nar$/) {
my $hashPart = $1;
my $expectedNarHash = $2;
my $storePath = queryPathFromHashPart($hashPart);
my $storePath = $store->queryPathFromHashPart($hashPart);
return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
my ($deriver, $narHash, $time, $narSize, $refs, $sigs) = queryPathInfo($storePath, 1) or die;
my ($deriver, $narHash, $time, $narSize, $refs, $sigs) = $store->queryPathInfo($storePath, 1) or die;
return [404, ['Content-Type' => 'text/plain'], ["Incorrect NAR hash. Maybe the path has been recreated.\n"]]
unless $narHash eq "sha256:$expectedNarHash";
my $fh = new IO::Handle;
Expand All @@ -70,9 +71,9 @@ my $app = sub {
# FIXME: remove soon.
elsif ($path =~ /^\/nar\/([0-9a-z]+)\.nar$/) {
my $hashPart = $1;
my $storePath = queryPathFromHashPart($hashPart);
my $storePath = $store->queryPathFromHashPart($hashPart);
return [404, ['Content-Type' => 'text/plain'], ["No such path.\n"]] unless $storePath;
my ($deriver, $narHash, $time, $narSize, $refs) = queryPathInfo($storePath, 1) or die;
my ($deriver, $narHash, $time, $narSize, $refs) = $store->queryPathInfo($storePath, 1) or die;
my $fh = new IO::Handle;
open $fh, "-|", "nix", "dump-path", "--", $storePath;
return [200, ['Content-Type' => 'text/plain', 'Content-Length' => $narSize], $fh];
Expand Down

0 comments on commit 77ffa33

Please sign in to comment.