nixpkgs/nixos/modules
Dominique Martinet 45ef5c1741 logrotate: add configuration check at build time
Now the service no longer starts immediately,
check if the config we generated makes sense as soon as possible.

The check isn't perfect because logrotate --debug wants to check
users required, there are two problems:
 - /etc/passwd and /etc/group are sandboxed and we don't have
visibility of system users
 - the check phase runs as nixbld which cannot su to other users
and logrotate fails on this

Until these two problems can be addressed, users-related checks
are filtered out, it's still much better than no check.
The check can be disabled with services.logrotate.checkConfig
if required
(bird also has a preCheck param, to prepare the environment
before check, but we can add it if it becomes necessary)

Since this makes for very verbose builds, we only show errors:
There is no way to control log level, but logrotate hardcodes
'error:' at common log level, so we can use grep, taking care
to keep error codes

Some manual tests:
───────┬──────────────────────────────────────────
       │ File: valid-config.conf
───────┼──────────────────────────────────────────
   1   │ missingok
───────┴──────────────────────────────────────────
logrotate --debug ok
grep ok

───────┬──────────────────────────────────────────
       │ File: postrotate-no-end.conf
───────┼──────────────────────────────────────────
   1   │ missingok
   2   │ /file {
   3   │    postrotate
   4   │      test
   5   │ }
───────┴──────────────────────────────────────────
error: postrotate-no-end.conf:prerotate, postrotate or preremove without endscript

───────┬──────────────────────────────────────────
       │ File: missing-file.conf
───────┼──────────────────────────────────────────
   1   │ "test" { daily }
───────┴──────────────────────────────────────────
error: stat of test failed: No such file or directory

───────┬──────────────────────────────────────────
       │ File: unknown-option.conf
───────┼──────────────────────────────────────────
   1   │ some syntax error
───────┴──────────────────────────────────────────
logrotate --debug ok
error: unknown-option.conf:1 unknown option 'some' -- ignoring line

───────┬──────────────────────────────────────────
       │ File: unknown-user.conf
───────┼──────────────────────────────────────────
   1   │ su notauser notagroup
───────┴──────────────────────────────────────────
error: unknown-user.conf:1 unknown user 'notauser'

In particular note that logrotate would not error on unknown option
(it just ignores the line) but this change makes the check fail.
2022-04-01 07:09:27 +09:00
..
config Merge pull request #162996 from alyssais/resolvconf-disable 2022-03-27 12:25:14 +02:00
hardware Merge remote-tracking branch 'upstream/master' 2022-03-21 11:32:36 -04:00
i18n/input-method nixos/documentation: split options doc build 2022-01-02 19:46:13 +01:00
installer installer/cd-dvd/iso-image: add syslinuxTheme config option 2022-03-25 21:37:20 +01:00
misc Merge pull request #164270 from alyssais/locate-pruneNames 2022-03-16 21:17:48 +01:00
profiles nixos/nix-daemon: use structural settings 2022-01-26 21:04:50 -05:00
programs nixos/_1password: cleanup 2022-03-30 08:23:27 -07:00
security Merge pull request #156858: nixos/polkit: don't enable by default 2022-03-05 14:48:35 +01:00
services logrotate: add configuration check at build time 2022-04-01 07:09:27 +09:00
system nixos/logrotate: convert to freeform 2022-04-01 07:09:26 +09:00
tasks nixos/nix-gc, nixos/auto-upgrade: Minor documentation fixes. 2022-03-31 00:24:25 -04:00
testing nixos/tests: also set TimeoutStart in systemd.user.extraConfig 2022-01-21 04:18:05 +01:00
virtualisation nixos/logrotate: convert to freeform 2022-04-01 07:09:26 +09:00
module-list.nix netbox: init module 2022-03-30 22:24:34 +02:00
rename.nix Remove F-PROT package and service module (EoL) (#160372) 2022-03-02 21:51:47 +02:00