summary refs log tree commit diff
path: root/nixos/modules/services/misc/fstrim.nix
blob: a9fc04b46f0abeed7d0fb9271faf11505b89bbef (plain) (blame)
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, lib, pkgs, ... }:

with lib;

let

  cfg = config.services.fstrim;

in {

  options = {

    services.fstrim = {
      enable = mkEnableOption "periodic SSD TRIM of mounted partitions in background";

      interval = mkOption {
        type = types.str;
        default = "weekly";
        description = ''
          How often we run fstrim. For most desktop and server systems
          a sufficient trimming frequency is once a week.

          The format is described in
          <citerefentry><refentrytitle>systemd.time</refentrytitle>
          <manvolnum>7</manvolnum></citerefentry>.
        '';
      };
    };

  };

  config = mkIf cfg.enable {

    systemd.packages = [ pkgs.util-linux ];

    systemd.timers.fstrim = {
      timerConfig = {
        OnCalendar = cfg.interval;
      };
      wantedBy = [ "timers.target" ];
    };

  };

  meta.maintainers = with maintainers; [ ];
}