2014-04-24 23:32:32 +02:00
|
|
|
# GeoClue 2 daemon.
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
2018-08-09 16:29:07 +02:00
|
|
|
let
|
|
|
|
# the demo agent isn't built by default, but we need it here
|
|
|
|
package = pkgs.geoclue2.override { withDemoAgent = config.services.geoclue2.enableDemoAgent; };
|
2019-05-02 00:08:56 +02:00
|
|
|
|
|
|
|
cfg = config.services.geoclue2;
|
|
|
|
|
|
|
|
defaultWhitelist = [ "gnome-shell" "io.elementary.desktop.agent-geoclue2" ];
|
|
|
|
|
|
|
|
appConfigModule = types.submodule ({ name, ... }: {
|
|
|
|
options = {
|
|
|
|
desktopID = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
description = "Desktop ID of the application.";
|
|
|
|
};
|
|
|
|
|
|
|
|
isAllowed = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether the application will be allowed access to location information.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
isSystem = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
description = ''
|
|
|
|
Whether the application is a system component or not.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
type = types.listOf types.str;
|
|
|
|
default = [];
|
|
|
|
description = ''
|
|
|
|
List of UIDs of all users for which this application is allowed location
|
|
|
|
info access, Defaults to an empty string to allow it for all users.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config.desktopID = mkDefault name;
|
|
|
|
});
|
|
|
|
|
|
|
|
appConfigToINICompatible = _: { desktopID, isAllowed, isSystem, users, ... }: {
|
|
|
|
name = desktopID;
|
|
|
|
value = {
|
|
|
|
allowed = isAllowed;
|
|
|
|
system = isSystem;
|
|
|
|
users = concatStringsSep ";" users;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2018-08-09 16:29:07 +02:00
|
|
|
in
|
2014-04-24 23:32:32 +02:00
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.geoclue2 = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to enable GeoClue 2 daemon, a DBus service
|
2017-10-21 07:24:37 +02:00
|
|
|
that provides location information for accessing.
|
2014-04-24 23:32:32 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-09 16:29:07 +02:00
|
|
|
enableDemoAgent = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to use the GeoClue demo agent. This should be
|
|
|
|
overridden by desktop environments that provide their own
|
|
|
|
agent.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2019-05-02 00:08:56 +02:00
|
|
|
enableNmea = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to fetch location from NMEA sources on local network.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enable3G = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable 3G source.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableCDMA = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable CDMA source.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableModemGPS = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable Modem-GPS source.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
enableWifi = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = true;
|
|
|
|
description = ''
|
|
|
|
Whether to enable WiFi source.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
geoProviderUrl = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "https://location.services.mozilla.com/v1/geolocate?key=geoclue";
|
|
|
|
example = "https://www.googleapis.com/geolocation/v1/geolocate?key=YOUR_KEY";
|
|
|
|
description = ''
|
|
|
|
The url to the wifi GeoLocation Service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
submitData = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
|
|
|
description = ''
|
|
|
|
Whether to submit data to a GeoLocation Service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
submissionUrl = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "https://location.services.mozilla.com/v1/submit?key=geoclue";
|
|
|
|
description = ''
|
|
|
|
The url to submit data to a GeoLocation Service.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
submissionNick = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "geoclue";
|
|
|
|
description = ''
|
|
|
|
A nickname to submit network data with.
|
|
|
|
Must be 2-32 characters long.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
appConfig = mkOption {
|
2020-08-23 01:28:45 +02:00
|
|
|
type = types.attrsOf appConfigModule;
|
2019-05-02 00:08:56 +02:00
|
|
|
default = {};
|
2021-10-03 18:06:03 +02:00
|
|
|
example = literalExpression ''
|
2019-05-02 00:08:56 +02:00
|
|
|
"com.github.app" = {
|
|
|
|
isAllowed = true;
|
|
|
|
isSystem = true;
|
|
|
|
users = [ "300" ];
|
|
|
|
};
|
|
|
|
'';
|
|
|
|
description = ''
|
|
|
|
Specify extra settings per application.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2014-04-24 23:32:32 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
2019-05-02 00:08:56 +02:00
|
|
|
config = mkIf cfg.enable {
|
2014-04-24 23:32:32 +02:00
|
|
|
|
2018-08-09 16:29:07 +02:00
|
|
|
environment.systemPackages = [ package ];
|
|
|
|
|
|
|
|
services.dbus.packages = [ package ];
|
|
|
|
|
|
|
|
systemd.packages = [ package ];
|
2019-05-02 00:08:56 +02:00
|
|
|
|
2021-03-24 04:01:14 +01:00
|
|
|
# we cannot use DynamicUser as we need the the geoclue user to exist for the
|
|
|
|
# dbus policy to work
|
2019-10-30 03:50:52 +01:00
|
|
|
users = {
|
|
|
|
users.geoclue = {
|
|
|
|
isSystemUser = true;
|
|
|
|
home = "/var/lib/geoclue";
|
|
|
|
group = "geoclue";
|
|
|
|
description = "Geoinformation service";
|
|
|
|
};
|
2019-05-20 00:53:18 +02:00
|
|
|
|
2019-10-30 03:50:52 +01:00
|
|
|
groups.geoclue = {};
|
|
|
|
};
|
2019-05-20 00:53:18 +02:00
|
|
|
|
2019-10-30 03:50:52 +01:00
|
|
|
systemd.services.geoclue = {
|
2023-10-04 07:21:50 +02:00
|
|
|
wants = lib.optionals cfg.enableWifi [ "network-online.target" ];
|
2022-11-09 17:50:01 +01:00
|
|
|
after = lib.optionals cfg.enableWifi [ "network-online.target" ];
|
2019-10-30 03:50:52 +01:00
|
|
|
# restart geoclue service when the configuration changes
|
|
|
|
restartTriggers = [
|
|
|
|
config.environment.etc."geoclue/geoclue.conf".source
|
|
|
|
];
|
|
|
|
serviceConfig.StateDirectory = "geoclue";
|
|
|
|
};
|
2019-05-02 00:08:56 +02:00
|
|
|
|
2018-08-09 16:29:07 +02:00
|
|
|
# this needs to run as a user service, since it's associated with the
|
|
|
|
# user who is making the requests
|
2019-05-02 00:08:56 +02:00
|
|
|
systemd.user.services = mkIf cfg.enableDemoAgent {
|
2019-08-13 23:52:01 +02:00
|
|
|
geoclue-agent = {
|
2018-08-09 16:29:07 +02:00
|
|
|
description = "Geoclue agent";
|
|
|
|
# this should really be `partOf = [ "geoclue.service" ]`, but
|
|
|
|
# we can't be part of a system service, and the agent should
|
|
|
|
# be okay with the main service coming and going
|
|
|
|
wantedBy = [ "default.target" ];
|
2023-10-04 07:21:50 +02:00
|
|
|
wants = lib.optionals cfg.enableWifi [ "network-online.target" ];
|
2022-08-05 23:10:21 +02:00
|
|
|
after = lib.optionals cfg.enableWifi [ "network-online.target" ];
|
2021-03-24 04:01:14 +01:00
|
|
|
unitConfig.ConditionUser = "!@system";
|
2019-10-30 03:50:52 +01:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "exec";
|
|
|
|
ExecStart = "${package}/libexec/geoclue-2.0/demos/agent";
|
|
|
|
Restart = "on-failure";
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
2018-08-09 16:29:07 +02:00
|
|
|
};
|
|
|
|
};
|
2018-12-20 18:46:05 +01:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
services.geoclue2.appConfig.epiphany = {
|
2019-05-02 00:08:56 +02:00
|
|
|
isAllowed = true;
|
|
|
|
isSystem = false;
|
|
|
|
};
|
2014-04-24 23:32:32 +02:00
|
|
|
|
2019-08-13 23:52:01 +02:00
|
|
|
services.geoclue2.appConfig.firefox = {
|
2019-05-02 00:08:56 +02:00
|
|
|
isAllowed = true;
|
|
|
|
isSystem = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
environment.etc."geoclue/geoclue.conf".text =
|
|
|
|
generators.toINI {} ({
|
|
|
|
agent = {
|
|
|
|
whitelist = concatStringsSep ";"
|
|
|
|
(optional cfg.enableDemoAgent "geoclue-demo-agent" ++ defaultWhitelist);
|
|
|
|
};
|
|
|
|
network-nmea = {
|
|
|
|
enable = cfg.enableNmea;
|
|
|
|
};
|
|
|
|
"3g" = {
|
|
|
|
enable = cfg.enable3G;
|
|
|
|
};
|
|
|
|
cdma = {
|
|
|
|
enable = cfg.enableCDMA;
|
|
|
|
};
|
|
|
|
modem-gps = {
|
|
|
|
enable = cfg.enableModemGPS;
|
|
|
|
};
|
|
|
|
wifi = {
|
|
|
|
enable = cfg.enableWifi;
|
|
|
|
url = cfg.geoProviderUrl;
|
|
|
|
submit-data = boolToString cfg.submitData;
|
|
|
|
submission-url = cfg.submissionUrl;
|
|
|
|
submission-nick = cfg.submissionNick;
|
|
|
|
};
|
|
|
|
} // mapAttrs' appConfigToINICompatible cfg.appConfig);
|
|
|
|
};
|
2019-10-31 14:33:24 +01:00
|
|
|
|
2021-08-02 02:46:24 +02:00
|
|
|
meta = with lib; {
|
|
|
|
maintainers = with maintainers; [ ] ++ teams.pantheon.members;
|
|
|
|
};
|
2014-04-24 23:32:32 +02:00
|
|
|
}
|