at 18.03-beta 2.5 kB view raw
1{ config, lib, pkgs, ... }: 2 3with lib; 4 5let 6 7 cfg = config.services.babeld; 8 9 conditionalBoolToString = value: if (isBool value) then (boolToString value) else (toString value); 10 11 paramsString = params: 12 concatMapStringsSep " " (name: "${name} ${conditionalBoolToString (getAttr name params)}") 13 (attrNames params); 14 15 interfaceConfig = name: 16 let 17 interface = getAttr name cfg.interfaces; 18 in 19 "interface ${name} ${paramsString interface}\n"; 20 21 configFile = with cfg; pkgs.writeText "babeld.conf" ( 22 (optionalString (cfg.interfaceDefaults != null) '' 23 default ${paramsString cfg.interfaceDefaults} 24 '') 25 + (concatMapStrings interfaceConfig (attrNames cfg.interfaces)) 26 + extraConfig); 27 28in 29 30{ 31 32 ###### interface 33 34 options = { 35 36 services.babeld = { 37 38 enable = mkOption { 39 default = false; 40 description = '' 41 Whether to run the babeld network routing daemon. 42 ''; 43 }; 44 45 interfaceDefaults = mkOption { 46 default = null; 47 description = '' 48 A set describing default parameters for babeld interfaces. 49 See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options. 50 ''; 51 type = types.nullOr (types.attrsOf types.unspecified); 52 example = 53 { 54 type = "tunnel"; 55 "split-horizon" = true; 56 }; 57 }; 58 59 interfaces = mkOption { 60 default = {}; 61 description = '' 62 A set describing babeld interfaces. 63 See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for options. 64 ''; 65 type = types.attrsOf (types.attrsOf types.unspecified); 66 example = 67 { enp0s2 = 68 { type = "wired"; 69 "hello-interval" = 5; 70 "split-horizon" = "auto"; 71 }; 72 }; 73 }; 74 75 extraConfig = mkOption { 76 default = ""; 77 description = '' 78 Options that will be copied to babeld.conf. 79 See <citerefentry><refentrytitle>babeld</refentrytitle><manvolnum>8</manvolnum></citerefentry> for details. 80 ''; 81 }; 82 }; 83 84 }; 85 86 87 ###### implementation 88 89 config = mkIf config.services.babeld.enable { 90 91 systemd.services.babeld = { 92 description = "Babel routing daemon"; 93 after = [ "network.target" ]; 94 wantedBy = [ "multi-user.target" ]; 95 serviceConfig.ExecStart = "${pkgs.babeld}/bin/babeld -c ${configFile}"; 96 }; 97 98 }; 99 100}