nixpkgs/nixos/modules/services/misc/fstrim.nix
Jörg Thalheim 7d8f1572d1 nixos: enable fstrim by default
The majority of users these days will install NixOS on SSD/NVME based
storage. Enabling fstrim ensures that the TRIM operation on this type of
storage is run at least once a week. This will improve performance and
life time of said devices. This also works in virtual machines as
formats such as qcow2 or vmdk support TRIM.
Ubuntu has a similar systemd timer also for quite a while enabled by
default.
Enabling this service will not increase the dependency closure as
util-linux is already part of the base system.
In case only filesystems that are not supported by fstrim are used, the
overhead is negelible as fstrim run in less than a second once a week.
2024-09-29 14:04:18 +02:00

45 lines
859 B
Nix

{ config, lib, pkgs, ... }:
let
cfg = config.services.fstrim;
in {
options = {
services.fstrim = {
enable = (lib.mkEnableOption "periodic SSD TRIM of mounted partitions in background" // {
default = true;
});
interval = lib.mkOption {
type = lib.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
{manpage}`systemd.time(7)`.
'';
};
};
};
config = lib.mkIf cfg.enable {
systemd.packages = [ pkgs.util-linux ];
systemd.timers.fstrim = {
timerConfig = {
OnCalendar = [ "" cfg.interval ];
};
wantedBy = [ "timers.target" ];
};
};
meta.maintainers = [ ];
}