nixos: uptimed - rewrite and harden a bit (#7220)
This is mostly @thoughtpolice's work, but I cleaned it up a bit.
This commit is contained in:
parent
d787c2258b
commit
7ccda42007
|
@ -1,66 +1,55 @@
|
||||||
{pkgs, config, lib, ...}:
|
{ config, lib, pkgs, ... }:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
let
|
let
|
||||||
|
cfg = config.services.uptimed;
|
||||||
inherit (lib) mkOption mkIf singleton;
|
|
||||||
|
|
||||||
inherit (pkgs) uptimed;
|
|
||||||
|
|
||||||
stateDir = "/var/spool/uptimed";
|
stateDir = "/var/spool/uptimed";
|
||||||
|
|
||||||
uptimedUser = "uptimed";
|
|
||||||
|
|
||||||
in
|
in
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
||||||
###### interface
|
|
||||||
|
|
||||||
options = {
|
options = {
|
||||||
|
|
||||||
services.uptimed = {
|
services.uptimed = {
|
||||||
|
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
description = ''
|
description = ''
|
||||||
Uptimed allows you to track your highest uptimes.
|
Enable <literal>uptimed</literal>, allowing you to track
|
||||||
|
your highest uptimes.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
config = mkIf cfg.enable {
|
||||||
###### implementation
|
users.extraUsers.uptimed = {
|
||||||
|
description = "Uptimed daemon user";
|
||||||
config = mkIf config.services.uptimed.enable {
|
home = stateDir;
|
||||||
|
createHome = true;
|
||||||
environment.systemPackages = [ uptimed ];
|
uid = config.ids.uids.uptimed;
|
||||||
|
};
|
||||||
users.extraUsers = singleton
|
|
||||||
{ name = uptimedUser;
|
|
||||||
uid = config.ids.uids.uptimed;
|
|
||||||
description = "Uptimed daemon user";
|
|
||||||
home = stateDir;
|
|
||||||
};
|
|
||||||
|
|
||||||
systemd.services.uptimed = {
|
systemd.services.uptimed = {
|
||||||
description = "Uptimed daemon";
|
unitConfig.Documentation = "man:uptimed(8) man:uprecords(1)";
|
||||||
wantedBy = [ "multi-user.target" ];
|
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";
|
||||||
|
};
|
||||||
|
|
||||||
preStart = ''
|
preStart = ''
|
||||||
mkdir -m 0755 -p ${stateDir}
|
|
||||||
chown ${uptimedUser} ${stateDir}
|
|
||||||
|
|
||||||
if ! test -f ${stateDir}/bootid ; then
|
if ! test -f ${stateDir}/bootid ; then
|
||||||
${uptimed}/sbin/uptimed -b
|
${pkgs.uptimed}/sbin/uptimed -b
|
||||||
fi
|
fi
|
||||||
'';
|
'';
|
||||||
|
|
||||||
script = "${uptimed}/sbin/uptimed";
|
|
||||||
};
|
};
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue