2016-01-23 19:28:01 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-23 19:28:01 +00:00
|
|
|
with lib;
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-23 19:28:01 +00:00
|
|
|
let
|
|
|
|
cfg = config.services.uptimed;
|
2009-09-16 07:48:47 +00:00
|
|
|
stateDir = "/var/spool/uptimed";
|
|
|
|
in
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
services.uptimed = {
|
|
|
|
enable = mkOption {
|
2009-09-16 07:49:23 +00:00
|
|
|
default = false;
|
2009-09-16 07:48:47 +00:00
|
|
|
description = ''
|
2016-01-23 19:28:01 +00:00
|
|
|
Enable <literal>uptimed</literal>, allowing you to track
|
|
|
|
your highest uptimes.
|
2009-09-16 07:48:47 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2016-01-23 19:28:01 +00:00
|
|
|
config = mkIf cfg.enable {
|
2018-06-29 23:58:35 +00:00
|
|
|
users.users.uptimed = {
|
2016-01-23 19:28:01 +00:00
|
|
|
description = "Uptimed daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
createHome = true;
|
|
|
|
uid = config.ids.uids.uptimed;
|
|
|
|
};
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.uptimed = {
|
2016-01-23 19:28:01 +00: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 07:48:47 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
preStart = ''
|
|
|
|
if ! test -f ${stateDir}/bootid ; then
|
2016-01-23 19:28:01 +00:00
|
|
|
${pkgs.uptimed}/sbin/uptimed -b
|
2016-01-06 06:50:18 +00:00
|
|
|
fi
|
|
|
|
'';
|
|
|
|
};
|
2009-09-16 07:48:47 +00:00
|
|
|
};
|
|
|
|
}
|