2014-05-05 18:58:51 +00:00
|
|
|
{pkgs, config, lib, ...}:
|
2009-09-16 07:48:47 +00:00
|
|
|
|
|
|
|
let
|
|
|
|
|
2014-05-05 18:58:51 +00:00
|
|
|
inherit (lib) mkOption mkIf singleton;
|
2009-09-16 07:48:47 +00:00
|
|
|
|
|
|
|
inherit (pkgs) uptimed;
|
|
|
|
|
|
|
|
stateDir = "/var/spool/uptimed";
|
|
|
|
|
|
|
|
uptimedUser = "uptimed";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 07:48:47 +00:00
|
|
|
options = {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 07:48:47 +00:00
|
|
|
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 {
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 08:01:03 +00:00
|
|
|
environment.systemPackages = [ uptimed ];
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 07:48:47 +00:00
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = uptimedUser;
|
|
|
|
uid = config.ids.uids.uptimed;
|
|
|
|
description = "Uptimed daemon user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
systemd.services.uptimed = {
|
|
|
|
description = "Uptimed daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
preStart = ''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${uptimedUser} ${stateDir}
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
if ! test -f ${stateDir}/bootid ; then
|
|
|
|
${uptimed}/sbin/uptimed -b
|
|
|
|
fi
|
|
|
|
'';
|
2009-09-16 07:48:47 +00:00
|
|
|
|
2016-01-06 06:50:18 +00:00
|
|
|
script = "${uptimed}/sbin/uptimed";
|
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 07:48:47 +00:00
|
|
|
};
|
2011-09-14 18:20:50 +00:00
|
|
|
|
2009-09-16 07:48:47 +00:00
|
|
|
}
|