2015-08-09 23:13:40 +00:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2015-08-21 20:18:09 +00:00
|
|
|
cfg = config.networking.fan;
|
2015-08-09 23:13:40 +00:00
|
|
|
modprobe = "${config.system.sbin.modprobe}/sbin/modprobe";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2015-08-21 20:18:09 +00:00
|
|
|
networking.fan = {
|
2015-08-09 23:13:40 +00:00
|
|
|
|
2015-08-21 20:18:09 +00:00
|
|
|
enable = mkEnableOption "FAN Networking";
|
2015-08-09 23:13:40 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.fanctl ];
|
|
|
|
|
2015-08-21 20:18:09 +00:00
|
|
|
systemd.services.fan = {
|
|
|
|
description = "FAN Networking";
|
2015-08-09 23:13:40 +00:00
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "network-online.target" ];
|
|
|
|
before = [ "docker.service" ];
|
|
|
|
restartIfChanged = false;
|
|
|
|
preStart = ''
|
|
|
|
if [ ! -f /proc/sys/net/fan/version ]; then
|
|
|
|
${modprobe} ipip
|
|
|
|
if [ ! -f /proc/sys/net/fan/version ]; then
|
2015-08-21 20:18:09 +00:00
|
|
|
echo "The Fan Networking patches have not been applied to this kernel!" 1>&2
|
2015-08-09 23:13:40 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-08-21 20:18:09 +00:00
|
|
|
mkdir -p /var/lib/fan-networking
|
2015-08-09 23:13:40 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStart = "${pkgs.fanctl}/bin/fanctl up -a";
|
|
|
|
ExecStop = "${pkgs.fanctl}/bin/fanctl down -a";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|