diff options
| author | makefu <github@syntax-fehler.de> | 2021-11-07 14:31:25 +0100 | 
|---|---|---|
| committer | makefu <github@syntax-fehler.de> | 2021-11-07 14:31:25 +0100 | 
| commit | 4572fc3e34c981df82767360ae06216d1cfe6f10 (patch) | |
| tree | ba5c53fff3908f2889116a2efc329bcf520a80c7 /tv | |
| parent | 7b618e1e0883b9ea05c73b5e88d2adc6d144cae6 (diff) | |
| parent | a9e605e8866b2f7277e7db0c8e4de8e8d4cf8565 (diff) | |
Merge remote-tracking branch 'lass/master'
Diffstat (limited to 'tv')
| -rw-r--r-- | tv/2configs/elm-packages-proxy.nix | 107 | ||||
| -rw-r--r-- | tv/2configs/gitrepos.nix | 3 | ||||
| -rw-r--r-- | tv/5pkgs/haskell/mailaids.nix | 4 | ||||
| -rw-r--r-- | tv/5pkgs/haskell/th-env/default.nix | 4 | 
4 files changed, 113 insertions, 5 deletions
diff --git a/tv/2configs/elm-packages-proxy.nix b/tv/2configs/elm-packages-proxy.nix index 097d706..caea188 100644 --- a/tv/2configs/elm-packages-proxy.nix +++ b/tv/2configs/elm-packages-proxy.nix @@ -60,6 +60,11 @@ in {        proxy_pass $new_uri;      ''; + +    locations."/search.json".extraConfig = '' +      proxy_pass http://127.0.0.1:${toString config.krebs.htgen.elm-packages-proxy.port}; +      proxy_pass_header Server; +    '';    };    krebs.htgen.elm-packages-proxy = { @@ -192,6 +197,36 @@ in {            exit          ;; +        'DELETE /packages/'*) + +          author=$req_x_author +          pname=$req_x_package +          user=$req_x_user +          version=$req_x_version + +          zipball=${cfg.packageDir}/$author/$pname/$version/zipball +          elmjson=$HOME/cache/$author%2F$pname%2F$version%2Felm.json +          endpointjson=$HOME/cache/$author%2F$pname%2F$version%2Fendpoint.json + +          if test -e "$zipball"; then +            zipball_owner=$(attr -q -g X-User "$zipball" || :) +            if test "$zipball_owner" = "$req_x_user"; then +              echo "user $user is deleting package $author/$pname@$version" >&2 +              rm -f "$elmjson" +              rm -f "$endpointjson" +              rm "$zipball" +              string_response 200 OK \ +                  "package deleted: $author/$pname@$version" \ +                  text/plain +              exit +            else +              string_response 403 Forbidden \ +                  "package already exists: $author/$pname@$version" \ +                  text/plain +              exit +            fi +          fi +        ;;          'GET /all-packages'|'POST /all-packages')            response=$(mktemp -t htgen.$$.elm-packages-proxy.all-packages.XXXXXXXX) @@ -239,7 +274,7 @@ in {                  select(.!="") |                  sub("^\\./(?<author>[^/]+)/(?<pname>[^/]+)/(?<version>[^/]+)$";"\(.author)/\(.pname)@\(.version)")                ) | -              sort_by(split("@") | [.[0]]+(.[1]|split("."))) | +              sort_by(split("@") | [.[0]]+(.[1]|split(".")|map(tonumber))) |                reverse              '            } | @@ -248,6 +283,76 @@ in {            file_response 200 OK "$response" 'application/json; charset=UTF-8'            exit          ;; +        'GET /search.json') + +          searchjson=$HOME/cache/search.json +          mkdir -p "$HOME/cache" + +          # update cached search.json +          ( +            last_modified=$( +              if test -f "$searchjson"; then +                date -Rr "$searchjson" +              else +                date -R -d @0 +              fi +            ) +            tempsearchjson=$(mktemp "$searchjson.XXXXXXXX") +            trap 'rm "$tempsearchjson" >&2' EXIT +            curl -fsS --compressed https://package.elm-lang.org/search.json \ +                -H "If-Modified-Since: $last_modified" \ +                -o "$tempsearchjson" +            if test -s "$tempsearchjson"; then +              mv "$tempsearchjson" "$searchjson" +              trap - EXIT +            fi +          ) + +          response=$(mktemp -t htgen.$$.elm-packages-proxy.search.XXXXXXXX) +          trap 'rm "$response" >&2' EXIT + +          { +            printf '{"upstream":'; cat "$searchjson" +            printf ',"private":'; (cd ${cfg.packageDir}; find -mindepth 3 -maxdepth 3) | +              jq -Rs ' +                split("\n") | +                map( +                  select(.!="") | +                  match("^\\./(?<author>[^/]+)/(?<pname>[^/]+)/(?<version>[^/]+)$").captures | +                  map({key:.name,value:.string}) | +                  from_entries +                ) | +                map({ +                  key: "\(.author)/\(.pname)", +                  value: .version, +                }) | +                from_entries +              ' +            printf '}' +          } | +          jq -c ' +            reduce .upstream[] as $upstreamItem ({ private, output: [] }; +              .private[$upstreamItem.name] as $privateItem | +              if $privateItem then +                .output += [$upstreamItem * { version: $privateItem.version }] | +                .private |= del(.[$upstreamItem.name]) +              else +                .output += [$upstreamItem] +              end +            ) | + +            .output + (.private | to_entries | sort_by(.key) | map({ +              name: .key, +              version: .value, +              summary: "dummy summary", +              license: "dummy license", +            })) +          ' \ +          > $response + +          file_response 200 OK "$response" 'application/json; charset=UTF-8' +          exit +        ;;        esac      ''}'';    }; diff --git a/tv/2configs/gitrepos.nix b/tv/2configs/gitrepos.nix index 1586f3b..2b8457e 100644 --- a/tv/2configs/gitrepos.nix +++ b/tv/2configs/gitrepos.nix @@ -83,6 +83,9 @@ let {      htgen = {        cgit.desc = "toy HTTP server";      }; +    ircaids = { +      cgit.desc = "Assortment of aids for working with Internet relay chat"; +    };      krops = {        cgit.desc = "deployment tools";      }; diff --git a/tv/5pkgs/haskell/mailaids.nix b/tv/5pkgs/haskell/mailaids.nix index b705c7c..f152a76 100644 --- a/tv/5pkgs/haskell/mailaids.nix +++ b/tv/5pkgs/haskell/mailaids.nix @@ -1,6 +1,6 @@  { mkDerivation, aeson, aeson-pretty, base, bytestring  , case-insensitive, fetchgit, lens, optparse-applicative -, purebred-email, stdenv, text, vector, word8 +, purebred-email, lib, text, vector, word8  }:  mkDerivation {    pname = "mailaids"; @@ -17,5 +17,5 @@ mkDerivation {      aeson aeson-pretty base bytestring case-insensitive lens      optparse-applicative purebred-email text vector word8    ]; -  license = stdenv.lib.licenses.mit; +  license = lib.licenses.mit;  } diff --git a/tv/5pkgs/haskell/th-env/default.nix b/tv/5pkgs/haskell/th-env/default.nix index 474a63b..158fb16 100644 --- a/tv/5pkgs/haskell/th-env/default.nix +++ b/tv/5pkgs/haskell/th-env/default.nix @@ -1,4 +1,4 @@ -{ mkDerivation, base, stdenv, template-haskell, text }: +{ mkDerivation, base, lib, template-haskell, text }:  mkDerivation {    pname = "th-env";    version = "1.0.0"; @@ -6,5 +6,5 @@ mkDerivation {    libraryHaskellDepends = [ base template-haskell text ];    homepage = "https://stackoverflow.com/q/57635686";    license = "unknown"; -  hydraPlatforms = stdenv.lib.platforms.none; +  hydraPlatforms = lib.platforms.none;  }  | 
