nixpkgs/nixos/modules/services
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
..
admin nixos/pgadmin: init 2022-02-26 14:30:14 +01:00
amqp
audio nixos/squeezelite: add support for PulseAudio version 2022-03-13 21:08:52 +08:00
backup nixos/zrepl: note about systemd unit, add snapshot test 2022-03-30 08:55:15 -07:00
blockchain/ethereum
cluster Merge pull request #154004 from illustris/hadoop 2022-03-16 14:05:56 +02:00
computing
continuous-integration docs: replace defunct git://github.com urls with https:// 2022-03-25 11:21:42 +01:00
databases nixos/redis: bind on localhost by default 2022-02-28 13:37:47 +01:00
desktops nixos/wireplumber: fix Lua syntax 2022-03-31 15:11:15 +03:00
development add a defaultText 2022-02-23 16:19:10 -05:00
display-managers
editors
finance
games Merge pull request #161226 from Misterio77/master 2022-03-29 14:17:01 +01:00
hardware joycond: don't use dkms hid-nintendo on kernel 5.16 or newer 2022-03-19 16:38:09 +01:00
home-automation nixos/zigbee2mqtt: move into home-automation category 2022-03-01 19:19:31 +01:00
logging logrotate: add configuration check at build time 2022-04-01 07:09:27 +09:00
mail
matrix Merge pull request #164627 from mkg20001/fix-matrix 2022-03-31 18:26:03 +02:00
misc nixos/logrotate: convert to freeform 2022-04-01 07:09:26 +09:00
monitoring Merge pull request #164533 from mweinelt/kea-exporter-after-kea 2022-03-30 00:03:03 +02:00
network-filesystems nixos/ipfs: improve how the commandline flags are generated 2022-03-24 20:42:07 +00:00
networking nixos/logrotate: convert to freeform 2022-04-01 07:09:26 +09:00
printing
scheduling
search
security nixos/sslmate-agent: init 2022-03-28 17:41:18 -06:00
system nixos/earlyoom: bring the module up to date (#163663) 2022-03-24 15:34:09 +08:00
torrent
ttys
video nixos/unifi-video: add deprecation warning for openFirewall 2022-03-28 19:55:50 -07:00
wayland
web-apps mastodon: use correct GitHub Url 2022-03-31 13:17:11 +02:00
web-servers nixos/logrotate: convert to freeform 2022-04-01 07:09:26 +09:00
x11 Merge pull request #166156 from andersk/gnome-vte-shell 2022-03-29 21:58:14 +02:00