2015-08-10 01:13:40 +02:00
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
2015-08-21 22:18:09 +02:00
|
|
|
cfg = config.networking.fan;
|
2015-08-10 01:13:40 +02:00
|
|
|
modprobe = "${config.system.sbin.modprobe}/sbin/modprobe";
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
2015-08-21 22:18:09 +02:00
|
|
|
networking.fan = {
|
2015-08-10 01:13:40 +02:00
|
|
|
|
2015-08-21 22:18:09 +02:00
|
|
|
enable = mkEnableOption "FAN Networking";
|
2015-08-10 01:13:40 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
|
|
|
|
|
|
|
environment.systemPackages = [ pkgs.fanctl ];
|
|
|
|
|
2015-08-21 22:18:09 +02:00
|
|
|
systemd.services.fan = {
|
|
|
|
description = "FAN Networking";
|
2015-08-10 01:13:40 +02: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 22:18:09 +02:00
|
|
|
echo "The Fan Networking patches have not been applied to this kernel!" 1>&2
|
2015-08-10 01:13:40 +02:00
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2015-08-21 22:18:09 +02:00
|
|
|
mkdir -p /var/lib/fan-networking
|
2015-08-10 01:13:40 +02:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
ExecStart = "${pkgs.fanctl}/bin/fanctl up -a";
|
|
|
|
ExecStop = "${pkgs.fanctl}/bin/fanctl down -a";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|