summaryrefslogtreecommitdiff
path: root/nix/module.nix
blob: 401b9566224f8640186ce8c2c3351de1374b9b6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
{ 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;
      };

      monitorTimeout = mkOption {
        type = with types; nullOr ints.positive;
        default = 3600;
      };
    };
  };

  dirService = dCfg: with dCfg; nameValuePair ("rolling-directory@" + escapeSystemdPath path) {
    wantedBy = [ "multi-user.target" ];

    serviceConfig = {
      ExecStart = let
        sArgs = [ path (toString maxSize) ] + (optional (monitorTimeout != null) monitorTimeout);
      in "${pkgs.rolling-directory}/bin/rolling-directory ${escapeShellArgs sArgs}";
    };
  };
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);
  };
}