From c3b796ef793eed845da99a9518ec019df8a0a470 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Mon, 22 Jul 2024 22:25:25 +0100 Subject: [PATCH] add maps app (doesn't do much yet) --- configuration.nix | 2 + pkgs/maps/Makefile | 16 ++++++++ pkgs/maps/default.nix | 85 +++++++++++++++++++++++++++++++++++++++++++ pkgs/maps/main.fnl | 71 ++++++++++++++++++++++++++++++++++++ pkgs/maps/shell.nix | 9 +++++ 5 files changed, 183 insertions(+) create mode 100644 pkgs/maps/Makefile create mode 100644 pkgs/maps/default.nix create mode 100644 pkgs/maps/main.fnl create mode 100644 pkgs/maps/shell.nix diff --git a/configuration.nix b/configuration.nix index a558c6d..5bf0086 100644 --- a/configuration.nix +++ b/configuration.nix @@ -49,6 +49,7 @@ in { }); modemmanager-small = mm; satellite = prev.satellite.override { modemmanager = mm; }; + maps = final.callPackage ./pkgs/maps {}; }) ]; @@ -200,6 +201,7 @@ SUBSYSTEM=="wwan", ENV{DEVNAME}=="/dev/wwan0qmi0", ENV{DEVTYPE}=="wwan_port", \ satellite wlr-randr modemmanager-small + maps ]; users.users.dan = { diff --git a/pkgs/maps/Makefile b/pkgs/maps/Makefile new file mode 100644 index 0000000..48237d5 --- /dev/null +++ b/pkgs/maps/Makefile @@ -0,0 +1,16 @@ +FENNEL?=fennel +PREFIX?=/usr/local +NAME?=maps + +MODULES=main.fnl + +%.lua : %.fnl + $(FENNEL) --compile $< > $@ + +$(NAME): $(patsubst %.fnl,%.lua,$(MODULES)) Makefile + (echo -e "#!/usr/bin/env lua\n" ; cat main.lua ) > $@ + chmod +x $@ + +install: + mkdir -p $(PREFIX)/bin $(PREFIX)/ + cp $(NAME) $(PREFIX)/bin diff --git a/pkgs/maps/default.nix b/pkgs/maps/default.nix new file mode 100644 index 0000000..54e0e6c --- /dev/null +++ b/pkgs/maps/default.nix @@ -0,0 +1,85 @@ +{ stdenv +, pkg-config +, buildPackages +, callPackage +, clutter +, fetchFromGitHub +, fetchurl +, gobject-introspection +, gtk3 +, lib +, lua53Packages +, lua5_3 +, makeDesktopItem +, makeWrapper +, wrapGAppsHook3 +, writeText +, osm-gps-map +, glib-networking +, copyDesktopItems +}: +let + luaPackages = lua53Packages; + fennel = luaPackages.fennel; + lgi = luaPackages.buildLuaPackage { + pname = "lgi"; + version = "0.9.2-2"; + buildInputs = [ gobject-introspection ]; + nativeBuildInputs = [ pkg-config ]; + + src = fetchFromGitHub { + owner = "lgi-devs"; + repo = "lgi"; + rev = "e06ad94c8a1c84e3cdb80cee293450a280dfcbc7"; + hash = "sha256-VYr/DV1FAyzPe6p6Quc1nmsHup23IAMfz532rL167Q4="; + }; + }; + lua = lua5_3.withPackages (ps: with ps; [ + lgi + luafilesystem + luaposix + readline + ]); + pname = "maps"; +in stdenv.mkDerivation { + inherit pname; + version = "0.1"; + src =./.; + + buildInputs = [ + lua + gtk3.dev + gobject-introspection # .dev + osm-gps-map + glib-networking +# gdk-pixbuf + # glib +# libchamplain + ]; + nativeBuildInputs = [ + buildPackages.lua + gobject-introspection + makeWrapper + fennel + wrapGAppsHook3 + copyDesktopItems + ]; + GIO_EXTRA_MODULES = [ "${glib-networking.out}/lib/gio/modules" ]; + + makeFlags = [ "PREFIX=${placeholder "out"}" "NAME=${pname}" ]; + + postInstall = '' + mkdir -p $out/share/icons/ + cp icon.svg $out/share/icons/${pname}.svg + ''; + + desktopItems = [ + (makeDesktopItem { + name = pname; + desktopName = "Maps"; + exec = pname; + type = "Application"; + icon = "nix-snowflake"; # "${placeholder "out"}/share/icons/${pname}.svg"; + }) + ]; +} diff --git a/pkgs/maps/main.fnl b/pkgs/maps/main.fnl new file mode 100644 index 0000000..aaa0b51 --- /dev/null +++ b/pkgs/maps/main.fnl @@ -0,0 +1,71 @@ +; (local { : view } (require :fennel)) + +(local { + : Gtk + : OsmGpsMap + : Gdk + } + (require :lgi)) + +(local CSS " +label.readout { + font: 48px \"Noto Sans\"; + margin: 10px; + padding: 5px; + background-color: rgba(0, 0, 0, 0.2); +} +") + +(fn styles [] + (let [style_provider (Gtk.CssProvider)] + (Gtk.StyleContext.add_provider_for_screen + (Gdk.Screen.get_default) + style_provider + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ) + (style_provider:load_from_data CSS))) + +(local window (Gtk.Window { + :title "Map" + :name "toplevel" + :default_width 720 + :default_height 800 + + :on_destroy Gtk.main_quit + })) + +(fn osm-widget [] + (doto (OsmGpsMap.Map {}) + (tset :map-source OsmGpsMap.MapSource_t.OPENSTREETMAP) + (: :set_center_and_zoom 52.595 -0.1 14) + (: :layer_add (OsmGpsMap.MapOsd { + :show_copyright true + ; :show_coordinates true + :show_scale true + })) + )) + +(fn readout [text] + (doto (Gtk.Label {:label text}) + (-> (: :get_style_context) (: :add_class :readout)))) + +(fn readouts [] + (doto (Gtk.Box + { + :orientation Gtk.Orientation.VERTICAL + :halign Gtk.Align.END + }) + (-> (: :get_style_context) (: :add_class :readouts)) + (: :add (readout "21:05:00")) + (: :add (readout "00:00")) + (: :add (readout "25 km/h")))) + +(window:add + (doto (Gtk.Overlay {}) + (: :add (osm-widget)) + (: :add_overlay (readouts)) + )) + +(window:show_all) +(styles) +(Gtk:main) diff --git a/pkgs/maps/shell.nix b/pkgs/maps/shell.nix new file mode 100644 index 0000000..0ce9d22 --- /dev/null +++ b/pkgs/maps/shell.nix @@ -0,0 +1,9 @@ +with import {}; +let package = pkgs.callPackage ./. {}; +in +package.overrideAttrs(o: { + shellHook = '' + export LUA_CPATH=$(lua -e "print(package.cpath)") + export LUA_PATH=$(lua -e "print(package.path)") + ''; +})