From cc479ee57e2f5124db21bd76f0a9467c6fdf1e13 Mon Sep 17 00:00:00 2001 From: NullBite Date: Tue, 29 Oct 2024 13:18:02 +0100 Subject: [PATCH] system: add gps module --- system/hardware/default.nix | 1 + system/hardware/gps.nix | 48 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 system/hardware/gps.nix diff --git a/system/hardware/default.nix b/system/hardware/default.nix index a7e71c8..1d1362b 100644 --- a/system/hardware/default.nix +++ b/system/hardware/default.nix @@ -6,5 +6,6 @@ ./opengl.nix ./sound.nix ./binfmt.nix + ./gps.nix ]; } diff --git a/system/hardware/gps.nix b/system/hardware/gps.nix new file mode 100644 index 0000000..ff9762c --- /dev/null +++ b/system/hardware/gps.nix @@ -0,0 +1,48 @@ +{ config, lib, pkgs, ... }: +let + cfg = config.nixfiles.hardware.gps; +in +{ + options = { + nixfiles.hardware.gps = { + enable = lib.mkEnableOption "GPS configuration"; + gpsdBridge = lib.mkOption { + description = "Whether to enable bridging of gpsd data to Geoclue2"; + default = true; + example = false; + type = lib.types.bool; + }; + }; + }; + + config = lib.mkIf cfg.enable { + services.geoclue2 = { + enable = true; + }; + + environment.etc."geoclue/conf.d/00-nmea-socket.conf".text = lib.mkIf cfg.gpsdBridge '' + [network-nmea] + enable=true + nmea-socket=/run/gpsd-nmea/nmea.sock + ''; + + # this could probably be a systemd socket but i don't know how to make those + systemd.services.gpsd-nmea-bridge = lib.mkIf cfg.gpsdBridge { + path = with pkgs; [ + gpsd + coreutils + socat + ]; + description = "gpsd to Geoclue2 GPS data bridge"; + before = [ "geoclue.service" ]; + wantedBy = [ "geoclue.service" "multi-user.target" ]; + serviceConfig = { + RuntimeDirectory = "gpsd-nmea"; + ExecStart = pkgs.writeShellScript "gpsd-nmea-bridge" " + exec socat -U UNIX-LISTEN:\${RUNTIME_DIRECTORY}/nmea.sock,fork,reuseaddr,mode=777 SYSTEM:'gpspipe -Br | stdbuf -oL tail -n+4' + "; + }; + }; + services.gpsd.enable = lib.mkIf cfg.gpsdBridge true; + }; +}