at 23.11-pre 1.4 kB view raw
1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.cachefilesd; 8 9 cfgFile = pkgs.writeText "cachefilesd.conf" '' 10 dir ${cfg.cacheDir} 11 ${cfg.extraConfig} 12 ''; 13 14in 15 16{ 17 options = { 18 services.cachefilesd = { 19 20 enable = mkOption { 21 type = types.bool; 22 default = false; 23 description = lib.mdDoc "Whether to enable cachefilesd network filesystems caching daemon."; 24 }; 25 26 cacheDir = mkOption { 27 type = types.str; 28 default = "/var/cache/fscache"; 29 description = lib.mdDoc "Directory to contain filesystem cache."; 30 }; 31 32 extraConfig = mkOption { 33 type = types.lines; 34 default = ""; 35 example = "brun 10%"; 36 description = lib.mdDoc "Additional configuration file entries. See cachefilesd.conf(5) for more information."; 37 }; 38 39 }; 40 }; 41 42 ###### implementation 43 44 config = mkIf cfg.enable { 45 46 boot.kernelModules = [ "cachefiles" ]; 47 48 systemd.services.cachefilesd = { 49 description = "Local network file caching management daemon"; 50 wantedBy = [ "multi-user.target" ]; 51 serviceConfig = { 52 Type = "exec"; 53 ExecStart = "${pkgs.cachefilesd}/bin/cachefilesd -n -f ${cfgFile}"; 54 Restart = "on-failure"; 55 PrivateTmp = true; 56 }; 57 }; 58 59 systemd.tmpfiles.rules = [ 60 "d ${cfg.cacheDir} 0700 root root - -" 61 ]; 62 }; 63}