From 0f258c3a01aa82d9de2406d711982df824070bc7 Mon Sep 17 00:00:00 2001 From: Moritz 'e1mo' Fromm Date: Mon, 20 Feb 2023 09:25:00 +0100 Subject: [PATCH] Specify priority via NIX_SERVE_PRIORITY Close #19 --- nix-serve.psgi | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/nix-serve.psgi b/nix-serve.psgi index e9fdd00..ef26b00 100644 --- a/nix-serve.psgi +++ b/nix-serve.psgi @@ -3,6 +3,7 @@ use Nix::Config; use Nix::Manifest; use Nix::Store; use Nix::Utils; +use Scalar::Util; use strict; sub stripPath { @@ -13,9 +14,11 @@ sub stripPath { my $app = sub { my $env = shift; my $path = $env->{PATH_INFO}; + my $priority = $ENV{"NIX_SERVE_PRIORITY"} || "30"; if ($path eq "/nix-cache-info") { - return [200, ['Content-Type' => 'text/plain'], ["StoreDir: $Nix::Config::storeDir\nWantMassQuery: 1\nPriority: 30\n"]]; + die("NIX_SERVE_PRIORITY must be numeric") unless Scalar::Util::looks_like_number($priority); + return [200, ['Content-Type' => 'text/plain'], ["StoreDir: $Nix::Config::storeDir\nWantMassQuery: 1\nPriority: $priority\n"]]; } elsif ($path =~ /^\/([0-9a-z]+)\.narinfo$/) {