1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7 cfg = config.networking.fan;
8 modprobe = "${pkgs.kmod}/bin/modprobe";
9
10in
11
12{
13
14 ###### interface
15
16 options = {
17
18 networking.fan = {
19
20 enable = mkEnableOption "FAN Networking";
21
22 };
23
24 };
25
26
27 ###### implementation
28
29 config = mkIf cfg.enable {
30
31 environment.systemPackages = [ pkgs.fanctl ];
32
33 systemd.services.fan = {
34 description = "FAN Networking";
35 wantedBy = [ "multi-user.target" ];
36 after = [ "network-online.target" ];
37 before = [ "docker.service" ];
38 restartIfChanged = false;
39 preStart = ''
40 if [ ! -f /proc/sys/net/fan/version ]; then
41 ${modprobe} ipip
42 if [ ! -f /proc/sys/net/fan/version ]; then
43 echo "The Fan Networking patches have not been applied to this kernel!" 1>&2
44 exit 1
45 fi
46 fi
47
48 mkdir -p /var/lib/fan-networking
49 '';
50 serviceConfig = {
51 Type = "oneshot";
52 RemainAfterExit = true;
53 ExecStart = "${pkgs.fanctl}/bin/fanctl up -a";
54 ExecStop = "${pkgs.fanctl}/bin/fanctl down -a";
55 };
56 };
57
58 };
59
60}