2009-09-16 09:48:47 +02: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
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 09:48:47 +02:00
|
|
|
options = {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 09:48:47 +02:00
|
|
|
services.uptimed = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
2009-09-16 09:49:23 +02:00
|
|
|
default = false;
|
2009-09-16 09:48:47 +02:00
|
|
|
description = ''
|
|
|
|
Uptimed allows you to track your highest uptimes.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf config.services.uptimed.enable {
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 10:01:03 +02:00
|
|
|
environment.systemPackages = [ uptimed ];
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 09:48:47 +02:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = uptimedUser;
|
|
|
|
uid = config.ids.uids.uptimed;
|
|
|
|
description = "Uptimed daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2009-10-12 20:09:34 +02:00
|
|
|
jobs.uptimed =
|
2009-10-12 19:09:38 +02:00
|
|
|
{ description = "Uptimed daemon";
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2009-10-12 19:09:38 +02:00
|
|
|
startOn = "startup";
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2009-10-12 19:09:38 +02:00
|
|
|
preStart =
|
|
|
|
''
|
2009-09-16 09:48:47 +02: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 19:09:38 +02:00
|
|
|
'';
|
2009-09-16 09:48:47 +02:00
|
|
|
|
2009-10-12 19:09:38 +02:00
|
|
|
exec = "${uptimed}/sbin/uptimed ${uptimedFlags}";
|
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 09:48:47 +02:00
|
|
|
};
|
2011-09-14 20:20:50 +02:00
|
|
|
|
2009-09-16 09:48:47 +02:00
|
|
|
}
|