at 25.11-pre 2.9 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7let 8 cfg = config.services.automatic-timezoned; 9in 10{ 11 options = { 12 services.automatic-timezoned = { 13 enable = lib.mkOption { 14 type = lib.types.bool; 15 default = false; 16 description = '' 17 Enable `automatic-timezoned`, simple daemon for keeping the system 18 timezone up-to-date based on the current location. It uses geoclue2 to 19 determine the current location and systemd-timedated to actually set 20 the timezone. 21 22 To avoid silent overriding by the service, if you have explicitly set a 23 timezone, either remove it or ensure that it is set with a lower priority 24 than the default value using `lib.mkDefault` or `lib.mkOverride`. This is 25 to make the choice deliberate. An error will be presented otherwise. 26 ''; 27 }; 28 package = lib.mkPackageOption pkgs "automatic-timezoned" { }; 29 }; 30 }; 31 32 config = lib.mkIf cfg.enable { 33 # This will give users an error if they have set an explicit time 34 # zone, rather than having the service silently override it. 35 time.timeZone = null; 36 37 security.polkit.extraConfig = '' 38 polkit.addRule(function(action, subject) { 39 if (action.id == "org.freedesktop.timedate1.set-timezone" 40 && subject.user == "automatic-timezoned") { 41 return polkit.Result.YES; 42 } 43 }); 44 ''; 45 46 services.geoclue2 = { 47 enable = true; 48 appConfig.automatic-timezoned = { 49 isAllowed = true; 50 isSystem = true; 51 users = [ (toString config.ids.uids.automatic-timezoned) ]; 52 }; 53 }; 54 55 systemd.services = { 56 57 automatic-timezoned = { 58 description = "Automatically update system timezone based on location"; 59 requires = [ "automatic-timezoned-geoclue-agent.service" ]; 60 after = [ "automatic-timezoned-geoclue-agent.service" ]; 61 serviceConfig = { 62 Type = "exec"; 63 User = "automatic-timezoned"; 64 ExecStart = "${cfg.package}/bin/automatic-timezoned"; 65 }; 66 wantedBy = [ "default.target" ]; 67 }; 68 69 automatic-timezoned-geoclue-agent = { 70 description = "Geoclue agent for automatic-timezoned"; 71 requires = [ "geoclue.service" ]; 72 after = [ "geoclue.service" ]; 73 serviceConfig = { 74 Type = "exec"; 75 User = "automatic-timezoned"; 76 ExecStart = "${pkgs.geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/agent"; 77 Restart = "on-failure"; 78 PrivateTmp = true; 79 }; 80 wantedBy = [ "default.target" ]; 81 }; 82 83 }; 84 85 users = { 86 users.automatic-timezoned = { 87 description = "automatic-timezoned"; 88 uid = config.ids.uids.automatic-timezoned; 89 group = "automatic-timezoned"; 90 }; 91 groups.automatic-timezoned = { 92 gid = config.ids.gids.automatic-timezoned; 93 }; 94 }; 95 }; 96}