mirror of
https://github.com/NixOS/nixpkgs.git
synced 2025-06-10 19:55:41 +03:00
nixos/services.bird-lg: remove with lib;
This commit is contained in:
parent
9ce866bc9b
commit
c666e7b2dd
1 changed files with 75 additions and 78 deletions
|
@ -1,176 +1,173 @@
|
|||
{ config, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
|
||||
let
|
||||
cfg = config.services.bird-lg;
|
||||
|
||||
stringOrConcat = sep: v: if builtins.isString v then v else concatStringsSep sep v;
|
||||
stringOrConcat = sep: v: if builtins.isString v then v else lib.concatStringsSep sep v;
|
||||
|
||||
frontend_args = let
|
||||
fe = cfg.frontend;
|
||||
in {
|
||||
"--servers" = concatStringsSep "," fe.servers;
|
||||
"--servers" = lib.concatStringsSep "," fe.servers;
|
||||
"--domain" = fe.domain;
|
||||
"--listen" = fe.listenAddress;
|
||||
"--proxy-port" = fe.proxyPort;
|
||||
"--whois" = fe.whois;
|
||||
"--dns-interface" = fe.dnsInterface;
|
||||
"--bgpmap-info" = concatStringsSep "," cfg.frontend.bgpMapInfo;
|
||||
"--bgpmap-info" = lib.concatStringsSep "," cfg.frontend.bgpMapInfo;
|
||||
"--title-brand" = fe.titleBrand;
|
||||
"--navbar-brand" = fe.navbar.brand;
|
||||
"--navbar-brand-url" = fe.navbar.brandURL;
|
||||
"--navbar-all-servers" = fe.navbar.allServers;
|
||||
"--navbar-all-url" = fe.navbar.allServersURL;
|
||||
"--net-specific-mode" = fe.netSpecificMode;
|
||||
"--protocol-filter" = concatStringsSep "," cfg.frontend.protocolFilter;
|
||||
"--protocol-filter" = lib.concatStringsSep "," cfg.frontend.protocolFilter;
|
||||
};
|
||||
|
||||
proxy_args = let
|
||||
px = cfg.proxy;
|
||||
in {
|
||||
"--allowed" = concatStringsSep "," px.allowedIPs;
|
||||
"--allowed" = lib.concatStringsSep "," px.allowedIPs;
|
||||
"--bird" = px.birdSocket;
|
||||
"--listen" = px.listenAddress;
|
||||
"--traceroute_bin" = px.traceroute.binary;
|
||||
"--traceroute_flags" = concatStringsSep " " px.traceroute.flags;
|
||||
"--traceroute_flags" = lib.concatStringsSep " " px.traceroute.flags;
|
||||
"--traceroute_raw" = px.traceroute.rawOutput;
|
||||
};
|
||||
|
||||
mkArgValue = value:
|
||||
if isString value
|
||||
then escapeShellArg value
|
||||
else if isBool value
|
||||
then boolToString value
|
||||
if lib.isString value
|
||||
then lib.escapeShellArg value
|
||||
else if lib.isBool value
|
||||
then lib.boolToString value
|
||||
else toString value;
|
||||
|
||||
filterNull = filterAttrs (_: v: v != "" && v != null && v != []);
|
||||
filterNull = lib.filterAttrs (_: v: v != "" && v != null && v != []);
|
||||
|
||||
argsAttrToList = args: mapAttrsToList (name: value: "${name} " + mkArgValue value ) (filterNull args);
|
||||
argsAttrToList = args: lib.mapAttrsToList (name: value: "${name} " + mkArgValue value ) (filterNull args);
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.bird-lg = {
|
||||
package = mkPackageOption pkgs "bird-lg" { };
|
||||
package = lib.mkPackageOption pkgs "bird-lg" { };
|
||||
|
||||
user = mkOption {
|
||||
type = types.str;
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "bird-lg";
|
||||
description = "User to run the service.";
|
||||
};
|
||||
|
||||
group = mkOption {
|
||||
type = types.str;
|
||||
group = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "bird-lg";
|
||||
description = "Group to run the service.";
|
||||
};
|
||||
|
||||
frontend = {
|
||||
enable = mkEnableOption "Bird Looking Glass Frontend Webserver";
|
||||
enable = lib.mkEnableOption "Bird Looking Glass Frontend Webserver";
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.str;
|
||||
listenAddress = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "127.0.0.1:5000";
|
||||
description = "Address to listen on.";
|
||||
};
|
||||
|
||||
proxyPort = mkOption {
|
||||
type = types.port;
|
||||
proxyPort = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8000;
|
||||
description = "Port bird-lg-proxy is running on.";
|
||||
};
|
||||
|
||||
domain = mkOption {
|
||||
type = types.str;
|
||||
domain = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
example = "dn42.lantian.pub";
|
||||
description = "Server name domain suffixes.";
|
||||
};
|
||||
|
||||
servers = mkOption {
|
||||
type = types.listOf types.str;
|
||||
servers = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
example = [ "gigsgigscloud" "hostdare" ];
|
||||
description = "Server name prefixes.";
|
||||
};
|
||||
|
||||
whois = mkOption {
|
||||
type = types.str;
|
||||
whois = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "whois.verisign-grs.com";
|
||||
description = "Whois server for queries.";
|
||||
};
|
||||
|
||||
dnsInterface = mkOption {
|
||||
type = types.str;
|
||||
dnsInterface = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "asn.cymru.com";
|
||||
description = "DNS zone to query ASN information.";
|
||||
};
|
||||
|
||||
bgpMapInfo = mkOption {
|
||||
type = types.listOf types.str;
|
||||
bgpMapInfo = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ "asn" "as-name" "ASName" "descr" ];
|
||||
description = "Information displayed in bgpmap.";
|
||||
};
|
||||
|
||||
titleBrand = mkOption {
|
||||
type = types.str;
|
||||
titleBrand = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "Bird-lg Go";
|
||||
description = "Prefix of page titles in browser tabs.";
|
||||
};
|
||||
|
||||
netSpecificMode = mkOption {
|
||||
type = types.str;
|
||||
netSpecificMode = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
example = "dn42";
|
||||
description = "Apply network-specific changes for some networks.";
|
||||
};
|
||||
|
||||
protocolFilter = mkOption {
|
||||
type = types.listOf types.str;
|
||||
protocolFilter = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "ospf" ];
|
||||
description = "Information displayed in bgpmap.";
|
||||
};
|
||||
|
||||
nameFilter = mkOption {
|
||||
type = types.str;
|
||||
nameFilter = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "";
|
||||
example = "^ospf";
|
||||
description = "Protocol names to hide in summary tables (RE2 syntax),";
|
||||
};
|
||||
|
||||
timeout = mkOption {
|
||||
type = types.int;
|
||||
timeout = lib.mkOption {
|
||||
type = lib.types.int;
|
||||
default = 120;
|
||||
description = "Time before request timed out, in seconds.";
|
||||
};
|
||||
|
||||
navbar = {
|
||||
brand = mkOption {
|
||||
type = types.str;
|
||||
brand = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "Bird-lg Go";
|
||||
description = "Brand to show in the navigation bar .";
|
||||
};
|
||||
|
||||
brandURL = mkOption {
|
||||
type = types.str;
|
||||
brandURL = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/";
|
||||
description = "URL of the brand to show in the navigation bar.";
|
||||
};
|
||||
|
||||
allServers = mkOption {
|
||||
type = types.str;
|
||||
allServers = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "ALL Servers";
|
||||
description = "Text of 'All server' button in the navigation bar.";
|
||||
};
|
||||
|
||||
allServersURL = mkOption {
|
||||
type = types.str;
|
||||
allServersURL = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "all";
|
||||
description = "URL of 'All servers' button.";
|
||||
};
|
||||
};
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = with types; either lines (listOf str);
|
||||
extraArgs = lib.mkOption {
|
||||
type = with lib.types; either lines (listOf str);
|
||||
default = [ ];
|
||||
description = ''
|
||||
Extra parameters documented [here](https://github.com/xddxdd/bird-lg-go#frontend).
|
||||
|
@ -183,50 +180,50 @@ in
|
|||
};
|
||||
|
||||
proxy = {
|
||||
enable = mkEnableOption "Bird Looking Glass Proxy";
|
||||
enable = lib.mkEnableOption "Bird Looking Glass Proxy";
|
||||
|
||||
listenAddress = mkOption {
|
||||
type = types.str;
|
||||
listenAddress = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "127.0.0.1:8000";
|
||||
description = "Address to listen on.";
|
||||
};
|
||||
|
||||
allowedIPs = mkOption {
|
||||
type = types.listOf types.str;
|
||||
allowedIPs = lib.mkOption {
|
||||
type = lib.types.listOf lib.types.str;
|
||||
default = [ ];
|
||||
example = [ "192.168.25.52" "192.168.25.53" "192.168.0.0/24" ];
|
||||
description = "List of IPs or networks to allow (default all allowed).";
|
||||
};
|
||||
|
||||
birdSocket = mkOption {
|
||||
type = types.str;
|
||||
birdSocket = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "/var/run/bird/bird.ctl";
|
||||
description = "Bird control socket path.";
|
||||
};
|
||||
|
||||
traceroute = {
|
||||
binary = mkOption {
|
||||
type = types.str;
|
||||
binary = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "${pkgs.traceroute}/bin/traceroute";
|
||||
defaultText = literalExpression ''"''${pkgs.traceroute}/bin/traceroute"'';
|
||||
defaultText = lib.literalExpression ''"''${pkgs.traceroute}/bin/traceroute"'';
|
||||
description = "Traceroute's binary path.";
|
||||
};
|
||||
|
||||
flags = mkOption {
|
||||
type = with types; listOf str;
|
||||
flags = lib.mkOption {
|
||||
type = with lib.types; listOf str;
|
||||
default = [ ];
|
||||
description = "Flags for traceroute process";
|
||||
};
|
||||
|
||||
rawOutput = mkOption {
|
||||
type = types.bool;
|
||||
rawOutput = lib.mkOption {
|
||||
type = lib.types.bool;
|
||||
default = false;
|
||||
description = "Display traceroute output in raw format.";
|
||||
};
|
||||
};
|
||||
|
||||
extraArgs = mkOption {
|
||||
type = with types; either lines (listOf str);
|
||||
extraArgs = lib.mkOption {
|
||||
type = with lib.types; either lines (listOf str);
|
||||
default = [ ];
|
||||
description = ''
|
||||
Extra parameters documented [here](https://github.com/xddxdd/bird-lg-go#proxy).
|
||||
|
@ -254,7 +251,7 @@ in
|
|||
;
|
||||
|
||||
systemd.services = {
|
||||
bird-lg-frontend = mkIf cfg.frontend.enable {
|
||||
bird-lg-frontend = lib.mkIf cfg.frontend.enable {
|
||||
enable = true;
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
@ -270,12 +267,12 @@ in
|
|||
};
|
||||
script = ''
|
||||
${cfg.package}/bin/frontend \
|
||||
${concatStringsSep " \\\n " (argsAttrToList frontend_args)} \
|
||||
${lib.concatStringsSep " \\\n " (argsAttrToList frontend_args)} \
|
||||
${stringOrConcat " " cfg.frontend.extraArgs}
|
||||
'';
|
||||
};
|
||||
|
||||
bird-lg-proxy = mkIf cfg.proxy.enable {
|
||||
bird-lg-proxy = lib.mkIf cfg.proxy.enable {
|
||||
enable = true;
|
||||
after = [ "network.target" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
@ -291,14 +288,14 @@ in
|
|||
};
|
||||
script = ''
|
||||
${cfg.package}/bin/proxy \
|
||||
${concatStringsSep " \\\n " (argsAttrToList proxy_args)} \
|
||||
${lib.concatStringsSep " \\\n " (argsAttrToList proxy_args)} \
|
||||
${stringOrConcat " " cfg.proxy.extraArgs}
|
||||
'';
|
||||
};
|
||||
};
|
||||
users = mkIf (cfg.frontend.enable || cfg.proxy.enable) {
|
||||
groups."bird-lg" = mkIf (cfg.group == "bird-lg") { };
|
||||
users."bird-lg" = mkIf (cfg.user == "bird-lg") {
|
||||
users = lib.mkIf (cfg.frontend.enable || cfg.proxy.enable) {
|
||||
groups."bird-lg" = lib.mkIf (cfg.group == "bird-lg") { };
|
||||
users."bird-lg" = lib.mkIf (cfg.user == "bird-lg") {
|
||||
description = "Bird Looking Glass user";
|
||||
extraGroups = lib.optionals (config.services.bird2.enable) [ "bird2" ];
|
||||
group = cfg.group;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue