summaryrefslogtreecommitdiffstats
path: root/nixos/modules/services/admin/docuum.nix
blob: a2516cf9eb94e45d365cfe25adaedab16fa01767 (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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{
  config,
  pkgs,
  lib,
  utils,
  ...
}:

let
  cfg = config.services.docuum;
  inherit (lib)
    mkIf
    mkEnableOption
    mkOption
    getExe
    types
    optionals
    concatMap
    ;
in
{
  options.services.docuum = {
    enable = mkEnableOption "docuum daemon";

    threshold = mkOption {
      description = "Threshold for deletion in bytes, like `10 GB`, `10 GiB`, `10GB` or percentage-based thresholds like `50%`";
      type = types.str;
      default = "10 GB";
      example = "50%";
    };

    minAge = mkOption {
      description = "Sets the minimum age of images to be considered for deletion.";
      type = types.nullOr types.str;
      default = null;
      example = "1d";
    };

    keep = mkOption {
      description = "Prevents deletion of images for which repository:tag matches the specified regex.";
      type = types.listOf types.str;
      default = [ ];
      example = [ "^my-image" ];
    };

    deletionChunkSize = mkOption {
      description = "Removes specified quantity of images at a time.";
      type = types.int;
      default = 1;
      example = 10;
    };
  };

  config = mkIf cfg.enable {
    assertions = [
      {
        assertion = config.virtualisation.docker.enable;
        message = "docuum requires docker on the host";
      }
    ];

    systemd.services.docuum = {
      after = [ "docker.socket" ];
      requires = [ "docker.socket" ];
      wantedBy = [ "multi-user.target" ];
      path = [ config.virtualisation.docker.package ];
      environment.HOME = "/var/lib/docuum";

      serviceConfig = {
        DynamicUser = true;
        StateDirectory = "docuum";
        SupplementaryGroups = [ "docker" ];
        ExecStart = utils.escapeSystemdExecArgs (
          [
            (getExe pkgs.docuum)
            "--threshold"
            cfg.threshold
            "--deletion-chunk-size"
            cfg.deletionChunkSize
          ]
          ++ (concatMap (keep: [
            "--keep"
            keep
          ]) cfg.keep)
          ++ (optionals (cfg.minAge != null) [
            "--min-age"
            cfg.minAge
          ])
        );
      };
    };
  };
}