1 { config, lib, pkgs, ... }:
3 cfg = config.services.bird-lg;
5 stringOrConcat = sep: v: if builtins.isString v then v else lib.concatStringsSep sep v;
10 "--servers" = lib.concatStringsSep "," fe.servers;
11 "--domain" = fe.domain;
12 "--listen" = fe.listenAddress;
13 "--proxy-port" = fe.proxyPort;
15 "--dns-interface" = fe.dnsInterface;
16 "--bgpmap-info" = lib.concatStringsSep "," cfg.frontend.bgpMapInfo;
17 "--title-brand" = fe.titleBrand;
18 "--navbar-brand" = fe.navbar.brand;
19 "--navbar-brand-url" = fe.navbar.brandURL;
20 "--navbar-all-servers" = fe.navbar.allServers;
21 "--navbar-all-url" = fe.navbar.allServersURL;
22 "--net-specific-mode" = fe.netSpecificMode;
23 "--protocol-filter" = lib.concatStringsSep "," cfg.frontend.protocolFilter;
29 "--allowed" = lib.concatStringsSep "," px.allowedIPs;
30 "--bird" = px.birdSocket;
31 "--listen" = px.listenAddress;
32 "--traceroute_bin" = px.traceroute.binary;
33 "--traceroute_flags" = lib.concatStringsSep " " px.traceroute.flags;
34 "--traceroute_raw" = px.traceroute.rawOutput;
39 then lib.escapeShellArg value
40 else if lib.isBool value
41 then lib.boolToString value
44 filterNull = lib.filterAttrs (_: v: v != "" && v != null && v != []);
46 argsAttrToList = args: lib.mapAttrsToList (name: value: "${name} " + mkArgValue value ) (filterNull args);
51 package = lib.mkPackageOption pkgs "bird-lg" { };
56 description = "User to run the service.";
59 group = lib.mkOption {
62 description = "Group to run the service.";
66 enable = lib.mkEnableOption "Bird Looking Glass Frontend Webserver";
68 listenAddress = lib.mkOption {
70 default = "127.0.0.1:5000";
71 description = "Address to listen on.";
74 proxyPort = lib.mkOption {
75 type = lib.types.port;
77 description = "Port bird-lg-proxy is running on.";
80 domain = lib.mkOption {
82 example = "dn42.lantian.pub";
83 description = "Server name domain suffixes.";
86 servers = lib.mkOption {
87 type = lib.types.listOf lib.types.str;
88 example = [ "gigsgigscloud" "hostdare" ];
89 description = "Server name prefixes.";
92 whois = lib.mkOption {
94 default = "whois.verisign-grs.com";
95 description = "Whois server for queries.";
98 dnsInterface = lib.mkOption {
100 default = "asn.cymru.com";
101 description = "DNS zone to query ASN information.";
104 bgpMapInfo = lib.mkOption {
105 type = lib.types.listOf lib.types.str;
106 default = [ "asn" "as-name" "ASName" "descr" ];
107 description = "Information displayed in bgpmap.";
110 titleBrand = lib.mkOption {
111 type = lib.types.str;
112 default = "Bird-lg Go";
113 description = "Prefix of page titles in browser tabs.";
116 netSpecificMode = lib.mkOption {
117 type = lib.types.str;
120 description = "Apply network-specific changes for some networks.";
123 protocolFilter = lib.mkOption {
124 type = lib.types.listOf lib.types.str;
126 example = [ "ospf" ];
127 description = "Information displayed in bgpmap.";
130 nameFilter = lib.mkOption {
131 type = lib.types.str;
134 description = "Protocol names to hide in summary tables (RE2 syntax),";
137 timeout = lib.mkOption {
138 type = lib.types.int;
140 description = "Time before request timed out, in seconds.";
144 brand = lib.mkOption {
145 type = lib.types.str;
146 default = "Bird-lg Go";
147 description = "Brand to show in the navigation bar .";
150 brandURL = lib.mkOption {
151 type = lib.types.str;
153 description = "URL of the brand to show in the navigation bar.";
156 allServers = lib.mkOption {
157 type = lib.types.str;
158 default = "ALL Servers";
159 description = "Text of 'All server' button in the navigation bar.";
162 allServersURL = lib.mkOption {
163 type = lib.types.str;
165 description = "URL of 'All servers' button.";
169 extraArgs = lib.mkOption {
170 type = with lib.types; either lines (listOf str);
173 Extra parameters documented [here](https://github.com/xddxdd/bird-lg-go#frontend).
176 Passing lines (plain strings) is deprecated in favour of passing lists of strings.
183 enable = lib.mkEnableOption "Bird Looking Glass Proxy";
185 listenAddress = lib.mkOption {
186 type = lib.types.str;
187 default = "127.0.0.1:8000";
188 description = "Address to listen on.";
191 allowedIPs = lib.mkOption {
192 type = lib.types.listOf lib.types.str;
194 example = [ "192.168.25.52" "192.168.25.53" "192.168.0.0/24" ];
195 description = "List of IPs or networks to allow (default all allowed).";
198 birdSocket = lib.mkOption {
199 type = lib.types.str;
200 default = "/var/run/bird/bird.ctl";
201 description = "Bird control socket path.";
205 binary = lib.mkOption {
206 type = lib.types.str;
207 default = "${pkgs.traceroute}/bin/traceroute";
208 defaultText = lib.literalExpression ''"''${pkgs.traceroute}/bin/traceroute"'';
209 description = "Traceroute's binary path.";
212 flags = lib.mkOption {
213 type = with lib.types; listOf str;
215 description = "Flags for traceroute process";
218 rawOutput = lib.mkOption {
219 type = lib.types.bool;
221 description = "Display traceroute output in raw format.";
225 extraArgs = lib.mkOption {
226 type = with lib.types; either lines (listOf str);
229 Extra parameters documented [here](https://github.com/xddxdd/bird-lg-go#proxy).
232 Passing lines (plain strings) is deprecated in favour of passing lists of strings.
240 ###### implementation
245 lib.optional (cfg.frontend.enable && builtins.isString cfg.frontend.extraArgs) ''
246 Passing strings to `services.bird-lg.frontend.extraOptions' is deprecated. Please pass a list of strings instead.
248 ++ lib.optional (cfg.proxy.enable && builtins.isString cfg.proxy.extraArgs) ''
249 Passing strings to `services.bird-lg.proxy.extraOptions' is deprecated. Please pass a list of strings instead.
254 bird-lg-frontend = lib.mkIf cfg.frontend.enable {
256 after = [ "network.target" ];
257 wantedBy = [ "multi-user.target" ];
258 description = "Bird Looking Glass Frontend Webserver";
261 Restart = "on-failure";
262 ProtectSystem = "full";
264 MemoryDenyWriteExecute = "yes";
269 ${cfg.package}/bin/frontend \
270 ${lib.concatStringsSep " \\\n " (argsAttrToList frontend_args)} \
271 ${stringOrConcat " " cfg.frontend.extraArgs}
275 bird-lg-proxy = lib.mkIf cfg.proxy.enable {
277 after = [ "network.target" ];
278 wantedBy = [ "multi-user.target" ];
279 description = "Bird Looking Glass Proxy";
282 Restart = "on-failure";
283 ProtectSystem = "full";
285 MemoryDenyWriteExecute = "yes";
290 ${cfg.package}/bin/proxy \
291 ${lib.concatStringsSep " \\\n " (argsAttrToList proxy_args)} \
292 ${stringOrConcat " " cfg.proxy.extraArgs}
296 users = lib.mkIf (cfg.frontend.enable || cfg.proxy.enable) {
297 groups."bird-lg" = lib.mkIf (cfg.group == "bird-lg") { };
298 users."bird-lg" = lib.mkIf (cfg.user == "bird-lg") {
299 description = "Bird Looking Glass user";
300 extraGroups = lib.optionals (config.services.bird2.enable) [ "bird2" ];
307 meta.maintainers = with lib.maintainers; [