diff options
author | Maxime Brunet <max@brnt.mx> | 2022-10-08 13:16:33 -0700 |
---|---|---|
committer | Maxime Brunet <max@brnt.mx> | 2022-11-16 15:26:21 -0800 |
commit | 29b5192b08744a6ff52484950384dd206368bc2e (patch) | |
tree | 6d7e5d796b60cae73ccd523e2ae8be7b3a4fc33d /nixos/modules/services/system | |
parent | 86018bc8368343e377cd1721bf30efbe85d362d6 (diff) | |
download | nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar.gz nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar.bz2 nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar.lz nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar.xz nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.tar.zst nixpkgs-29b5192b08744a6ff52484950384dd206368bc2e.zip |
automatic-timezoned: init at 1.0.41
Diffstat (limited to 'nixos/modules/services/system')
-rw-r--r-- | nixos/modules/services/system/automatic-timezoned.nix | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/nixos/modules/services/system/automatic-timezoned.nix b/nixos/modules/services/system/automatic-timezoned.nix new file mode 100644 index 00000000000..9bdd64dd33a --- /dev/null +++ b/nixos/modules/services/system/automatic-timezoned.nix @@ -0,0 +1,92 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.automatic-timezoned; +in +{ + options = { + services.automatic-timezoned = { + enable = mkOption { + type = types.bool; + default = false; + description = mdDoc '' + Enable `automatic-timezoned`, simple daemon for keeping the system + timezone up-to-date based on the current location. It uses geoclue2 to + determine the current location and systemd-timedated to actually set + the timezone. + ''; + }; + package = mkOption { + type = types.package; + default = pkgs.automatic-timezoned; + defaultText = literalExpression "pkgs.automatic-timezoned"; + description = mdDoc '' + Which `automatic-timezoned` package to use. + ''; + }; + }; + }; + + config = mkIf cfg.enable { + security.polkit.extraConfig = '' + polkit.addRule(function(action, subject) { + if (action.id == "org.freedesktop.timedate1.set-timezone" + && subject.user == "automatic-timezoned") { + return polkit.Result.YES; + } + }); + ''; + + services.geoclue2 = { + enable = true; + appConfig.automatic-timezoned = { + isAllowed = true; + isSystem = true; + users = [ (toString config.ids.uids.automatic-timezoned) ]; + }; + }; + + systemd.services = { + + automatic-timezoned = { + description = "Automatically update system timezone based on location"; + requires = [ "automatic-timezoned-geoclue-agent.service" ]; + after = [ "automatic-timezoned-geoclue-agent.service" ]; + serviceConfig = { + Type = "exec"; + User = "automatic-timezoned"; + ExecStart = "${cfg.package}/bin/automatic-timezoned --zoneinfo-path=${pkgs.tzdata}/share/zoneinfo/zone1970.tab"; + }; + wantedBy = [ "default.target" ]; + }; + + automatic-timezoned-geoclue-agent = { + description = "Geoclue agent for automatic-timezoned"; + requires = [ "geoclue.service" ]; + after = [ "geoclue.service" ]; + serviceConfig = { + Type = "exec"; + User = "automatic-timezoned"; + ExecStart = "${pkgs.geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/agent"; + Restart = "on-failure"; + PrivateTmp = true; + }; + wantedBy = [ "default.target" ]; + }; + + }; + + users = { + users.automatic-timezoned = { + description = "automatic-timezoned"; + uid = config.ids.uids.automatic-timezoned; + group = "automatic-timezoned"; + }; + groups.automatic-timezoned = { + gid = config.ids.gids.automatic-timezoned; + }; + }; + }; +} |