···
16
+
meta = with pkgs.lib.maintainers; {
17
+
maintainers = [ martinetd ];
14
-
import ./make-test-python.nix (
18
-
meta = with pkgs.lib.maintainers; {
19
-
maintainers = [ martinetd ];
26
-
services.logrotate.enable = true;
24
+
services.logrotate.enable = true;
29
+
services.logrotate = {
31
+
configFile = pkgs.writeText "logrotate.conf" ''
32
+
# self-written config file
33
+
su notarealuser notagroupeither
31
-
services.logrotate = {
33
-
configFile = pkgs.writeText "logrotate.conf" ''
34
-
# self-written config file
35
-
su notarealuser notagroupeither
42
-
imports = [ importTest ];
40
+
imports = [ importTest ];
44
-
services.logrotate = {
47
-
# remove default frequency header and add another
50
-
delaycompress = true;
52
-
# extra global setting... affecting nothing
58
-
# using mail somewhere should add --mail to logrotate invocation
60
-
mail = "user@domain.tld";
62
-
# postrotate should be suffixed by 'endscript'
64
-
postrotate = "touch /dev/null";
66
-
# check checkConfig works as expected: there is nothing to check here
67
-
# except that the file build passes
70
-
createolddir = "0750 root utmp";
71
-
create = "root utmp";
72
-
"create " = "0750 root utmp";
74
-
# multiple paths should be aggregated
81
-
# overriding imported path should keep existing attributes
82
-
# (e.g. olddir is still set)
42
+
services.logrotate = {
45
+
# remove default frequency header and add another
48
+
delaycompress = true;
50
+
# extra global setting... affecting nothing
56
+
# using mail somewhere should add --mail to logrotate invocation
58
+
mail = "user@domain.tld";
60
+
# postrotate should be suffixed by 'endscript'
62
+
postrotate = "touch /dev/null";
64
+
# check checkConfig works as expected: there is nothing to check here
65
+
# except that the file build passes
68
+
createolddir = "0750 root utmp";
69
+
create = "root utmp";
70
+
"create " = "0750 root utmp";
72
+
# multiple paths should be aggregated
79
+
# overriding imported path should keep existing attributes
80
+
# (e.g. olddir is still set)
92
-
with subtest("whether logrotate works"):
93
-
# we must rotate once first to create logrotate stamp
94
-
defaultMachine.succeed("systemctl start logrotate.service")
95
-
# we need to wait for console text once here to
96
-
# clear console buffer up to this point for next wait
97
-
defaultMachine.wait_for_console_text('logrotate.service: Deactivated successfully')
90
+
with subtest("whether logrotate works"):
91
+
# we must rotate once first to create logrotate stamp
92
+
defaultMachine.succeed("systemctl start logrotate.service")
93
+
# we need to wait for console text once here to
94
+
# clear console buffer up to this point for next wait
95
+
defaultMachine.wait_for_console_text('logrotate.service: Deactivated successfully')
99
-
defaultMachine.succeed(
100
-
# wtmp is present in default config.
101
-
"rm -f /var/log/wtmp*",
102
-
# we need to give it at least 1MB
103
-
"dd if=/dev/zero of=/var/log/wtmp bs=2M count=1",
97
+
defaultMachine.succeed(
98
+
# wtmp is present in default config.
99
+
"rm -f /var/log/wtmp*",
100
+
# we need to give it at least 1MB
101
+
"dd if=/dev/zero of=/var/log/wtmp bs=2M count=1",
105
-
# move into the future and check rotation.
106
-
"date -s 'now + 1 month + 1 day'")
107
-
defaultMachine.wait_for_console_text('logrotate.service: Deactivated successfully')
108
-
defaultMachine.succeed(
109
-
# check rotate worked
110
-
"[ -e /var/log/wtmp.1 ]",
112
-
with subtest("default config does not have mail"):
113
-
defaultMachine.fail("systemctl cat logrotate.service | grep -- --mail")
114
-
with subtest("using mails adds mail option"):
115
-
machine.succeed("systemctl cat logrotate.service | grep -- --mail")
116
-
with subtest("check generated config matches expectation"):
118
-
# copy conf to /tmp/logrotate.conf for easy grep
119
-
"conf=$(systemctl cat logrotate | grep -oE '/nix/store[^ ]*logrotate.conf'); cp $conf /tmp/logrotate.conf",
120
-
"! grep weekly /tmp/logrotate.conf",
121
-
"grep -E '^delaycompress' /tmp/logrotate.conf",
122
-
"tail -n 1 /tmp/logrotate.conf | grep shred",
123
-
"sed -ne '/\"sendmail\" {/,/}/p' /tmp/logrotate.conf | grep 'mail user@domain.tld'",
124
-
"sed -ne '/\"postrotate\" {/,/}/p' /tmp/logrotate.conf | grep endscript",
125
-
"grep '\"file1\"\n\"file2\" {' /tmp/logrotate.conf",
126
-
"sed -ne '/\"import\" {/,/}/p' /tmp/logrotate.conf | grep noolddir",
128
-
# also check configFile option
129
-
failingMachine.succeed(
130
-
"conf=$(systemctl cat logrotate | grep -oE '/nix/store[^ ]*logrotate.conf'); cp $conf /tmp/logrotate.conf",
131
-
"grep 'self-written config' /tmp/logrotate.conf",
133
-
with subtest("Check logrotate-checkconf service"):
134
-
machine.wait_for_unit("logrotate-checkconf.service")
135
-
# wait_for_unit also asserts for success, so wait for
136
-
# parent target instead and check manually.
137
-
failingMachine.wait_for_unit("multi-user.target")
138
-
info = failingMachine.get_unit_info("logrotate-checkconf.service")
139
-
if info["ActiveState"] != "failed":
140
-
raise Exception('logrotate-checkconf.service was not failed')
103
+
# move into the future and check rotation.
104
+
"date -s 'now + 1 month + 1 day'")
105
+
defaultMachine.wait_for_console_text('logrotate.service: Deactivated successfully')
106
+
defaultMachine.succeed(
107
+
# check rotate worked
108
+
"[ -e /var/log/wtmp.1 ]",
110
+
with subtest("default config does not have mail"):
111
+
defaultMachine.fail("systemctl cat logrotate.service | grep -- --mail")
112
+
with subtest("using mails adds mail option"):
113
+
machine.succeed("systemctl cat logrotate.service | grep -- --mail")
114
+
with subtest("check generated config matches expectation"):
116
+
# copy conf to /tmp/logrotate.conf for easy grep
117
+
"conf=$(systemctl cat logrotate | grep -oE '/nix/store[^ ]*logrotate.conf'); cp $conf /tmp/logrotate.conf",
118
+
"! grep weekly /tmp/logrotate.conf",
119
+
"grep -E '^delaycompress' /tmp/logrotate.conf",
120
+
"tail -n 1 /tmp/logrotate.conf | grep shred",
121
+
"sed -ne '/\"sendmail\" {/,/}/p' /tmp/logrotate.conf | grep 'mail user@domain.tld'",
122
+
"sed -ne '/\"postrotate\" {/,/}/p' /tmp/logrotate.conf | grep endscript",
123
+
"grep '\"file1\"\n\"file2\" {' /tmp/logrotate.conf",
124
+
"sed -ne '/\"import\" {/,/}/p' /tmp/logrotate.conf | grep noolddir",
126
+
# also check configFile option
127
+
failingMachine.succeed(
128
+
"conf=$(systemctl cat logrotate | grep -oE '/nix/store[^ ]*logrotate.conf'); cp $conf /tmp/logrotate.conf",
129
+
"grep 'self-written config' /tmp/logrotate.conf",
131
+
with subtest("Check logrotate-checkconf service"):
132
+
machine.wait_for_unit("logrotate-checkconf.service")
133
+
# wait_for_unit also asserts for success, so wait for
134
+
# parent target instead and check manually.
135
+
failingMachine.wait_for_unit("multi-user.target")
136
+
info = failingMachine.get_unit_info("logrotate-checkconf.service")
137
+
if info["ActiveState"] != "failed":
138
+
raise Exception('logrotate-checkconf.service was not failed')
142
-
machine.log(machine.execute("systemd-analyze security logrotate.service | grep -v ✓")[1])
140
+
machine.log(machine.execute("systemd-analyze security logrotate.service | grep -v ✓")[1])