mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-11-21 22:03:19 +01:00
42 lines
992 B
Nix
42 lines
992 B
Nix
|
{ config, pkgs, ... }:
|
||
|
{
|
||
|
# Based on https://github.com/NixOS/nixpkgs/blob/nixos-23.11/nixos/modules/services/misc/nix-gc.nix
|
||
|
|
||
|
assertions = [{
|
||
|
assertion = config.nix.enable;
|
||
|
message = ''nix-gc-7 requires nix.enable'';
|
||
|
}];
|
||
|
|
||
|
systemd.timers."nix-gc-7" = {
|
||
|
wantedBy = [ "timers.target" ];
|
||
|
partOf = [ "nix-gc-7.service" ];
|
||
|
timerConfig = {
|
||
|
OnCalendar = "weekly";
|
||
|
Persistent = true;
|
||
|
|
||
|
AccuracySec = "2d";
|
||
|
RandomizedDelaySec = "1d";
|
||
|
};
|
||
|
};
|
||
|
|
||
|
systemd.services."nix-gc-7" = {
|
||
|
description = "Keep only the most recent 7 system generations";
|
||
|
|
||
|
conflicts = [ "shutdown.target" "sleep.target" ];
|
||
|
before = [ "shutdown.target" "sleep.target" ];
|
||
|
|
||
|
serviceConfig = {
|
||
|
Type = "oneshot";
|
||
|
PrivateTmp = true;
|
||
|
|
||
|
Nice = 19;
|
||
|
IOSchedulingClass = "idle";
|
||
|
};
|
||
|
|
||
|
script = ''
|
||
|
set -eu -o pipefail
|
||
|
${config.nix.package.out}/bin/nix-env --delete-generations +7 --profile /nix/var/nix/profiles/system
|
||
|
'';
|
||
|
};
|
||
|
}
|