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