{ 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" ]; path = with pkgs; [ rolling-directory ]; script = let args = [ dCfg.path dCfg.maxSize "monitor" ] ++ optionals (dCfg.monitorTimeout != null) ["-t" dCfg.monitorTimeout] ++ optionals (dCfg.minSleep != null) ["-s" dCfg.minSleep]; in '' exec -- rolling-directory ${escapeShellArgs args} ''; }; in { options = { services.rollingDirectories = mkOption { type = with types; listOf (submodule dirConfig); default = []; }; programs.recv.enable = mkEnableOption "the ‘recv’ program"; }; config = { nixpkgs.overlays = [ (import ./default.nix) ]; systemd.services = listToAttrs (map dirService config.services.rollingDirectories); security.wrappers = mkIf config.programs.recv.enable { recv.source = "${pkgs.recv}/bin/recv"; }; }; }