nixpkgs-suyu/nixos/modules/services/monitoring/incron.nix

100 lines
2.6 KiB
Nix
Raw Normal View History

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