summary refs log tree commit diff
path: root/nixos/modules/services/system/uptimed.nix
blob: 5f8916bbf9a47cdc9ab9cd52eabda2cd85a2e03c (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
55
56
57
58
59
60
61
62
63
64
65
66
{pkgs, config, lib, ...}:

let

  inherit (lib) mkOption mkIf singleton;

  inherit (pkgs) uptimed;

  stateDir = "/var/spool/uptimed";

  uptimedUser = "uptimed";

in

{

  ###### interface

  options = {

    services.uptimed = {

      enable = mkOption {
        default = false;
        description = ''
          Uptimed allows you to track your highest uptimes.
        '';
      };

    };

  };


  ###### implementation

  config = mkIf config.services.uptimed.enable {

    environment.systemPackages = [ uptimed ];

    users.extraUsers = singleton
      { name = uptimedUser;
        uid = config.ids.uids.uptimed;
        description = "Uptimed daemon user";
        home = stateDir;
      };

    systemd.services.uptimed = {
      description = "Uptimed daemon";
      wantedBy = [ "multi-user.target" ];

      preStart = ''
        mkdir -m 0755 -p ${stateDir}
        chown ${uptimedUser} ${stateDir}

        if ! test -f ${stateDir}/bootid ; then
          ${uptimed}/sbin/uptimed -b
        fi
      '';

      script = "${uptimed}/sbin/uptimed";
    };

  };

}