at 25.11-pre 2.1 kB view raw
1{ 2 config, 3 pkgs, 4 lib, 5 utils, 6 ... 7}: 8 9let 10 cfg = config.services.docuum; 11 inherit (lib) 12 mkIf 13 mkEnableOption 14 mkOption 15 getExe 16 types 17 optionals 18 concatMap 19 ; 20in 21{ 22 options.services.docuum = { 23 enable = mkEnableOption "docuum daemon"; 24 25 threshold = mkOption { 26 description = "Threshold for deletion in bytes, like `10 GB`, `10 GiB`, `10GB` or percentage-based thresholds like `50%`"; 27 type = types.str; 28 default = "10 GB"; 29 example = "50%"; 30 }; 31 32 minAge = mkOption { 33 description = "Sets the minimum age of images to be considered for deletion."; 34 type = types.nullOr types.str; 35 default = null; 36 example = "1d"; 37 }; 38 39 keep = mkOption { 40 description = "Prevents deletion of images for which repository:tag matches the specified regex."; 41 type = types.listOf types.str; 42 default = [ ]; 43 example = [ "^my-image" ]; 44 }; 45 46 deletionChunkSize = mkOption { 47 description = "Removes specified quantity of images at a time."; 48 type = types.int; 49 default = 1; 50 example = 10; 51 }; 52 }; 53 54 config = mkIf cfg.enable { 55 assertions = [ 56 { 57 assertion = config.virtualisation.docker.enable; 58 message = "docuum requires docker on the host"; 59 } 60 ]; 61 62 systemd.services.docuum = { 63 after = [ "docker.socket" ]; 64 requires = [ "docker.socket" ]; 65 wantedBy = [ "multi-user.target" ]; 66 path = [ config.virtualisation.docker.package ]; 67 environment.HOME = "/var/lib/docuum"; 68 69 serviceConfig = { 70 DynamicUser = true; 71 StateDirectory = "docuum"; 72 SupplementaryGroups = [ "docker" ]; 73 ExecStart = utils.escapeSystemdExecArgs ( 74 [ 75 (getExe pkgs.docuum) 76 "--threshold" 77 cfg.threshold 78 "--deletion-chunk-size" 79 cfg.deletionChunkSize 80 ] 81 ++ (concatMap (keep: [ 82 "--keep" 83 keep 84 ]) cfg.keep) 85 ++ (optionals (cfg.minAge != null) [ 86 "--min-age" 87 cfg.minAge 88 ]) 89 ); 90 }; 91 }; 92 }; 93}