@@ -0,0 +1,59 @@
1+{ config, pkgs, lib, ... }:
2+
3+with lib;
4+
5+let
6+
7+ cfg = config.services.cachefilesd;
8+
9+ cfgFile = pkgs.writeText "cachefilesd.conf" ''
10+ dir ${cfg.cacheDir}
11+ ${cfg.extraConfig}
12+ '';
13+
14+in
15+
16+{
17+ options = {
18+ services.cachefilesd = {
19+
20+ enable = mkOption {
21+ type = types.bool;
22+ default = false;
23+ description = "Whether to enable cachefilesd network filesystems caching daemon.";
24+ };
25+
26+ cacheDir = mkOption {
27+ type = types.str;
28+ default = "/var/cache/fscache";
29+ description = "Directory to contain filesystem cache.";
30+ };
31+
32+ extraConfig = mkOption {
33+ type = types.lines;
34+ default = "";
35+ example = "brun 10%";
36+ description = "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+ systemd.services.cachefilesd = {
47+ description = "Local network file caching management daemon";
48+ wantedBy = [ "multi-user.target" ];
49+ path = [ pkgs.kmod pkgs.cachefilesd ];
50+ script = ''
51+ modprobe -qab cachefiles
52+ mkdir -p ${cfg.cacheDir}
53+ chmod 700 ${cfg.cacheDir}
54+ exec cachefilesd -n -f ${cfgFile}
55+ '';
56+ };
57+
58+ };
59+}