Skip to content

Commit

Permalink
nixos/services.geoclue2: remove with lib;
Browse files Browse the repository at this point in the history
  • Loading branch information
Stunkymonkey committed Dec 8, 2024
1 parent eeda338 commit e693f4b
Showing 1 changed file with 46 additions and 50 deletions.
96 changes: 46 additions & 50 deletions nixos/modules/services/desktops/geoclue2.nix
Original file line number Diff line number Diff line change
@@ -1,37 +1,33 @@
# GeoClue 2 daemon.

{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.services.geoclue2;

defaultWhitelist = [ "gnome-shell" "io.elementary.desktop.agent-geoclue2" ];

appConfigModule = types.submodule ({ name, ... }: {
appConfigModule = lib.types.submodule ({ name, ... }: {
options = {
desktopID = mkOption {
type = types.str;
desktopID = lib.mkOption {
type = lib.types.str;
description = "Desktop ID of the application.";
};

isAllowed = mkOption {
type = types.bool;
isAllowed = lib.mkOption {
type = lib.types.bool;
description = ''
Whether the application will be allowed access to location information.
'';
};

isSystem = mkOption {
type = types.bool;
isSystem = lib.mkOption {
type = lib.types.bool;
description = ''
Whether the application is a system component or not.
'';
};

users = mkOption {
type = types.listOf types.str;
users = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = ''
List of UIDs of all users for which this application is allowed location
Expand All @@ -40,15 +36,15 @@ let
};
};

config.desktopID = mkDefault name;
config.desktopID = lib.mkDefault name;
});

appConfigToINICompatible = _: { desktopID, isAllowed, isSystem, users, ... }: {
name = desktopID;
value = {
allowed = isAllowed;
system = isSystem;
users = concatStringsSep ";" users;
users = lib.concatStringsSep ";" users;
};
};

Expand All @@ -61,17 +57,17 @@ in

services.geoclue2 = {

enable = mkOption {
type = types.bool;
enable = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to enable GeoClue 2 daemon, a DBus service
that provides location information for accessing.
'';
};

enableDemoAgent = mkOption {
type = types.bool;
enableDemoAgent = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to use the GeoClue demo agent. This should be
Expand All @@ -80,95 +76,95 @@ in
'';
};

enableNmea = mkOption {
type = types.bool;
enableNmea = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to fetch location from NMEA sources on local network.
'';
};

enable3G = mkOption {
type = types.bool;
enable3G = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable 3G source.
'';
};

enableCDMA = mkOption {
type = types.bool;
enableCDMA = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable CDMA source.
'';
};

enableModemGPS = mkOption {
type = types.bool;
enableModemGPS = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable Modem-GPS source.
'';
};

enableWifi = mkOption {
type = types.bool;
enableWifi = lib.mkOption {
type = lib.types.bool;
default = true;
description = ''
Whether to enable WiFi source.
'';
};

geoProviderUrl = mkOption {
type = types.str;
geoProviderUrl = lib.mkOption {
type = lib.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.
'';
};

package = mkOption {
type = types.package;
package = lib.mkOption {
type = lib.types.package;
default = pkgs.geoclue2;
defaultText = literalExpression "pkgs.geoclue2";
defaultText = lib.literalExpression "pkgs.geoclue2";
apply = pkg: pkg.override {
# the demo agent isn't built by default, but we need it here
withDemoAgent = cfg.enableDemoAgent;
};
description = "The geoclue2 package to use";
};

submitData = mkOption {
type = types.bool;
submitData = lib.mkOption {
type = lib.types.bool;
default = false;
description = ''
Whether to submit data to a GeoLocation Service.
'';
};

submissionUrl = mkOption {
type = types.str;
submissionUrl = lib.mkOption {
type = lib.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;
submissionNick = lib.mkOption {
type = lib.types.str;
default = "geoclue";
description = ''
A nickname to submit network data with.
Must be 2-32 characters long.
'';
};

appConfig = mkOption {
type = types.attrsOf appConfigModule;
appConfig = lib.mkOption {
type = lib.types.attrsOf appConfigModule;
default = {};
example = literalExpression ''
example = lib.literalExpression ''
"com.github.app" = {
isAllowed = true;
isSystem = true;
Expand All @@ -186,7 +182,7 @@ in


###### implementation
config = mkIf cfg.enable {
config = lib.mkIf cfg.enable {

environment.systemPackages = [ cfg.package ];

Expand Down Expand Up @@ -219,7 +215,7 @@ in

# this needs to run as a user service, since it's associated with the
# user who is making the requests
systemd.user.services = mkIf cfg.enableDemoAgent {
systemd.user.services = lib.mkIf cfg.enableDemoAgent {
geoclue-agent = {
description = "Geoclue agent";
# this should really be `partOf = [ "geoclue.service" ]`, but
Expand Down Expand Up @@ -249,10 +245,10 @@ in
};

environment.etc."geoclue/geoclue.conf".text =
generators.toINI {} ({
lib.generators.toINI {} ({
agent = {
whitelist = concatStringsSep ";"
(optional cfg.enableDemoAgent "geoclue-demo-agent" ++ defaultWhitelist);
whitelist = lib.concatStringsSep ";"
(lib.optional cfg.enableDemoAgent "geoclue-demo-agent" ++ defaultWhitelist);
};
network-nmea = {
enable = cfg.enableNmea;
Expand All @@ -269,11 +265,11 @@ in
wifi = {
enable = cfg.enableWifi;
url = cfg.geoProviderUrl;
submit-data = boolToString cfg.submitData;
submit-data = lib.boolToString cfg.submitData;
submission-url = cfg.submissionUrl;
submission-nick = cfg.submissionNick;
};
} // mapAttrs' appConfigToINICompatible cfg.appConfig);
} // lib.mapAttrs' appConfigToINICompatible cfg.appConfig);
};

meta = with lib; {
Expand Down

0 comments on commit e693f4b

Please sign in to comment.