summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFelix Buehler <account@buehler.rocks>2022-12-24 11:58:27 +0100
committerFelix Buehler <account@buehler.rocks>2022-12-24 12:01:16 +0100
commit661751120058a4d28229750e2118aa04fee19a0e (patch)
tree099f058b9733f5e14f8bb35ced935677eff39ced
parentb139bf1c47c6660cd0f5e2d3448e05e82da2ea6b (diff)
nixos/podman: add autoPrune option
-rw-r--r--nixos/modules/virtualisation/podman/default.nix48
1 files changed, 48 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/podman/default.nix b/nixos/modules/virtualisation/podman/default.nix
index 118bf82cdd66..13bbb4471ea5 100644
--- a/nixos/modules/virtualisation/podman/default.nix
+++ b/nixos/modules/virtualisation/podman/default.nix
@@ -109,6 +109,37 @@ in
'';
};
+ autoPrune = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = lib.mdDoc ''
+ Whether to periodically prune Podman resources. If enabled, a
+ systemd timer will run `podman system prune -f`
+ as specified by the `dates` option.
+ '';
+ };
+
+ flags = mkOption {
+ type = types.listOf types.str;
+ default = [];
+ example = [ "--all" ];
+ description = lib.mdDoc ''
+ Any additional flags passed to {command}`podman system prune`.
+ '';
+ };
+
+ dates = mkOption {
+ default = "weekly";
+ type = types.str;
+ description = lib.mdDoc ''
+ Specification (in the format described by
+ {manpage}`systemd.time(7)`) of the time at
+ which the prune will occur.
+ '';
+ };
+ };
+
package = lib.mkOption {
type = types.package;
default = podmanPackage;
@@ -151,6 +182,23 @@ in
ExecStart = [ "" "${cfg.package}/bin/podman $LOGGING system service" ];
};
+ systemd.services.podman-prune = {
+ description = "Prune podman resources";
+
+ restartIfChanged = false;
+ unitConfig.X-StopOnRemoval = false;
+
+ serviceConfig.Type = "oneshot";
+
+ script = ''
+ ${cfg.package}/bin/podman system prune -f ${toString cfg.autoPrune.flags}
+ '';
+
+ startAt = lib.optional cfg.autoPrune.enable cfg.autoPrune.dates;
+ after = [ "podman.service" ];
+ requires = [ "podman.service" ];
+ };
+
systemd.sockets.podman.wantedBy = [ "sockets.target" ];
systemd.sockets.podman.socketConfig.SocketGroup = "podman";