From 88782420cda654b630743fee2ce7025dfc5eef45 Mon Sep 17 00:00:00 2001 From: Eva Emmerich Date: Fri, 10 Apr 2026 11:52:50 +0200 Subject: [PATCH] docker: add option to prune all volumes when auto pruning it is not possible to prune all volumes using `docker system prune`, the best that can be done is the removal of anonymous volumes using the `--volumes` flag https://docs.docker.com/reference/cli/docker/system/prune/#description add new option `autoPrune.allVolumes.enable` which runs `docker volume prune --all --force` when the system prune service runs. https://docs.docker.com/reference/cli/docker/volume/prune/ add new test for this feature, and the autoPrune feature --- nixos/modules/virtualisation/docker.nix | 66 +++++++++++++++++++++---- nixos/tests/all-tests.nix | 1 + nixos/tests/docker-autoprune.nix | 57 +++++++++++++++++++++ 3 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 nixos/tests/docker-autoprune.nix diff --git a/nixos/modules/virtualisation/docker.nix b/nixos/modules/virtualisation/docker.nix index 099d60423f00..26b9e9cbaf73 100644 --- a/nixos/modules/virtualisation/docker.nix +++ b/nixos/modules/virtualisation/docker.nix @@ -157,6 +157,14 @@ in Whether to periodically prune Docker resources. If enabled, a systemd timer will run `docker system prune -f` as specified by the `dates` option. + + NOTE: by default this does not prune volumes. Anonymous volumes + can be pruned by passing "--volumes" to [autoPrune.flags](#opt-virtualisation.docker.autoPrune.flags). + + To prune all volumes (not just anonymous ones) [`autoPrune.allVolumes.enable`](#opt-virtualisation.docker.autoPrune.allVolumes.enable) + must be used. + + See [upstream documentation](https://docs.docker.com/reference/cli/docker/system/prune/#description) for further information. ''; }; @@ -206,6 +214,28 @@ in system was powered down. ''; }; + + allVolumes = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to periodically prune all Docker volumes when auto pruning other docker resources + by running {command}`docker volume prune --force --all` + + To prune only anonymous volumes, instead pass `--volumes` to `autoPrune.flags` + ''; + }; + + flags = mkOption { + type = types.listOf types.str; + default = [ ]; + example = [ "--filter=label=