summary refs log tree commit diff
path: root/nixos/modules/services/networking/fan.nix
blob: 3170567e5b4a4660956b05454f2d86f751a51086 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
{ config, lib, pkgs, ... }:

with lib;

let

  cfg = config.networking.fan;
  modprobe = "${config.system.sbin.modprobe}/sbin/modprobe";

in

{

  ###### interface

  options = {

    networking.fan = {

      enable = mkEnableOption "FAN Networking";

    };

  };


  ###### implementation

  config = mkIf cfg.enable {

    environment.systemPackages = [ pkgs.fanctl ];

    systemd.services.fan = {
      description = "FAN Networking";
      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
            echo "The Fan Networking patches have not been applied to this kernel!" 1>&2
            exit 1
          fi
        fi

        mkdir -p /var/lib/fan-networking
      '';
      serviceConfig = {
        Type = "oneshot";
        RemainAfterExit = true;
        ExecStart = "${pkgs.fanctl}/bin/fanctl up -a";
        ExecStop = "${pkgs.fanctl}/bin/fanctl down -a";
      };
    };

  };

}