summary refs log tree commit diff
path: root/nixos/modules/services/network-filesystems/cachefilesd.nix
blob: 619813408405f7a8c3b07131805500ca03a77704 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
{ config, pkgs, lib, ... }:

with lib;

let

  cfg = config.services.cachefilesd;

  cfgFile = pkgs.writeText "cachefilesd.conf" ''
    dir ${cfg.cacheDir}
    ${cfg.extraConfig}
  '';

in

{
  options = {
    services.cachefilesd = {

      enable = mkOption {
        type = types.bool;
        default = false;
        description = "Whether to enable cachefilesd network filesystems caching daemon.";
      };

      cacheDir = mkOption {
        type = types.str;
        default = "/var/cache/fscache";
        description = "Directory to contain filesystem cache.";
      };

      extraConfig = mkOption {
        type = types.lines;
        default = "";
        example = "brun 10%";
        description = "Additional configuration file entries. See cachefilesd.conf(5) for more information.";
      };

    };
  };

  ###### implementation

  config = mkIf cfg.enable {

    systemd.services.cachefilesd = {
      description = "Local network file caching management daemon";
      wantedBy = [ "multi-user.target" ];
      path = [ pkgs.kmod pkgs.cachefilesd ];
      script = ''
        modprobe -qab cachefiles
        mkdir -p ${cfg.cacheDir}
        chmod 700 ${cfg.cacheDir}
        exec cachefilesd -n -f ${cfgFile}
      '';
    };

  };
}