diff options
Diffstat (limited to 'krebs')
-rw-r--r-- | krebs/5pkgs/simple/htgen-paste/default.nix | 27 | ||||
-rw-r--r-- | krebs/5pkgs/simple/htgen-paste/src/htgen-paste | 68 | ||||
-rw-r--r-- | krebs/nixpkgs-unstable.json | 8 | ||||
-rw-r--r-- | krebs/nixpkgs.json | 8 |
4 files changed, 103 insertions, 8 deletions
diff --git a/krebs/5pkgs/simple/htgen-paste/default.nix b/krebs/5pkgs/simple/htgen-paste/default.nix new file mode 100644 index 000000000..48b72833e --- /dev/null +++ b/krebs/5pkgs/simple/htgen-paste/default.nix @@ -0,0 +1,27 @@ +{ pkgs, stockholm, stdenv }: +with stockholm.lib; + +stdenv.mkDerivation rec { + pname = "htgen-paste"; + version = "1.0.0"; + + src = ./src; + + buildPhase = '' + ( + exec > htgen-paste + echo PATH=${makeBinPath [ + pkgs.nix + pkgs.file + pkgs.coreutils + pkgs.findutils + ]} + echo STATEDIR=${shell.escape "\${STATEDIR-$HOME}"} + cat $src/htgen-paste + ) + ''; + + installPhase = '' + install -D htgen-paste $out/bin/htgen-paste + ''; +} diff --git a/krebs/5pkgs/simple/htgen-paste/src/htgen-paste b/krebs/5pkgs/simple/htgen-paste/src/htgen-paste new file mode 100644 index 000000000..bc806e870 --- /dev/null +++ b/krebs/5pkgs/simple/htgen-paste/src/htgen-paste @@ -0,0 +1,68 @@ +find_item() { + if test ${#1} -ge 7; then + set -- "$(find "$STATEDIR/items" -mindepth 1 -maxdepth 1 \ + -regex "$STATEDIR/items/$1[0-9A-Za-z]*$")" + if test -n "$1" && test $(echo "$1" | wc -l) = 1; then + echo "$1" + return 0 + fi + fi + return 1 +} + +abs_path=${Request_URI%%\?*} + +case "$Method $abs_path" in + "GET /"[0-9a-z]*) + if item=$(find_item ${abs_path#/}); then + content_type=$(cat "$item".content_type 2>/dev/null || file -ib "$item") + printf 'HTTP/1.1 200 OK\r\n' + printf 'Content-Type: %s\r\n' "$content_type" + printf 'Server: %s\r\n' "$Server" + printf 'Connection: close\r\n' + printf 'Content-Length: %d\r\n' $(wc -c < $item) + printf '\r\n' + cat $item + exit + fi + ;; + "POST /") + content=$(mktemp -t htgen.$$.content.XXXXXXXX) + trap "rm $content >&2" EXIT + + case ${req_expect-} in 100-continue) + printf 'HTTP/1.1 100 Continue\r\n\r\n' + esac + + head -c $req_content_length > $content + + sha256=$(sha256sum -b $content | cut -d\ -f1) + base32=$(nix-hash --to-base32 --type sha256 $sha256) + item=$STATEDIR/items/$base32 + ref=http://$req_host/$base32 + + if ! test -e $item; then + mkdir -v -p $STATEDIR/items >&2 + cp -v $content $item >&2 + fi + + if test -n ${reg_content_type-}; then + echo -n "$req_content_type" > "$item".content_type + fi + + base32short=$(echo $base32 | cut -b-7) + if item=$(find_item $base32short); then + ref=$(echo "$ref"; echo "http://$req_host/$base32short") + fi + + printf 'HTTP/1.1 200 OK\r\n' + printf 'Content-Type: text/plain; charset=UTF-8\r\n' + printf 'Server: %s\r\n' "$Server" + printf 'Connection: close\r\n' + printf 'Content-Length: %d\r\n' $(expr ${#ref} + 1) + printf '\r\n' + printf '%s\n' "$ref" + + exit + ;; +esac diff --git a/krebs/nixpkgs-unstable.json b/krebs/nixpkgs-unstable.json index bd1ab98c0..11ac1c6e4 100644 --- a/krebs/nixpkgs-unstable.json +++ b/krebs/nixpkgs-unstable.json @@ -1,9 +1,9 @@ { "url": "https://github.com/NixOS/nixpkgs", - "rev": "645bc49f34fa8eff95479f0345ff57e55b53437e", - "date": "2023-04-19T18:04:47+02:00", - "path": "/nix/store/jh86824939585dinrs1zlkh6cvz8l8l7-nixpkgs", - "sha256": "0kfndc7xdkm89yl0f27wdnwd6gdad3i49jx7gvaib1hz0ifpmxzv", + "rev": "d6b863fd9b7bb962e6f9fdf292419a775e772891", + "date": "2023-04-26T18:35:28+02:00", + "path": "/nix/store/kyr8hz9d55f9fffr4y8d3hz3zb7h9fhb-nixpkgs", + "sha256": "02rd1n6d453rdp2978bvnp99nyfa26jxgbsg78yb9mmdxvha3hnr", "fetchLFS": false, "fetchSubmodules": false, "deepClone": false, diff --git a/krebs/nixpkgs.json b/krebs/nixpkgs.json index 7e478e9cf..bc350d0d7 100644 --- a/krebs/nixpkgs.json +++ b/krebs/nixpkgs.json @@ -1,9 +1,9 @@ { "url": "https://github.com/NixOS/nixpkgs", - "rev": "fd901ef4bf93499374c5af385b2943f5801c0833", - "date": "2023-04-22T11:27:49+08:00", - "path": "/nix/store/gpfv5hbki6g1b63nqw7md5bjlcpzsz1w-nixpkgs", - "sha256": "1fd7xyfna0klfbv37qq1ms2j4gzjpy14a8vbnw1i8ix6fijkywjf", + "rev": "15b75800dce80225b44f067c9012b09de37dfad2", + "date": "2023-04-26T21:45:16+02:00", + "path": "/nix/store/5d3a0nazp51ndfgf9dpgyyw14g5i02mh-nixpkgs", + "sha256": "0xmza136qf0hssh2a4dq62w7w1xs6rdfxs314pqxqjvvqibf1qb2", "fetchLFS": false, "fetchSubmodules": false, "deepClone": false, |