From 71fa63eaa77c45850c75da7c7d32fbb442cf2663 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 27 May 2025 13:11:48 +0100 Subject: [PATCH 1/4] stolen from liminix --- pkgs/rxi-json/default.nix | 15 +++++++++++++++ pkgs/rxi-json/default.nix~ | 14 ++++++++++++++ 2 files changed, 29 insertions(+) create mode 100644 pkgs/rxi-json/default.nix create mode 100644 pkgs/rxi-json/default.nix~ diff --git a/pkgs/rxi-json/default.nix b/pkgs/rxi-json/default.nix new file mode 100644 index 0000000..7af9d1a --- /dev/null +++ b/pkgs/rxi-json/default.nix @@ -0,0 +1,15 @@ +{ + fetchurl, + runCommand, + lua, +}: +let + src = fetchurl { + url = "https://raw.githubusercontent.com/rxi/json.lua/11077824d7cfcd28a4b2f152518036b295e7e4ce/json.lua"; + hash = "sha256-DqzNpX+rwDMHNt4l9Fz1iYIaQrXg/gLk4xJffcC/K34="; + }; +in +runCommand "json" { } '' + mkdir -p $out/share/lua/${lua.luaversion}/ + cp ${src} $out/share/lua/${lua.luaversion}/json.lua +'' diff --git a/pkgs/rxi-json/default.nix~ b/pkgs/rxi-json/default.nix~ new file mode 100644 index 0000000..be0fe46 --- /dev/null +++ b/pkgs/rxi-json/default.nix~ @@ -0,0 +1,14 @@ +{ + fetchurl, + runCommand, + lua, +}: +let + src = fetchurl { + url = "https://raw.githubusercontent.com/rxi/json.lua/11077824d7cfcd28a4b2f152518036b295e7e4ce/json.lua"; + hash = "sha256-DqzNpX+rwDMHNt4l9Fz1iYIaQrXg/gLk4xJffcC/K34="; + }; +in runCommand "json" {} '' + mkdir -p $out/share/lua/${lua.luaversion}/ + cp ${src} $out/share/lua/${lua.luaversion}/json.lua +''; From a2906f515052967edb10757e080555036b807eb8 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 27 May 2025 13:12:12 +0100 Subject: [PATCH 2/4] http request to overpass --- pkgs/maps/tiles.fnl | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 pkgs/maps/tiles.fnl diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl new file mode 100644 index 0000000..29a516c --- /dev/null +++ b/pkgs/maps/tiles.fnl @@ -0,0 +1,32 @@ +(local req (require :http.request)) +(local { : dict_to_query } (require :http.util)) +(local { : view } (require :fennel)) + +(local + query + (-> + [ + "[bbox:30.618338,-96.323712,30.591028,-96.330826]" + "[out:json]" + "[timeout:90];" + "(" + "way (" + "30.626917110746," + "-96.348809105664," + "30.634468750236," + "-96.339893442898" + ");" + ");" + "out geom;" + ] + (table.concat "\n"))) + +(let [r + (req.new_from_uri + "https://overpass-api.de/api/interpreter")] + (tset r.headers ":method" "POST") + (r:set_body (dict_to_query { :data query })) + (let [(headers stream) (r:go)] + (print (view headers)) + (print (stream:get_body_as_string)))) + From 26ebbe21b5cbc074adfeddf2b4f6c6e836888f2d Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 27 May 2025 13:31:54 +0100 Subject: [PATCH 3/4] hack in rxi-json --- pkgs/maps/default.nix | 11 ++++++----- pkgs/maps/shell.nix | 2 +- pkgs/maps/tiles.fnl | 3 +++ 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/pkgs/maps/default.nix b/pkgs/maps/default.nix index 54e0e6c..8bb3815 100644 --- a/pkgs/maps/default.nix +++ b/pkgs/maps/default.nix @@ -34,11 +34,14 @@ let hash = "sha256-VYr/DV1FAyzPe6p6Quc1nmsHup23IAMfz532rL167Q4="; }; }; + rxi-json = callPackage ../rxi-json { lua = lua5_3; }; lua = lua5_3.withPackages (ps: with ps; [ lgi luafilesystem luaposix readline + http + rxi-json ]); pname = "maps"; in stdenv.mkDerivation { @@ -49,15 +52,12 @@ in stdenv.mkDerivation { buildInputs = [ lua gtk3.dev - gobject-introspection # .dev + gobject-introspection osm-gps-map glib-networking -# gdk-pixbuf - # glib -# libchamplain ]; nativeBuildInputs = [ - buildPackages.lua +# lua gobject-introspection makeWrapper fennel @@ -65,6 +65,7 @@ in stdenv.mkDerivation { copyDesktopItems ]; GIO_EXTRA_MODULES = [ "${glib-networking.out}/lib/gio/modules" ]; + RXI_JSON="${rxi-json}/"; makeFlags = [ "PREFIX=${placeholder "out"}" "NAME=${pname}" ]; diff --git a/pkgs/maps/shell.nix b/pkgs/maps/shell.nix index 0ce9d22..ec8d430 100644 --- a/pkgs/maps/shell.nix +++ b/pkgs/maps/shell.nix @@ -4,6 +4,6 @@ in package.overrideAttrs(o: { shellHook = '' export LUA_CPATH=$(lua -e "print(package.cpath)") - export LUA_PATH=$(lua -e "print(package.path)") + export LUA_PATH=$(lua -e "print(package.path)")\;$RXI_JSON/share/lua/5.3/?.lua ''; }) diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl index 29a516c..81e4f44 100644 --- a/pkgs/maps/tiles.fnl +++ b/pkgs/maps/tiles.fnl @@ -1,7 +1,10 @@ (local req (require :http.request)) (local { : dict_to_query } (require :http.util)) +(local json (require :json)) + (local { : view } (require :fennel)) + (local query (-> From 184ba482f90c93460be4bd19e300bf9c1d08182c Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Tue, 27 May 2025 13:34:09 +0100 Subject: [PATCH 4/4] and decode --- pkgs/maps/tiles.fnl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkgs/maps/tiles.fnl b/pkgs/maps/tiles.fnl index 81e4f44..fe50eda 100644 --- a/pkgs/maps/tiles.fnl +++ b/pkgs/maps/tiles.fnl @@ -20,7 +20,7 @@ "-96.339893442898" ");" ");" - "out geom;" + "out ;" ] (table.concat "\n"))) @@ -31,5 +31,5 @@ (r:set_body (dict_to_query { :data query })) (let [(headers stream) (r:go)] (print (view headers)) - (print (stream:get_body_as_string)))) + (print (view (json.decode (stream:get_body_as_string))))))