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