2009-09-16 07:48:47 +00:00
|
|
|
{pkgs, config, ...}:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
inherit (pkgs.lib) mkOption mkIf singleton;
|
|
|
|
|
|
|
|
inherit (pkgs) uptimed;
|
|
|
|
|
|
|
|
stateDir = "/var/spool/uptimed";
|
|
|
|
|
|
|
|
uptimedUser = "uptimed";
|
|
|
|
|
|
|
|
modprobe = config.system.sbin.modprobe;
|
|
|
|
|
|
|
|
uptimedFlags = "";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.uptimed = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2009-09-16 07:49:23 +00:00
|
|
|
default = false;
|
2009-09-16 07:48:47 +00:00
|
|
|
description = ''
|
|
|
|
Uptimed allows you to track your highest uptimes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.uptimed.enable {
|
2009-10-12 17:09:38 +00:00
|
|
|
|
2009-09-16 08:01:03 +00:00
|
|
|
environment.systemPackages = [ uptimed ];
|
2009-09-16 07:48:47 +00:00
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = uptimedUser;
|
|
|
|
uid = config.ids.uids.uptimed;
|
|
|
|
description = "Uptimed daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
jobAttrs.uptimed =
|
|
|
|
{ description = "Uptimed daemon";
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
startOn = "startup";
|
|
|
|
stopOn = "shutdown";
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
preStart =
|
|
|
|
''
|
2009-09-16 07:48:47 +00:00
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${uptimedUser} ${stateDir}
|
|
|
|
|
|
|
|
# Needed to run uptimed as an unprivileged user.
|
|
|
|
${modprobe}/sbin/modprobe capability || true
|
|
|
|
|
|
|
|
if ! test -f ${stateDir}/bootid ; then
|
|
|
|
${uptimed}/sbin/uptimed -b
|
|
|
|
fi
|
2009-10-12 17:09:38 +00:00
|
|
|
'';
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2009-10-12 17:09:38 +00:00
|
|
|
exec = "${uptimed}/sbin/uptimed ${uptimedFlags}";
|
|
|
|
};
|
2009-09-16 07:48:47 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|