2018-08-27 21:31:55 +00:00
|
|
|
|
2018-08-25 22:08:24 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.services.incron;
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
|
|
|
|
|
|
|
services.incron = {
|
|
|
|
|
|
|
|
enable = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = false;
|
2018-08-27 21:31:55 +00:00
|
|
|
description = ''
|
|
|
|
Whether to enable the incron daemon.
|
|
|
|
|
2018-08-31 02:52:49 +00:00
|
|
|
Note that commands run under incrontab only support common Nix profiles for the <envar>PATH</envar> provided variable.
|
2018-08-27 21:31:55 +00:00
|
|
|
'';
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
allow = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc ''
|
2018-08-27 21:15:03 +00:00
|
|
|
Users allowed to use incrontab.
|
|
|
|
|
|
|
|
If empty then no user will be allowed to have their own incrontab.
|
2022-07-28 21:19:15 +00:00
|
|
|
If `null` then will defer to {option}`deny`.
|
|
|
|
If both {option}`allow` and {option}`deny` are null
|
2018-08-27 21:15:03 +00:00
|
|
|
then all users will be allowed to have their own incrontab.
|
|
|
|
'';
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
deny = mkOption {
|
|
|
|
type = types.nullOr (types.listOf types.str);
|
|
|
|
default = null;
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Users forbidden from using incrontab.";
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systab = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "The system incrontab contents.";
|
2018-08-25 22:08:24 +00:00
|
|
|
example = ''
|
2018-08-31 02:52:49 +00:00
|
|
|
/var/mail IN_CLOSE_WRITE abc $@/$#
|
|
|
|
/tmp IN_ALL_EVENTS efg $@/$# $&
|
2018-08-25 22:08:24 +00:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2018-08-29 00:43:28 +00:00
|
|
|
extraPackages = mkOption {
|
|
|
|
type = types.listOf types.package;
|
|
|
|
default = [];
|
2021-10-03 16:06:03 +00:00
|
|
|
example = literalExpression "[ pkgs.rsync ]";
|
2022-07-28 21:19:15 +00:00
|
|
|
description = lib.mdDoc "Extra packages available to the system incrontab.";
|
2018-08-29 00:43:28 +00:00
|
|
|
};
|
|
|
|
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2018-08-31 02:52:49 +00:00
|
|
|
warnings = optional (cfg.allow != null && cfg.deny != null)
|
2021-01-24 09:19:10 +00:00
|
|
|
"If `services.incron.allow` is set then `services.incron.deny` will be ignored.";
|
2018-08-28 23:50:55 +00:00
|
|
|
|
2018-08-25 22:08:24 +00:00
|
|
|
environment.systemPackages = [ pkgs.incron ];
|
|
|
|
|
2021-09-12 16:53:48 +00:00
|
|
|
security.wrappers.incrontab =
|
|
|
|
{ setuid = true;
|
|
|
|
owner = "root";
|
|
|
|
group = "root";
|
|
|
|
source = "${pkgs.incron}/bin/incrontab";
|
|
|
|
};
|
2018-08-25 22:08:24 +00:00
|
|
|
|
2018-08-27 15:23:19 +00:00
|
|
|
# incron won't read symlinks
|
|
|
|
environment.etc."incron.d/system" = {
|
|
|
|
mode = "0444";
|
2018-08-31 02:52:49 +00:00
|
|
|
text = cfg.systab;
|
2018-08-27 15:23:19 +00:00
|
|
|
};
|
2018-08-25 22:08:24 +00:00
|
|
|
environment.etc."incron.allow" = mkIf (cfg.allow != null) {
|
2018-08-31 02:52:49 +00:00
|
|
|
text = concatStringsSep "\n" cfg.allow;
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
environment.etc."incron.deny" = mkIf (cfg.deny != null) {
|
2018-08-31 02:52:49 +00:00
|
|
|
text = concatStringsSep "\n" cfg.deny;
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.incron = {
|
2018-08-31 02:52:49 +00:00
|
|
|
description = "File System Events Scheduler";
|
2018-08-25 22:08:24 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-08-29 00:43:28 +00:00
|
|
|
path = cfg.extraPackages;
|
2018-08-25 22:08:24 +00:00
|
|
|
serviceConfig.PIDFile = "/run/incrond.pid";
|
2018-08-31 02:52:49 +00:00
|
|
|
serviceConfig.ExecStartPre = "${pkgs.coreutils}/bin/mkdir -m 710 -p /var/spool/incron";
|
2018-08-31 03:03:04 +00:00
|
|
|
serviceConfig.ExecStart = "${pkgs.incron}/bin/incrond --foreground";
|
2018-08-25 22:08:24 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|