summary refs log tree commit diff
path: root/nixos/modules/services/networking/babeld.nix
diff options
context:
space:
mode:
authorMarkus Mueller <john.subscriber@markus.institute>2017-01-17 13:45:43 +0000
committerFranz Pletz <fpletz@fnordicwalking.de>2017-11-05 21:15:23 +0100
commit4874862732b036a174ab1a4d3fa9a6f4df7836e4 (patch)
tree895bac872d1a04311637edf6635ab651c2cc7797 /nixos/modules/services/networking/babeld.nix
parent4a3e7564b0ef0b887919c0ac4d06c55a107d4397 (diff)
downloadnixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar.gz
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar.bz2
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar.lz
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar.xz
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.tar.zst
nixlib-4874862732b036a174ab1a4d3fa9a6f4df7836e4.zip
babeld module: init
Diffstat (limited to 'nixos/modules/services/networking/babeld.nix')
-rw-r--r--nixos/modules/services/networking/babeld.nix98
1 files changed, 98 insertions, 0 deletions
diff --git a/nixos/modules/services/networking/babeld.nix b/nixos/modules/services/networking/babeld.nix
new file mode 100644
index 000000000000..dd76bac9df76
--- /dev/null
+++ b/nixos/modules/services/networking/babeld.nix
@@ -0,0 +1,98 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+
+let
+
+  cfg = config.services.babeld;
+
+  paramsString = params:
+    concatMapStringsSep "" (name: "${name} ${boolToString (getAttr name params)}")
+                   (attrNames params);
+
+  interfaceConfig = name:
+    let
+      interface = getAttr name cfg.interfaces;
+    in
+    "interface ${name} ${paramsString interface}\n";
+
+  configFile = with cfg; pkgs.writeText "babeld.conf" (
+    (optionalString (cfg.interfaceDefaults != null) ''
+      default ${paramsString cfg.interfaceDefaults}
+    '')
+    + (concatMapStrings interfaceConfig (attrNames cfg.interfaces))
+    + extraConfig);
+
+in
+
+{
+
+  ###### interface
+
+  options = {
+
+    services.babeld = {
+
+      enable = mkOption {
+        default = false;
+        description = ''
+          Whether to run the babeld network routing daemon.
+        '';
+      };
+
+      interfaceDefaults = mkOption {
+        default = null;
+        description = ''
+          A set describing default parameters for babeld interfaces.
+          See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options.
+        '';
+        type = types.nullOr (types.attrsOf types.unspecified);
+        example =
+          {
+            wired = true;
+            "split-horizon" = true;
+          };
+      };
+
+      interfaces = mkOption {
+        default = {};
+        description = ''
+          A set describing babeld interfaces.
+          See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options.
+        '';
+        type = types.attrsOf (types.attrsOf types.unspecified);
+        example =
+          { enp0s2 =
+            { wired = true;
+              "hello-interval" = 5;
+              "split-horizon" = "auto";
+            };
+          };
+      };
+
+      extraConfig = mkOption {
+        default = "";
+        description = ''
+          Options that will be copied to babeld.conf.
+          See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details.
+        '';
+      };
+    };
+
+  };
+
+
+  ###### implementation
+
+  config = mkIf config.services.babeld.enable {
+
+    systemd.services.babeld = {
+      description = "Babel routing daemon";
+      after = [ "network.target" ];
+      wantedBy = [ "multi-user.target" ];
+      serviceConfig.ExecStart = "${pkgs.babeld}/bin/babeld -c ${configFile}";
+    };
+
+  };
+
+}