2014-04-14 15:26:48 +01:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
with lib;
|
2010-09-16 03:06:44 +01:00
|
|
|
let
|
|
|
|
stateDir = "/var/lib/foldingathome";
|
|
|
|
cfg = config.services.foldingAtHome;
|
|
|
|
fahUser = "foldingathome";
|
|
|
|
in {
|
|
|
|
|
|
|
|
###### interface
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-16 03:06:44 +01:00
|
|
|
options = {
|
2011-09-14 19:20:50 +01:00
|
|
|
|
2010-09-16 03:06:44 +01:00
|
|
|
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 = ''
|
2011-09-14 19:20:50 +01:00
|
|
|
Extra configuration. Contents will be added verbatim to the
|
2010-09-16 03:06:44 +01:00
|
|
|
configuration file.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
users.extraUsers = singleton
|
|
|
|
{ name = fahUser;
|
2014-04-29 09:51:42 +01:00
|
|
|
uid = config.ids.uids.foldingathome;
|
2010-09-16 03:06:44 +01:00
|
|
|
description = "Folding@Home user";
|
|
|
|
home = stateDir;
|
|
|
|
};
|
|
|
|
|
|
|
|
jobs.foldingAtHome =
|
|
|
|
{ name = "foldingathome";
|
|
|
|
|
|
|
|
startOn = "started network-interfaces";
|
|
|
|
stopOn = "stopping network-interfaces";
|
|
|
|
|
|
|
|
preStart =
|
|
|
|
''
|
|
|
|
mkdir -m 0755 -p ${stateDir}
|
|
|
|
chown ${fahUser} ${stateDir}
|
|
|
|
cp -f ${pkgs.writeText "client.cfg" cfg.config} ${stateDir}/client.cfg
|
|
|
|
'';
|
|
|
|
exec = "${pkgs.su}/bin/su -s ${pkgs.stdenv.shell} ${fahUser} -c 'cd ${stateDir}; ${pkgs.foldingathome}/bin/fah6'";
|
|
|
|
};
|
|
|
|
|
|
|
|
services.foldingAtHome.config = ''
|
|
|
|
[settings]
|
|
|
|
username=${cfg.nickname}
|
|
|
|
'';
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-09-14 19:20:50 +01:00
|
|
|
}
|