|
97 | 97 | defaultText = lib.literalExpression "cfg.settings != {}"; |
98 | 98 | }; |
99 | 99 |
|
| 100 | + allowNetworking = lib.mkEnableOption "network access for logrotate"; |
| 101 | + |
100 | 102 | settings = lib.mkOption { |
101 | 103 | default = { }; |
102 | 104 | description = '' |
|
240 | 242 | config = lib.mkIf cfg.enable { |
241 | 243 | systemd.services.logrotate = { |
242 | 244 | description = "Logrotate Service"; |
| 245 | + documentation = [ |
| 246 | + "man:logrotate(8)" |
| 247 | + "man:logrotate(5)" |
| 248 | + ]; |
243 | 249 | startAt = "hourly"; |
244 | 250 |
|
245 | 251 | serviceConfig = { |
246 | | - Restart = "no"; |
247 | | - User = "root"; |
248 | | - ExecStart = "${pkgs.logrotate}/sbin/logrotate ${utils.escapeSystemdExecArgs cfg.extraArgs} ${mailOption} ${cfg.configFile}"; |
| 252 | + Type = "oneshot"; |
| 253 | + ExecStart = "${lib.getExe pkgs.logrotate} ${utils.escapeSystemdExecArgs cfg.extraArgs} ${mailOption} ${cfg.configFile}"; |
| 254 | + |
| 255 | + # performance |
| 256 | + Nice = 19; |
| 257 | + IOSchedulingClass = "best-effort"; |
| 258 | + IOSchedulingPriority = 7; |
| 259 | + |
| 260 | + # hardening |
| 261 | + CapabilityBoundingSet = [ |
| 262 | + "CAP_CHOWN" |
| 263 | + "CAP_SETGID" |
| 264 | + ]; |
| 265 | + DevicePolicy = "closed"; |
| 266 | + LockPersonality = true; |
| 267 | + MemoryDenyWriteExecute = true; |
| 268 | + NoNewPrivileges = true; |
| 269 | + PrivateDevices = true; |
| 270 | + PrivateTmp = true; |
| 271 | + ProcSubset = "pid"; |
| 272 | + ProtectClock = true; |
| 273 | + ProtectControlGroups = true; |
| 274 | + ProtectHome = true; |
| 275 | + ProtectHostname = true; |
| 276 | + ProtectKernelLogs = true; |
| 277 | + ProtectKernelModules = true; |
| 278 | + ProtectKernelTunables = true; |
| 279 | + ProtectProc = "invisible"; |
| 280 | + ProtectSystem = "full"; |
| 281 | + RestrictNamespaces = true; |
| 282 | + RestrictRealtime = true; |
| 283 | + RestrictSUIDSGID = true; |
| 284 | + SystemCallArchitectures = "native"; |
| 285 | + SystemCallFilter = [ |
| 286 | + "@system-service" |
| 287 | + "~@privileged @resources" |
| 288 | + "@chown" |
| 289 | + ]; |
| 290 | + UMask = "0027"; |
| 291 | + } // lib.optionalAttrs (!cfg.allowNetworking) { |
| 292 | + PrivateNetwork = true; |
| 293 | + RestrictAddressFamilies = "none"; |
249 | 294 | }; |
250 | 295 | }; |
251 | 296 | systemd.services.logrotate-checkconf = { |
|
0 commit comments