about summary refs log tree commit diff
path: root/nixos
diff options
context:
space:
mode:
authorBernardo Meurer <bernardo@meurer.org>2022-08-13 12:57:35 -0700
committerGitHub <noreply@github.com>2022-08-13 12:57:35 -0700
commit8979e6cc6901a3c3a0fa483ea997c84924d2f7f8 (patch)
treedc5bb4790d7d4f918432f012b7c3ca29f277f1f3 /nixos
parent0cf5cd886164b9fa3679c8b9f4831104a2ff3a2b (diff)
parent5975411744eb1e46bf07a3e1d08ab0c3ae0b432b (diff)
Merge pull request #186369 from lovesegfault/fix-localtime-service
Diffstat (limited to 'nixos')
-rw-r--r--nixos/modules/misc/ids.nix2
-rw-r--r--nixos/modules/module-list.nix2
-rw-r--r--nixos/modules/services/system/localtime.nix37
-rw-r--r--nixos/modules/services/system/localtimed.nix66
4 files changed, 69 insertions, 38 deletions
diff --git a/nixos/modules/misc/ids.nix b/nixos/modules/misc/ids.nix
index e3d7866cabb51..38ab338aa56cd 100644
--- a/nixos/modules/misc/ids.nix
+++ b/nixos/modules/misc/ids.nix
@@ -354,6 +354,7 @@ in
       webdav = 322;
       pipewire = 323;
       rstudio-server = 324;
+      localtimed = 325;
 
       # When adding a uid, make sure it doesn't match an existing gid. And don't use uids above 399!
 
@@ -662,6 +663,7 @@ in
       webdav = 322;
       pipewire = 323;
       rstudio-server = 324;
+      localtimed = 325;
 
       # When adding a gid, make sure it doesn't match an existing
       # uid. Users and groups with the same name should have equal
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 6e979561fa032..837bc7635a068 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -1023,7 +1023,7 @@
   ./services/system/cloud-init.nix
   ./services/system/dbus.nix
   ./services/system/earlyoom.nix
-  ./services/system/localtime.nix
+  ./services/system/localtimed.nix
   ./services/system/kerberos/default.nix
   ./services/system/nscd.nix
   ./services/system/saslauthd.nix
diff --git a/nixos/modules/services/system/localtime.nix b/nixos/modules/services/system/localtime.nix
deleted file mode 100644
index c80fe366453ee..0000000000000
--- a/nixos/modules/services/system/localtime.nix
+++ /dev/null
@@ -1,37 +0,0 @@
-{ config, lib, pkgs, ... }:
-
-with lib;
-
-let
-  cfg = config.services.localtimed;
-in {
-  imports = [ (lib.mkRenamedOptionModule [ "services" "localtime" ] [ "services" "localtimed" ]) ];
-
-  options = {
-    services.localtimed = {
-      enable = mkOption {
-        type = types.bool;
-        default = false;
-        description = lib.mdDoc ''
-          Enable `localtimed`, a simple daemon for keeping the
-          system timezone up-to-date based on the current location. It uses
-          geoclue2 to determine the current location.
-        '';
-      };
-    };
-  };
-
-  config = mkIf cfg.enable {
-    services.geoclue2.appConfig.localtimed = {
-      isAllowed = true;
-      isSystem = true;
-    };
-
-    # Install the polkit rules.
-    environment.systemPackages = [ pkgs.localtime ];
-    # Install the systemd unit.
-    systemd.packages = [ pkgs.localtime ];
-
-    systemd.services.localtime.wantedBy = [ "multi-user.target" ];
-  };
-}
diff --git a/nixos/modules/services/system/localtimed.nix b/nixos/modules/services/system/localtimed.nix
new file mode 100644
index 0000000000000..345bdbd8dda01
--- /dev/null
+++ b/nixos/modules/services/system/localtimed.nix
@@ -0,0 +1,66 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.localtimed;
+in {
+  imports = [ (lib.mkRenamedOptionModule [ "services" "localtime" ] [ "services" "localtimed" ]) ];
+
+  options = {
+    services.localtimed = {
+      enable = mkOption {
+        type = types.bool;
+        default = false;
+        description = lib.mdDoc ''
+          Enable `localtimed`, a simple daemon for keeping the
+          system timezone up-to-date based on the current location. It uses
+          geoclue2 to determine the current location.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    services.geoclue2.appConfig.localtimed = {
+      isAllowed = true;
+      isSystem = true;
+      users = [ (toString config.ids.uids.localtimed) ];
+    };
+
+    # Install the polkit rules.
+    environment.systemPackages = [ pkgs.localtime ];
+
+    systemd.services.localtimed = {
+      wantedBy = [ "multi-user.target" ];
+      partOf = [ "localtimed-geoclue-agent.service" ];
+      after = [ "localtimed-geoclue-agent.service" ];
+      serviceConfig = {
+        ExecStart = "${pkgs.localtime}/bin/localtimed";
+        Restart = "on-failure";
+        Type = "exec";
+        User = "localtimed";
+      };
+    };
+
+    systemd.services.localtimed-geoclue-agent = {
+      wantedBy = [ "multi-user.target" ];
+      partOf = [ "geoclue.service" ];
+      after = [ "geoclue.service" ];
+      serviceConfig = {
+        ExecStart = "${pkgs.geoclue2-with-demo-agent}/libexec/geoclue-2.0/demos/agent";
+        Restart = "on-failure";
+        Type = "exec";
+        User = "localtimed";
+      };
+    };
+
+    users = {
+      users.localtimed = {
+        uid = config.ids.uids.localtimed;
+        group = "localtimed";
+      };
+      groups.localtimed.gid = config.ids.gids.localtimed;
+    };
+  };
+}