at 21.11-pre 1.4 kB view raw
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 type = types.bool; 14 default = false; 15 description = '' 16 Enable <literal>uptimed</literal>, allowing you to track 17 your highest uptimes. 18 ''; 19 }; 20 }; 21 }; 22 23 config = mkIf cfg.enable { 24 users.users.uptimed = { 25 description = "Uptimed daemon user"; 26 home = stateDir; 27 createHome = true; 28 uid = config.ids.uids.uptimed; 29 }; 30 31 systemd.services.uptimed = { 32 unitConfig.Documentation = "man:uptimed(8) man:uprecords(1)"; 33 description = "uptimed service"; 34 wantedBy = [ "multi-user.target" ]; 35 36 serviceConfig = { 37 Restart = "on-failure"; 38 User = "uptimed"; 39 Nice = 19; 40 IOSchedulingClass = "idle"; 41 PrivateTmp = "yes"; 42 PrivateNetwork = "yes"; 43 NoNewPrivileges = "yes"; 44 ReadWriteDirectories = stateDir; 45 InaccessibleDirectories = "/home"; 46 ExecStart = "${pkgs.uptimed}/sbin/uptimed -f -p ${stateDir}/pid"; 47 }; 48 49 preStart = '' 50 if ! test -f ${stateDir}/bootid ; then 51 ${pkgs.uptimed}/sbin/uptimed -b 52 fi 53 ''; 54 }; 55 }; 56}