{ config, pkgs, lib, utils, ... }: with utils; with lib; let dirConfig = { options = { path = mkOption { type = types.path; }; maxSize = mkOption { type = with types; either ints.positive str; }; minSleep = mkOption { type = with types; nullOr ints.positive; default = 3600; }; monitorTimeout = mkOption { type = with types; nullOr ints.positive; default = 3600 * 24; }; }; }; dirService = dCfg: nameValuePair ("rolling-directory@" + escapeSystemdPath dCfg.path) { wantedBy = [ "multi-user.target" ]; serviceConfig = { ExecStart = let extraArgs = optionals (dCfg.monitorTimeout != null) ["-t" (toString dCfg.monitorTimeout)] + optionals (dCfg.minSleep != null) ["-s" (toString dCfg.minSleep)]; in '' ${pkgs.rolling-directory}/bin/rolling-directory %I ${toString dCfg.maxSize} monitor ${escapeShellArgs extraArgs} ''; }; }; in { options = { services.rollingDirectories = mkOption { type = with types; listOf (submodule dirConfig); default = []; }; }; config = { nixpkgs.config.packageOverrides = import ./default.nix; systemd.services = listToAttrs (map dirService config.services.rollingDirectories); }; }