From 4874862732b036a174ab1a4d3fa9a6f4df7836e4 Mon Sep 17 00:00:00 2001 From: Markus Mueller Date: Tue, 17 Jan 2017 13:45:43 +0000 Subject: babeld module: init --- nixos/modules/services/networking/babeld.nix | 98 ++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 nixos/modules/services/networking/babeld.nix (limited to 'nixos/modules/services/networking/babeld.nix') 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 babeld8 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 babeld8 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 babeld8 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}"; + }; + + }; + +} -- cgit 1.4.1