From b0e184b0f0c069cb92469fcb23b89bf637d5ed68 Mon Sep 17 00:00:00 2001 From: Colin Date: Thu, 20 Jun 2024 11:35:26 +0000 Subject: [PATCH] geoclue: integrate ols/wigle as backend the wigle API limits are *strict*. probably too strict to actually be useful --- hosts/common/programs/default.nix | 1 + hosts/common/programs/geoclue-demo-agent.nix | 16 ++++++++++++++++ hosts/common/programs/geoclue2/default.nix | 13 +++++++++++-- hosts/common/programs/ols.nix | 13 +++++++++++-- 4 files changed, 39 insertions(+), 4 deletions(-) create mode 100644 hosts/common/programs/geoclue-demo-agent.nix diff --git a/hosts/common/programs/default.nix b/hosts/common/programs/default.nix index 6e834042..4337535f 100644 --- a/hosts/common/programs/default.nix +++ b/hosts/common/programs/default.nix @@ -53,6 +53,7 @@ ./gdb.nix ./gdbus.nix ./geary.nix + ./geoclue-demo-agent.nix ./geoclue2 ./git.nix ./gnome-clocks.nix diff --git a/hosts/common/programs/geoclue-demo-agent.nix b/hosts/common/programs/geoclue-demo-agent.nix new file mode 100644 index 00000000..d24ac28d --- /dev/null +++ b/hosts/common/programs/geoclue-demo-agent.nix @@ -0,0 +1,16 @@ +{ config, pkgs, ... }: +{ + sane.programs.geoclue-demo-agent = { + packageUnwrapped = pkgs.linkFarm "geoclue-demo-agent" [{ + # bring the demo agent into a `bin/` directory so it can be invokable via PATH + name = "bin/geoclue-demo-agent"; + path = "${config.sane.programs.geoclue2.packageUnwrapped}/libexec/geoclue-2.0/demos/agent"; + }]; + + services.geoclue-agent = { + description = "geoclue 'demo' agent"; + command = "geoclue-demo-agent"; + partOf = [ "graphical-session" ]; + }; + }; +} diff --git a/hosts/common/programs/geoclue2/default.nix b/hosts/common/programs/geoclue2/default.nix index 338cca1d..0cff96ad 100644 --- a/hosts/common/programs/geoclue2/default.nix +++ b/hosts/common/programs/geoclue2/default.nix @@ -1,11 +1,18 @@ # geoclue location services daemon. # -# HOW TO TEST (hopefully): +# HOW TO TEST: +# - just invoke `where-am-i`: it should output the current latitude/longitude. +## more manual testing: # - build `geoclue2-with-demo-agent` # - run the service: `systemctl start geoclue` or "${geoclue2-with-demo-agent}/libexec/geoclue" # - run "${geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/agent" # - keep this running in the background # - run "${geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/where-am-i" +# +# DATA FLOW: +# - geoclue2 does http calls into local `ols`, which either hits the local disk or queries https://wigle.net. +# - geoclue users like gnome-maps somehow depend on an "agent", +# a user service which launches the geoclue system service on-demand (via dbus activation). { config, lib, pkgs, ... }: let cfg = config.sane.programs.geoclue2; @@ -16,7 +23,9 @@ in # packageUnwrapped = pkgs.geoclue2.override { withDemoAgent = true; }; packageUnwrapped = pkgs.geoclue2-with-demo-agent; suggestedPrograms = [ - "where-am-i" + "geoclue-demo-agent" + "ols" #< WiFi SSID -> lat/long lookups + "where-am-i" #< handy debugging/testing tool ]; }; diff --git a/hosts/common/programs/ols.nix b/hosts/common/programs/ols.nix index 952191c0..024cb58c 100644 --- a/hosts/common/programs/ols.nix +++ b/hosts/common/programs/ols.nix @@ -1,7 +1,15 @@ # OLS: Offline Location Service: -{ ... }: +# fields {wifi SSID,cell tower} -> lat/long queries from geoclue +# satisfies queries via https://wigle.net, by learning about map tiles +# and caching those on-disk so that repeat queries may be serviced offline. +# +# it listens on localhost:8088, and one can validate its operation with a query like (substitute macAddresses for something real): +# curl -d '{"wifiAccessPoints":[{"macAddress":"01:23:45:67:89:ab","signalStrength":-78},{"macAddress":"cd:ef:01:23:45:56","signalStrength":-76}]}' http://127.0.0.1:8088/v1/geolocate +{ pkgs, ... }: { sane.programs.ols = { + packageUnwrapped = pkgs.python3Packages.ols; + persist.byStore.private = [ ".local/share/ols" ]; @@ -10,7 +18,8 @@ services.ols = { description = "ols: Offline Location Service"; - command = "ols -d debug"; + command = "ols"; + partOf = [ "graphical-session" ]; }; }; }