1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.services.automatic-timezoned;
7in
8{
9 options = {
10 services.automatic-timezoned = {
11 enable = mkOption {
12 type = types.bool;
13 default = false;
14 description = ''
15 Enable `automatic-timezoned`, simple daemon for keeping the system
16 timezone up-to-date based on the current location. It uses geoclue2 to
17 determine the current location and systemd-timedated to actually set
18 the timezone.
19 '';
20 };
21 package = mkPackageOption pkgs "automatic-timezoned" { };
22 };
23 };
24
25 config = mkIf cfg.enable {
26 security.polkit.extraConfig = ''
27 polkit.addRule(function(action, subject) {
28 if (action.id == "org.freedesktop.timedate1.set-timezone"
29 && subject.user == "automatic-timezoned") {
30 return polkit.Result.YES;
31 }
32 });
33 '';
34
35 services.geoclue2 = {
36 enable = true;
37 appConfig.automatic-timezoned = {
38 isAllowed = true;
39 isSystem = true;
40 users = [ (toString config.ids.uids.automatic-timezoned) ];
41 };
42 };
43
44 systemd.services = {
45
46 automatic-timezoned = {
47 description = "Automatically update system timezone based on location";
48 requires = [ "automatic-timezoned-geoclue-agent.service" ];
49 after = [ "automatic-timezoned-geoclue-agent.service" ];
50 serviceConfig = {
51 Type = "exec";
52 User = "automatic-timezoned";
53 ExecStart = "${cfg.package}/bin/automatic-timezoned";
54 };
55 wantedBy = [ "default.target" ];
56 };
57
58 automatic-timezoned-geoclue-agent = {
59 description = "Geoclue agent for automatic-timezoned";
60 requires = [ "geoclue.service" ];
61 after = [ "geoclue.service" ];
62 serviceConfig = {
63 Type = "exec";
64 User = "automatic-timezoned";
65 ExecStart = "${pkgs.geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/agent";
66 Restart = "on-failure";
67 PrivateTmp = true;
68 };
69 wantedBy = [ "default.target" ];
70 };
71
72 };
73
74 users = {
75 users.automatic-timezoned = {
76 description = "automatic-timezoned";
77 uid = config.ids.uids.automatic-timezoned;
78 group = "automatic-timezoned";
79 };
80 groups.automatic-timezoned = {
81 gid = config.ids.gids.automatic-timezoned;
82 };
83 };
84 };
85}