Skip to content

Commit

Permalink
Merge pull request #979 from tiiuae/fix-location-sharing
Browse files Browse the repository at this point in the history
Fix Element location sharing
  • Loading branch information
brianmcgillion authored Jan 30, 2025
2 parents 59dd1b5 + 613005d commit 1eb21a9
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 3 deletions.
38 changes: 35 additions & 3 deletions modules/reference/appvms/comms.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
...
}:
let
inherit (lib) hasAttr optionals;
inherit (lib) hasAttr optionals mkForce;
in
{
name = "comms";
Expand Down Expand Up @@ -69,12 +69,44 @@ in
# GPSD collects data from GPS and makes it available on TCP port 2947
services.gpsd = {
enable = true;
# Give the ttyUSB0 device for gpsd in case gps was plugged in from boot
# This doesn't affect anything if device is not available
devices = [ "/dev/ttyUSB0" ];
# Use safer read-only mode
readonly = true;
debugLevel = 2;
# Set debug level to zero so gpsd won't flood the logs unnecessarily
debugLevel = 0;
# Listen on all IP-addresses
listenany = true;
extraArgs = [ "-n" ]; # Do not wait for a client to connect before polling
# Do not wait for a client to connect before polling
nowait = true;
# Give gpsd the control socket to use, so it will keep running even if there are no gps devices connected
extraArgs = [
"-F"
"/var/run/gpsd.sock"
];
};
services.udev.extraRules =
let
gps = lib.filter (d: d.name == "gps0") config.ghaf.hardware.definition.usb.external;
in
if gps != [ ] then
let
VID = (builtins.head gps).vendorId;
PID = (builtins.head gps).productId;
in
# When USB gps device is inserted run gpsdctl to add the device to gpsd, so it starts monitoring it
# (Note that this will be run way before gpsd service is running, if device is already connected when booting.
# This does not seem to have any negative effects though)
''
ACTION=="add", ENV{ID_BUS}=="usb", ENV{ID_VENDOR_ID}=="${VID}", ENV{ID_MODEL_ID}=="${PID}", ENV{DEVNAME}=="/dev/ttyUSB*", RUN+="${pkgs.gpsd}/bin/gpsdctl add '%E{DEVNAME}'"
''
else
null;
# Disable serial debug console on comms-vm as it makes the serial device owned by
# 'tty' group. gpsd runs hardcoded with effective gid of 'dialout' group, and thus
# can't access the device if this is enabled.
ghaf.development.usb-serial.enable = mkForce false;
}
];
}
4 changes: 4 additions & 0 deletions modules/reference/programs/element-desktop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ in
element-gps = {
description = "Element-gps is a GPS location provider for Element websocket interface.";
enable = true;
# Make sure this service is started after gpsd is running
requires = [ "gpsd.service" ];
after = [ "gpsd.service" ];

serviceConfig = {
Type = "simple";
ExecStart = "${pkgs.element-gps}/bin/main.py";
Expand Down

0 comments on commit 1eb21a9

Please sign in to comment.