2020-04-24 23:36:52 +00:00
|
|
|
{ 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;
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Whether to enable cachefilesd network filesystems caching daemon.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
cacheDir = mkOption {
|
|
|
|
type = types.str;
|
|
|
|
default = "/var/cache/fscache";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Directory to contain filesystem cache.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extraConfig = mkOption {
|
|
|
|
type = types.lines;
|
|
|
|
default = "";
|
|
|
|
example = "brun 10%";
|
2022-08-12 12:06:08 +00:00
|
|
|
description = lib.mdDoc "Additional configuration file entries. See cachefilesd.conf(5) for more information.";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
boot.kernelModules = [ "cachefiles" ];
|
|
|
|
|
2020-04-24 23:36:52 +00:00
|
|
|
systemd.services.cachefilesd = {
|
|
|
|
description = "Local network file caching management daemon";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2020-09-25 04:45:31 +00:00
|
|
|
serviceConfig = {
|
|
|
|
Type = "exec";
|
|
|
|
ExecStart = "${pkgs.cachefilesd}/bin/cachefilesd -n -f ${cfgFile}";
|
|
|
|
Restart = "on-failure";
|
|
|
|
PrivateTmp = true;
|
|
|
|
};
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
2020-09-25 04:45:31 +00:00
|
|
|
systemd.tmpfiles.rules = [
|
|
|
|
"d ${cfg.cacheDir} 0700 root root - -"
|
|
|
|
];
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
}
|