1{ pkgs, lib, ... }:
2
3{
4 name = "incron";
5 meta.maintainers = [ lib.maintainers.aanderse ];
6
7 nodes.machine =
8 { ... }:
9 {
10 services.incron.enable = true;
11 services.incron.extraPackages = [ pkgs.coreutils ];
12 services.incron.systab = ''
13 /test IN_CREATE,IN_MODIFY,IN_CLOSE_WRITE,IN_MOVED_FROM,IN_MOVED_TO echo "$@/$# $%" >> /root/incron.log
14 '';
15
16 # ensure the directory to be monitored exists before incron is started
17 systemd.tmpfiles.settings.incron-test = {
18 "/test".d = { };
19 };
20 };
21
22 testScript = ''
23 start_all()
24
25 machine.wait_for_unit("multi-user.target")
26 machine.wait_for_unit("incron.service")
27
28 machine.succeed("test -d /test")
29 # create some activity for incron to monitor
30 machine.succeed("touch /test/file")
31 machine.succeed("echo foo >> /test/file")
32 machine.succeed("mv /test/file /root")
33 machine.succeed("mv /root/file /test")
34
35 machine.sleep(1)
36
37 # touch /test/file
38 machine.succeed("grep '/test/file IN_CREATE' /root/incron.log")
39
40 # echo foo >> /test/file
41 machine.succeed("grep '/test/file IN_MODIFY' /root/incron.log")
42 machine.succeed("grep '/test/file IN_CLOSE_WRITE' /root/incron.log")
43
44 # mv /test/file /root
45 machine.succeed("grep '/test/file IN_MOVED_FROM' /root/incron.log")
46
47 # mv /root/file /test
48 machine.succeed("grep '/test/file IN_MOVED_TO' /root/incron.log")
49
50 # ensure something unexpected is not present
51 machine.fail("grep 'IN_OPEN' /root/incron.log")
52 '';
53}