Skip to content

Commit

Permalink
Initial release version
Browse files Browse the repository at this point in the history
  • Loading branch information
jensbin committed Oct 22, 2024
1 parent f4e7328 commit 4112efe
Show file tree
Hide file tree
Showing 7 changed files with 422 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
layout node
use nix
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,5 @@ Cargo.lock
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
#.idea/
.direnv/
14 changes: 14 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
[package]
name="cheap-ichnaea"
version="0.2.1"
edition="2021"

[dependencies]
actix-web = "4"
async-std = "1.13.0"
clap = { version = "4.5.18", features = ["derive"] }
env_logger = "0.11.5"
log = "0.4.22"
reqwest = { version = "0.12.7", features = ["blocking"] }
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0.128"
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# What is good for?

As a geolocation service to feed geloclue2. I only use geoclue2 to update the
timezone information on my device.
With the retirement of the Mozilla Location Service
(https://github.com/mozilla/ichnaea/issues/2065) the only option was to move
to Google Location Service.

I don't need accurate location data for timezone, the
[ip-api](https://ip-api.com service) service suits well enough.
So I build this local service.

# How to use it?
Start the service and adjust the `url` in `/etc/geoclue/geoclue.conf`

```
url=http://localhost:8080/v1/geolocate
```

```
Usage: cheap-ichnaea [OPTIONS]
Options:
-p, --port <PORT> The port number to listen on [default: 8080]
-t, --ttl-cache <TTL_CACHE> Cache TTL in seconds [default: 1800]
-h, --help Print help
-V, --version Print version
```

# Features

- Caching of responses (`--ttl-cache 3200`)
- Retrying to connect, when connection fails
56 changes: 56 additions & 0 deletions default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{ lib
, rustPlatform
, openssl
, pkg-config
}:
let
fs = lib.fileset;
# sourceFiles = ./.;
# sourceFiles = fs.gitTracked ./.;
sourceFiles = fs.unions [
./Cargo.toml
./Cargo.lock
./src/main.rs
# (fs.fileFilter
# (file: file.hasExt "rs")
# ./src
# )
];
in
rustPlatform.buildRustPackage {
pname = "cheap-ichnaea";
version = "0.2.1";

src = fs.toSource {
root = ./.;
fileset = sourceFiles;
};

# cargoHash = lib.fakeHash;
cargoLock = {
lockFile = ./Cargo.lock;
};

nativeBuildInputs = [
pkg-config
];

buildInputs = [
openssl
];

installPhase = ''
runHook preInstall
find .
install -D -t $out/bin target/x86_64-unknown-linux-gnu/release/cheap-ichnaea
runHook postInstall
'';
#doCheck = false;

meta = with lib; {
description = "Cheap ichnaea service";
license = licenses.mit;
};
}
15 changes: 15 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#with ( import <nixpkgs> {});
#{ nodeEnv, fetchgit, pkgs ? import <nixpkgs> {} }:
{ pkgs ? import <nixpkgs> {} }:

pkgs.mkShell {
buildInputs = [
pkgs.cargo
pkgs.pkg-config
pkgs.openssl
];

shellHook = ''
echo "cat countries.json | jq '.[] | {iso2, latitude, longitude}' | jq -c -s . > countries_opt.json"
'';
}
Loading

0 comments on commit 4112efe

Please sign in to comment.