summary refs log tree commit diff
diff options
context:
space:
mode:
authorDomen Kožar <domen@dev.si>2017-12-03 11:41:22 +0100
committerDomen Kožar <domen@dev.si>2017-12-03 11:42:51 +0100
commitd64ba1c0604d3d92ec23ac7e62899728045175d4 (patch)
tree16c7598fe231384402e987c62443f196992845fe
parentecd0e118516718b83642696bb9bd917761afce76 (diff)
downloadnixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar.gz
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar.bz2
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar.lz
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar.xz
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.tar.zst
nixlib-d64ba1c0604d3d92ec23ac7e62899728045175d4.zip
Add localtime package and nixos module
Simple daemon for keeping system timezone up-to-date via geoclue2.

Sadly i3 status needs to be restarted for timezone changes.
-rw-r--r--nixos/modules/module-list.nix1
-rw-r--r--nixos/modules/services/system/localtime.nix60
-rw-r--r--pkgs/tools/system/localtime/default.nix22
-rw-r--r--pkgs/top-level/all-packages.nix2
4 files changed, 85 insertions, 0 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index 5e2161aacb66..1cb51f2c82fa 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -588,6 +588,7 @@
   ./services/system/cloud-init.nix
   ./services/system/dbus.nix
   ./services/system/earlyoom.nix
+  ./services/system/localtime.nix
   ./services/system/kerberos.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
new file mode 100644
index 000000000000..b9355bbb9441
--- /dev/null
+++ b/nixos/modules/services/system/localtime.nix
@@ -0,0 +1,60 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+  cfg = config.services.localtime;
+in {
+  options = {
+    services.localtime = {
+      enable = mkOption {
+        default = false;
+        description = ''
+          Enable <literal>localtime</literal>, 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.
+        '';
+      };
+    };
+  };
+
+  config = mkIf cfg.enable {
+    services.geoclue2.enable = true;
+
+    security.polkit.extraConfig = ''
+     polkit.addRule(function(action, subject) {
+       if (action.id == "org.freedesktop.timedate1.set-timezone"
+           && subject.user == "localtimed") {
+         return polkit.Result.YES;
+       }
+     });
+    '';
+
+    users.users = [{
+      name = "localtimed";
+      description = "Taskserver user";
+    }];
+
+    systemd.services.localtime = {
+      description = "localtime service";
+      wantedBy = [ "multi-user.target" ];
+      partOf = [ "geoclue.service "];
+
+      serviceConfig = {
+        Restart                 = "on-failure";
+        # TODO: make it work with dbus
+        #DynamicUser             = true;
+        Nice                    = 10;
+        User                    = "localtimed";
+        PrivateTmp              = "yes";
+        PrivateDevices          = true;
+        PrivateNetwork          = "yes";
+        NoNewPrivileges         = "yes";
+        ProtectSystem           = "strict";
+        ProtectHome             = true;
+        ExecStart               = "${pkgs.localtime}/bin/localtimed";
+      };
+    };
+  };
+}
diff --git a/pkgs/tools/system/localtime/default.nix b/pkgs/tools/system/localtime/default.nix
new file mode 100644
index 000000000000..d9cfc77203e1
--- /dev/null
+++ b/pkgs/tools/system/localtime/default.nix
@@ -0,0 +1,22 @@
+{ stdenv, go, systemd, polkit, fetchFromGitHub, m4 }:
+
+stdenv.mkDerivation {
+  name = "localtime-2017-11-07";
+
+  src = fetchFromGitHub {
+    owner = "Stebalien";
+    repo = "localtime";
+    rev = "2e7b4317c723406bd75b2a1d640219ab9f8090ce";
+    sha256 = "04fyna8p7q7skzx9fzmncd6gx7x5pwa9jh8a84hpljlvj0kldfs8";
+  };
+  
+  buildInputs = [ go systemd polkit m4 ];
+
+  makeFlags = [ "PREFIX=$(out)" ];
+
+  meta = {
+    description = "A daemon for keeping the system timezone up-to-date based on the current location";
+    homepage = https://github.com/Stebalien/localtime;
+    platforms = stdenv.lib.platforms.linux;
+  };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 298b79b07b8b..1fc1f4581748 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -3208,6 +3208,8 @@ with pkgs;
 
   limesurvey = callPackage ../servers/limesurvey { };
 
+  localtime = callPackage ../tools/system/localtime { };
+
   logcheck = callPackage ../tools/system/logcheck {
     inherit (perlPackages) mimeConstruct;
   };