nixpkgs/nixos/modules/services/misc/folding-at-home.nix

69 lines
1.5 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, ... }:
with lib;
let
stateDir = "/var/lib/foldingathome";
cfg = config.services.foldingAtHome;
fahUser = "foldingathome";
in {
###### interface
options = {
services.foldingAtHome = {
enable = mkOption {
default = false;
description = ''
Whether to enable the Folding@Home to use idle CPU time.
'';
};
nickname = mkOption {
default = "Anonymous";
description = ''
A unique handle for statistics.
'';
};
config = mkOption {
default = "";
description = ''
Extra configuration. Contents will be added verbatim to the
configuration file.
'';
};
};
};
###### implementation
config = mkIf cfg.enable {
users.extraUsers = singleton
{ name = fahUser;
uid = config.ids.uids.foldingathome;
description = "Folding@Home user";
home = stateDir;
};
2016-01-06 07:50:18 +01:00
systemd.services.foldingathome = {
after = [ "network.target" ];
2016-01-06 07:50:18 +01:00
wantedBy = [ "multi-user.target" ];
preStart = ''
mkdir -m 0755 -p ${stateDir}
chown ${fahUser} ${stateDir}
cp -f ${pkgs.writeText "client.cfg" cfg.config} ${stateDir}/client.cfg
'';
2016-01-06 07:50:18 +01:00
script = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${fahUser} -c 'cd ${stateDir}; ${pkgs.foldingathome}/bin/fah6'";
};
2016-01-06 07:50:18 +01:00
services.foldingAtHome.config = ''
[settings]
username=${cfg.nickname}
'';
};
}