1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 cfg = config.services.uptimed; 7 stateDir = "/var/spool/uptimed"; 8in 9{ 10 options = { 11 services.uptimed = { 12 enable = mkOption { 13 default = false; 14 description = '' 15 Enable <literal>uptimed</literal>, allowing you to track 16 your highest uptimes. 17 ''; 18 }; 19 }; 20 }; 21 22 config = mkIf cfg.enable { 23 users.extraUsers.uptimed = { 24 description = "Uptimed daemon user"; 25 home = stateDir; 26 createHome = true; 27 uid = config.ids.uids.uptimed; 28 }; 29 30 systemd.services.uptimed = { 31 unitConfig.Documentation = "man:uptimed(8) man:uprecords(1)"; 32 description = "uptimed service"; 33 wantedBy = [ "multi-user.target" ]; 34 35 serviceConfig = { 36 Restart = "on-failure"; 37 User = "uptimed"; 38 Nice = 19; 39 IOSchedulingClass = "idle"; 40 PrivateTmp = "yes"; 41 PrivateNetwork = "yes"; 42 NoNewPrivileges = "yes"; 43 ReadWriteDirectories = stateDir; 44 InaccessibleDirectories = "/home"; 45 ExecStart = "${pkgs.uptimed}/sbin/uptimed -f -p ${stateDir}/pid"; 46 }; 47 48 preStart = '' 49 if ! test -f ${stateDir}/bootid ; then 50 ${pkgs.uptimed}/sbin/uptimed -b 51 fi 52 ''; 53 }; 54 }; 55}