Unverified Commit b5c9cecb authored by Todd Brown's avatar Todd Brown Committed by GitHub
Browse files

nixos/docker: add auto prune randomizedDelaySec and persistent options (#301547)

docker: add auto prune randomizedDelaySec and persistent options

Options mirror nix garbage collection
parent 895f72e2
Loading
Loading
Loading
Loading
+35 −0
Original line number Diff line number Diff line
@@ -159,6 +159,34 @@ in
          which the prune will occur.
        '';
      };

      randomizedDelaySec = mkOption {
        default = "0";
        type = types.singleLineStr;
        example = "45min";
        description = ''
          Add a randomized delay before each auto prune.
          The delay will be chosen between zero and this value.
          This value must be a time span in the format specified by
          {manpage}`systemd.time(7)`
        '';
      };

      persistent = mkOption {
        default = true;
        type = types.bool;
        example = false;
        description = ''
          Takes a boolean argument. If true, the time when the service
          unit was last triggered is stored on disk. When the timer is
          activated, the service unit is triggered immediately if it
          would have been triggered at least once during the time when
          the timer was inactive. Such triggering is nonetheless
          subject to the delay imposed by RandomizedDelaySec=. This is
          useful to catch up on missed runs of the service when the
          system was powered down.
        '';
      };
    };

    package = mkPackageOption pkgs "docker" { };
@@ -254,6 +282,13 @@ in
        requires = [ "docker.service" ];
      };

      systemd.timers.docker-prune = mkIf cfg.autoPrune.enable {
        timerConfig = {
          RandomizedDelaySec = cfg.autoPrune.randomizedDelaySec;
          Persistent = cfg.autoPrune.persistent;
        };
      };

      assertions = [
        { assertion = cfg.enableNvidia && pkgs.stdenv.hostPlatform.isx86_64 -> config.hardware.graphics.enable32Bit or false;
          message = "Option enableNvidia on x86_64 requires 32-bit support libraries";