diff --git a/flake.lock b/flake.lock index 57575c2..4d9870f 100644 --- a/flake.lock +++ b/flake.lock @@ -2,16 +2,16 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1606086654, - "narHash": "sha256-VFl+3eGIMqNp7cyOMJ6TjM/+UcsLKtodKoYexrlTJMI=", + "lastModified": 1726447378, + "narHash": "sha256-2yV8nmYE1p9lfmLHhOCbYwQC/W8WYfGQABoGzJOb1JQ=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "19db3e5ea2777daa874563b5986288151f502e27", + "rev": "086b448a5d54fd117f4dc2dee55c9f0ff461bdc1", "type": "github" }, "original": { "id": "nixpkgs", - "ref": "nixos-20.09", + "ref": "nixos-24.05", "type": "indirect" } }, diff --git a/flake.nix b/flake.nix index 09f5912..5c8eceb 100644 --- a/flake.nix +++ b/flake.nix @@ -1,5 +1,5 @@ { - inputs.nixpkgs.url = "nixpkgs/nixos-20.09"; + inputs.nixpkgs.url = "nixpkgs/nixos-24.05"; outputs = { self, nixpkgs }: @@ -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"; diff --git a/nix-serve.psgi b/nix-serve.psgi index 78370e2..928fa3b 100644 --- a/nix-serve.psgi +++ b/nix-serve.psgi @@ -22,6 +22,7 @@ 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"]]; @@ -29,9 +30,9 @@ my $app = sub { 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; @@ -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; @@ -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];