1{
2 config,
3 pkgs,
4 lib,
5 ...
6}:
7let
8 cfg = config.services.gobgpd;
9 format = pkgs.formats.toml { };
10 confFile = format.generate "gobgpd.conf" cfg.settings;
11in
12{
13 options.services.gobgpd = {
14 enable = lib.mkEnableOption "GoBGP Routing Daemon";
15
16 settings = lib.mkOption {
17 type = format.type;
18 default = { };
19 description = ''
20 GoBGP configuration. Refer to
21 <https://github.com/osrg/gobgp#documentation>
22 for details on supported values.
23 '';
24 example = lib.literalExpression ''
25 {
26 global = {
27 config = {
28 as = 64512;
29 router-id = "192.168.255.1";
30 };
31 };
32 neighbors = [
33 {
34 config = {
35 neighbor-address = "10.0.255.1";
36 peer-as = 65001;
37 };
38 }
39 {
40 config = {
41 neighbor-address = "10.0.255.2";
42 peer-as = 65002;
43 };
44 }
45 ];
46 }
47 '';
48 };
49 };
50
51 config = lib.mkIf cfg.enable {
52 environment.systemPackages = [ pkgs.gobgpd ];
53 systemd.services.gobgpd = {
54 wantedBy = [ "multi-user.target" ];
55 after = [ "network.target" ];
56 description = "GoBGP Routing Daemon";
57 serviceConfig = {
58 Type = "notify";
59 ExecStartPre = "${pkgs.gobgpd}/bin/gobgpd -f ${confFile} -d";
60 ExecStart = "${pkgs.gobgpd}/bin/gobgpd -f ${confFile} --sdnotify";
61 ExecReload = "${pkgs.gobgpd}/bin/gobgpd -r";
62 DynamicUser = true;
63 AmbientCapabilities = "cap_net_bind_service";
64 };
65 };
66 };
67}