about summary refs log tree commit diff
path: root/nixpkgs/nixos/modules/services/system/localtime.nix
blob: c7e897c9644813d6d4c6d6bf3c56c5ea0ba2dc37 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
{ 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;

    # so polkit will pick up the rules
    environment.systemPackages = [ pkgs.localtime ];

    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";
      };
    };
  };
}