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