grafana-alloy: don't build the frontend twice
[NixPkgs.git] / nixos / modules / services / monitoring / tuptime.nix
blob334f911a6c719156be692129f4c7d16bfff5a914
1 { config, lib, pkgs, ... }:
3 with lib;
5 let
7   cfg = config.services.tuptime;
9 in {
11   options.services.tuptime = {
13     enable = mkEnableOption "the total uptime service";
15     timer = {
16       enable = mkOption {
17         type = types.bool;
18         default = true;
19         description = "Whether to regularly log uptime to detect bad shutdowns.";
20       };
22       period = mkOption {
23         type = types.str;
24         default = "*:0/5";
25         description = "systemd calendar event";
26       };
27     };
28   };
31   config = mkIf cfg.enable {
33     environment.systemPackages = [ pkgs.tuptime ];
35     users = {
36       groups._tuptime.members = [ "_tuptime" ];
37       users._tuptime = {
38         isSystemUser = true;
39         group = "_tuptime";
40         description = "tuptime database owner";
41       };
42     };
44     systemd = {
45       services = {
47         tuptime = {
48           description = "The total uptime service";
49           documentation = [ "man:tuptime(1)" ];
50           after = [ "time-sync.target" ];
51           wantedBy = [ "multi-user.target" ];
52           serviceConfig = {
53             StateDirectory = "tuptime";
54             Type = "oneshot";
55             User = "_tuptime";
56             RemainAfterExit = true;
57             ExecStart = "${pkgs.tuptime}/bin/tuptime -q";
58             ExecStop = "${pkgs.tuptime}/bin/tuptime -qg";
59           };
60         };
62         tuptime-sync = mkIf cfg.timer.enable {
63           description = "Tuptime scheduled sync service";
64           serviceConfig = {
65             Type = "oneshot";
66             User = "_tuptime";
67             ExecStart = "${pkgs.tuptime}/bin/tuptime -q";
68           };
69         };
70       };
72       timers.tuptime-sync = mkIf cfg.timer.enable {
73         description = "Tuptime scheduled sync timer";
74         # this timer should be started if the service is started
75         # even if the timer was previously stopped
76         wantedBy = [ "tuptime.service" "timers.target" ];
77         # this timer should be stopped if the service is stopped
78         partOf = [ "tuptime.service" ];
79         timerConfig = {
80           OnBootSec = "1min";
81           OnCalendar = cfg.timer.period;
82           Unit = "tuptime-sync.service";
83         };
84       };
85     };
86   };
88   meta.maintainers = [ maintainers.evils ];