at 17.09-beta 2.2 kB view raw
1#! @shell@ 2 3STORE_DIR="${NIX_STORE_DIR:-/nix/store}" 4MASS_QUERY=0 5PRIORITY=75 6COMPRESSION=bzip2 7KEY= 8KEYNAME=na 9 10export NIX_REMOTE=daemon 11 12config="${NIX_BINARY_CACHE_CONFIG:-${HTTP_NIX_BINARY_CACHE_CONFIG:-/etc/nix/nix-binary-cache.cgi.conf}}" 13config="$(cd "$(@coreutils@/dirname "$config")"; 14 @coreutils@/pwd)/$(@coreutils@/basename "$config")" 15@coreutils@/test -e "$config" && . "$config" 16 17header(){ 18 echo "Content-Type: text/plain; charset=utf-8" 19 echo 20} 21 22header404(){ 23 echo "Status: 404 Not Found" 24 echo 25} 26 27clean_path() { 28 @gnused@/sed -re "s@^$STORE_DIR/?@@" | @findutils@/xargs 29} 30 31storeq(){ 32 @nix@/nix-store -q "$@" 33} 34 35sign(){ 36 test -n "$1" && 37 @coreutils@/sha256sum | @gnused@/sed -e 's/ .*//' | 38 @openssl@/openssl rsautl -sign -inkey "$@" | @coreutils@/base64 -w 0 39} 40 41case "$QUERY_STRING" in 42 "") 43 header 44 echo "Hello, this is a dynamically-generated Nix binary cache" 45 ;; 46 /debug) 47 header 48 set 49 ;; 50 /nix-cache-info) 51 header 52 echo "StoreDir: $STORE_DIR" 53 echo "WantMassQuery: $MASS_QUERY" 54 echo "Priority: $PRIORITY" 55 ;; 56 *.narinfo) 57 hash=${QUERY_STRING%.narinfo} 58 hash=${hash#/} 59 path="$(echo "$STORE_DIR/$hash-"* | @coreutils@/sort | @coreutils@/head -n 1)" 60 if [ -n "$path" ] && [ -e "$path" ]; then 61 header 62 info="$( 63 echo "StorePath: $path" 64 echo "URL: $(@coreutils@/basename "$path" 65 ).nar.$COMPRESSION" 66 echo "Compression: $COMPRESSION" 67 echo "NarHash: $(storeq --hash "$path")" 68 echo "NarSize: $(storeq --size "$path")" 69 echo "References: $(storeq --references "$path" | 70 @coreutils@/tac | clean_path )" 71 echo "Deriver: $(storeq --deriver "$path" | 72 clean_path )" 73 )" 74 signature="$(echo "$info" | sign "$KEY")" 75 76 echo "$info" 77 echo "Signature: 1;$KEYNAME;$signature" 78 79 else 80 header404 81 exit 1 82 fi 83 ;; 84 *.nar.xz) 85 path="$STORE_DIR${QUERY_STRING%.nar.xz}" 86 if [ -n "$path" ] && [ -e "$path" ]; then 87 header 88 @nix@/nix-store --dump "$path" | @xz@/xz 89 else 90 header404 91 exit 1 92 fi 93 ;; 94 *.nar.bzip2) 95 path="$STORE_DIR${QUERY_STRING%.nar.bzip2}" 96 echo "$path" >&2; 97 if [ -n "$path" ] && [ -e "$path" ]; then 98 header 99 @nix@/nix-store --dump "$path" | @bzip2@/bzip2 100 else 101 header404 102 exit 1 103 fi 104 ;; 105esac