1 { lib, config, pkgs, ... }:
4 cfg = config.services.filesWatcher;
8 services.filesWatcher = with types; mkOption {
11 Files to watch and trigger service reload or restart of service
14 type = attrsOf (submodule {
16 restart = mkEnableOption "Restart service rather than reloading it";
20 Paths to watch that should trigger a reload of the
28 Time to wait before reloading/restarting the service.
37 config.systemd.services = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
39 description = "${name} reloader";
40 after = [ "network.target" ];
42 action = if icfg.restart then "restart" else "reload";
44 # Service may be stopped during file modification (e.g. activationScripts)
45 if ${pkgs.systemd}/bin/systemctl --quiet is-active ${name}.service; then
46 ${pkgs.coreutils}/bin/sleep ${toString icfg.waitTime}
47 ${pkgs.systemd}/bin/systemctl ${action} ${name}.service
55 config.systemd.paths = attrsets.mapAttrs' (name: icfg: attrsets.nameValuePair
57 wantedBy = [ "multi-user.target" ];
58 pathConfig.PathChanged = icfg.paths;