nixpkgs/nixos/modules/services/system/uptimed.nix

67 lines
1.1 KiB
Nix
Raw Normal View History

{pkgs, config, lib, ...}:
let
inherit (lib) mkOption mkIf singleton;
inherit (pkgs) uptimed;
stateDir = "/var/spool/uptimed";
uptimedUser = "uptimed";
in
{
###### interface
options = {
services.uptimed = {
enable = mkOption {
default = false;
description = ''
Uptimed allows you to track your highest uptimes.
'';
};
};
};
###### implementation
config = mkIf config.services.uptimed.enable {
environment.systemPackages = [ uptimed ];
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" ];
2016-01-06 06:50:18 +00:00
preStart = ''
mkdir -m 0755 -p ${stateDir}
chown ${uptimedUser} ${stateDir}
2016-01-06 06:50:18 +00:00
if ! test -f ${stateDir}/bootid ; then
${uptimed}/sbin/uptimed -b
fi
'';
2016-01-06 06:50:18 +00:00
script = "${uptimed}/sbin/uptimed";
};
};
}