about summary refs log tree commit diff
path: root/nixos/modules/services/networking/networkd-dispatcher.nix
blob: d13ca23368c5b98c9d5e21f0657e806e7f065319 (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
61
62
63
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.services.networkd-dispatcher;
in {
  options = {
    services.networkd-dispatcher = {

      enable = mkEnableOption (mdDoc ''
        Networkd-dispatcher service for systemd-networkd connection status
        change. See [https://gitlab.com/craftyguy/networkd-dispatcher](upstream instructions)
        for usage.
      '');

      scriptDir = mkOption {
        type = types.path;
        default = "/var/lib/networkd-dispatcher";
        description = mdDoc ''
          This directory is used for keeping various scripts read and run by
          networkd-dispatcher. See [https://gitlab.com/craftyguy/networkd-dispatcher](upstream instructions)
          for directory structure and script usage.
        '';
      };

    };
  };

  config = mkIf cfg.enable {

    systemd = {

      packages = [ pkgs.networkd-dispatcher ];
      services.networkd-dispatcher = {
        wantedBy = [ "multi-user.target" ];
        # Override existing ExecStart definition
        serviceConfig.ExecStart = [
          ""
          "${pkgs.networkd-dispatcher}/bin/networkd-dispatcher -v --script-dir ${cfg.scriptDir} $networkd_dispatcher_args"
        ];
      };

      # Directory structure required according to upstream instructions
      # https://gitlab.com/craftyguy/networkd-dispatcher
      tmpfiles.rules = [
        "d '${cfg.scriptDir}'               0750 root root - -"
        "d '${cfg.scriptDir}/routable.d'    0750 root root - -"
        "d '${cfg.scriptDir}/dormant.d'     0750 root root - -"
        "d '${cfg.scriptDir}/no-carrier.d'  0750 root root - -"
        "d '${cfg.scriptDir}/off.d'         0750 root root - -"
        "d '${cfg.scriptDir}/carrier.d'     0750 root root - -"
        "d '${cfg.scriptDir}/degraded.d'    0750 root root - -"
        "d '${cfg.scriptDir}/configuring.d' 0750 root root - -"
        "d '${cfg.scriptDir}/configured.d'  0750 root root - -"
      ];

    };


  };
}