mirror of
https://codeberg.org/privacy1st/nix-git
synced 2024-12-23 02:36:05 +01:00
fix: weekly docker prune
This commit is contained in:
parent
20e590c1c1
commit
e8ee73bdd9
@ -13,20 +13,38 @@
|
||||
# As we use btrfs, we enable the according storageDriver option.
|
||||
storageDriver = "btrfs";
|
||||
|
||||
# Run `docker system prune -f` every week.
|
||||
# Run `docker system prune -f ${autoPrune.flags}` every week.
|
||||
autoPrune.enable = true;
|
||||
autoPrune.dates = "weekly";
|
||||
# https://docs.docker.com/engine/reference/commandline/system_prune/#options
|
||||
autoPrune.flags = [
|
||||
"--all"
|
||||
"--volumes"
|
||||
# https://docs.docker.com/engine/reference/commandline/system_prune/#filter
|
||||
# https://pkg.go.dev/maze.io/x/duration#ParseDuration
|
||||
"--filter until=7d"
|
||||
# `7d` could not be parsed, thus we use `168h`
|
||||
"--filter until=168h"
|
||||
# `--volumes` can't be used together with `--filter`.
|
||||
# Thus we added our own service below.
|
||||
#--volumes
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
# Prune docker volumes.
|
||||
# This is a slightly modified copy of https://github.com/NixOS/nixpkgs/blob/5a237aecb57296f67276ac9ab296a41c23981f56/nixos/modules/virtualisation/docker.nix#L211C5-L226
|
||||
systemd.services."docker-prune-volumes" = {
|
||||
description = "Prune docker volumes";
|
||||
restartIfChanged = false;
|
||||
unitConfig.X-StopOnRemoval = false;
|
||||
serviceConfig.Type = "oneshot";
|
||||
script = ''
|
||||
${pkgs.docker}/bin/docker system prune -f --all --volumes
|
||||
'';
|
||||
startAt = "weekly";
|
||||
after = [ "docker.service" ];
|
||||
requires = [ "docker.service" ];
|
||||
};
|
||||
|
||||
# Monitor unhealthy Docker containers.
|
||||
systemd.timers."docker-health" = {
|
||||
wantedBy = [ "timers.target" ];
|
||||
|
Loading…
Reference in New Issue
Block a user