diff --git a/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in b/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in index 1afe8854fed1..890e68765b40 100644 --- a/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in +++ b/pkgs/servers/http/nix-binary-cache/nix-binary-cache.cgi.in @@ -10,13 +10,18 @@ KEYNAME=na export NIX_REMOTE=daemon config="${NIX_BINARY_CACHE_CONFIG:-${HTTP_NIX_BINARY_CACHE_CONFIG:-/etc/nix/nix-binary-cache.cgi.conf}}" -config="$(cd "$(@coreutils@/dirname "$config")"; +config="$(cd "$(@coreutils@/dirname "$config")"; @coreutils@/pwd)/$(@coreutils@/basename "$config")" @coreutils@/test -e "$config" && . "$config" header(){ echo "Content-Type: text/plain; charset=utf-8" - echo + echo +} + +header404(){ + echo "Status: 404 Not Found" + echo } clean_path() { @@ -28,12 +33,12 @@ storeq(){ } sign(){ - test -n "$1" && - @coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' | + test -n "$1" && + @coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' | @openssl@/openssl rsautl -sign -inkey "$@" | @coreutils@/base64 -w 0 } -case "$QUERY_STRING" in +case "$QUERY_STRING" in "") header echo "Hello, this is a dynamically-generated Nix binary cache" @@ -61,9 +66,9 @@ case "$QUERY_STRING" in echo "Compression: $COMPRESSION" echo "NarHash: $(storeq --hash "$path")" echo "NarSize: $(storeq --size "$path")" - echo "References: $(storeq --references "$path" | + echo "References: $(storeq --references "$path" | @coreutils@/tac | clean_path )" - echo "Deriver: $(storeq --deriver "$path" | + echo "Deriver: $(storeq --deriver "$path" | clean_path )" )" signature="$(echo "$info" | sign "$KEY")" @@ -72,6 +77,7 @@ case "$QUERY_STRING" in echo "Signature: 1;$KEYNAME;$signature" else + header404 exit 1 fi ;; @@ -81,6 +87,7 @@ case "$QUERY_STRING" in header @nix@/nix-store --dump "$path" | @xz@/xz else + header404 exit 1 fi ;; @@ -91,6 +98,7 @@ case "$QUERY_STRING" in header @nix@/nix-store --dump "$path" | @bzip2@/bzip2 else + header404 exit 1 fi ;;