diff options
author | Pascal Bach <pascal.bach@nextrem.ch> | 2017-07-19 18:20:46 +0200 |
---|---|---|
committer | Franz Pletz <fpletz@fnordicwalking.de> | 2017-07-20 20:33:16 +0200 |
commit | 22acfd0327e02a110bb975e1692aef6d8c5524e3 (patch) | |
tree | be52866bbfce2dcea50ffbb0604bb35efe4c7af3 /nixos/modules | |
parent | b09c87ab47183a5a8e0184643e928edb24d2c19c (diff) | |
download | nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar.gz nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar.bz2 nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar.lz nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar.xz nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.tar.zst nixpkgs-22acfd0327e02a110bb975e1692aef6d8c5524e3.zip |
docker service: add option to do automatic pruning
This allows to run the prune job periodically on a machine. By default the if enabled the job is run once a week. The structure is similar to how system.autoUpgrade works.
Diffstat (limited to 'nixos/modules')
-rw-r--r-- | nixos/modules/virtualisation/docker.nix | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/nixos/modules/virtualisation/docker.nix b/nixos/modules/virtualisation/docker.nix index c26cae06cd1..25274c440e6 100644 --- a/nixos/modules/virtualisation/docker.nix +++ b/nixos/modules/virtualisation/docker.nix @@ -94,6 +94,37 @@ in <command>docker</command> daemon. ''; }; + + autoPrune = { + enable = mkOption { + type = types.bool; + default = false; + description = '' + Whether to periodically prune Docker resources. If enabled, a systemd timer will run + <literal>docker system prune -f</literal> once a day. + ''; + }; + + flags = mkOption { + type = types.listOf types.str; + default = []; + example = [ "--all" ]; + description = '' + Any additional flags passed to <command>docker system prune</command>. + ''; + }; + + dates = mkOption { + default = "weekly"; + type = types.str; + description = '' + Specification (in the format described by + <citerefentry><refentrytitle>systemd.time</refentrytitle> + <manvolnum>7</manvolnum></citerefentry>) of the time at + which the prune will occur. + ''; + }; + }; }; ###### implementation @@ -137,6 +168,22 @@ in SocketGroup = "docker"; }; }; + + + systemd.services.docker-prune = { + description = "Prune docker resources"; + + restartIfChanged = false; + unitConfig.X-StopOnRemoval = false; + + serviceConfig.Type = "oneshot"; + + script = '' + ${pkgs.docker}/bin/docker system prune -f ${toString cfg.autoPrune.flags} + ''; + + startAt = optional cfg.autoPrune.enable cfg.autoPrune.dates; + }; } ]); |