2016-01-23 20:28:01 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2016-01-23 20:28:01 +01:00
|
|
|
with lib;
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2016-01-23 20:28:01 +01:00
|
|
|
let
|
|
|
|
cfg = config.services.uptimed;
|
2009-09-16 09:48:47 +02:00
|
|
|
stateDir = "/var/spool/uptimed";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.uptimed = {
|
|
|
|
enable = mkOption {
|
2009-09-16 09:49:23 +02:00
|
|
|
default = false;
|
2009-09-16 09:48:47 +02:00
|
|
|
description = ''
|
2016-01-23 20:28:01 +01:00
|
|
|
Enable <literal>uptimed</literal>, allowing you to track
|
|
|
|
your highest uptimes.
|
2009-09-16 09:48:47 +02:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-01-23 20:28:01 +01:00
|
|
|
config = mkIf cfg.enable {
|
2018-06-30 01:58:35 +02:00
|
|
|
users.users.uptimed = {
|
2016-01-23 20:28:01 +01:00
|
|
|
description = "Uptimed daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.uptimed;
|
|
|
|
};
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
systemd.services.uptimed = {
|
2016-01-23 20:28:01 +01:00
|
|
|
unitConfig.Documentation = "man:uptimed(8) man:uprecords(1)";
|
|
|
|
description = "uptimed service";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Restart = "on-failure";
|
|
|
|
User = "uptimed";
|
|
|
|
Nice = 19;
|
|
|
|
IOSchedulingClass = "idle";
|
|
|
|
PrivateTmp = "yes";
|
|
|
|
PrivateNetwork = "yes";
|
|
|
|
NoNewPrivileges = "yes";
|
|
|
|
ReadWriteDirectories = stateDir;
|
|
|
|
InaccessibleDirectories = "/home";
|
|
|
|
ExecStart = "${pkgs.uptimed}/sbin/uptimed -f -p ${stateDir}/pid";
|
|
|
|
};
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2016-01-06 07:50:18 +01:00
|
|
|
preStart = ''
|
|
|
|
if ! test -f ${stateDir}/bootid ; then
|
2016-01-23 20:28:01 +01:00
|
|
|
${pkgs.uptimed}/sbin/uptimed -b
|
2016-01-06 07:50:18 +01:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2009-09-16 09:48:47 +02:00
|
|
|
};
|
|
|
|
}
|