···
+
{ config, lib, pkgs, ... }:
+
cfg = config.services.frr;
+
allServices = services ++ [ "zebra" ];
+
isEnabled = service: cfg.${service}.enable;
+
daemonName = service: if service == "zebra" then service else "${service}d";
+
if scfg.configFile != null then scfg.configFile
+
else pkgs.writeText "${daemonName service}.conf"
+
! FRR ${daemonName service} configuration
+
hostname ${config.networking.hostName}
+
service password-encryption
+
serviceOptions = service:
+
enable = mkEnableOption "the FRR ${toUpper service} routing protocol";
+
configFile = mkOption {
+
type = types.nullOr types.path;
+
example = "/etc/frr/${daemonName service}.conf";
+
Configuration file to use for FRR ${daemonName service}.
+
By default the NixOS generated files are used.
+
network 10.0.0.0/8 area 0
+
neighbor 10.0.0.1 remote-as 65001
+
examples.${service} or "";
+
${daemonName service} configuration statements.
+
vtyListenAddress = mkOption {
+
Address to bind to for the VTY interface.
+
vtyListenPort = mkOption {
+
type = types.nullOr types.int;
+
TCP Port to bind to for the VTY interface.
+
options.services.frr = {
+
zebra = (serviceOptions "zebra") // {
+
default = any isEnabled services;
+
Whether to enable the Zebra routing manager.
+
The Zebra routing manager is automatically enabled
+
if any routing protocols are configured.
+
{ options.services.frr = (genAttrs services serviceOptions); }
+
config = mkIf (any isEnabled allServices) {
+
environment.systemPackages = [
+
pkgs.frr # for the vtysh tool
+
description = "FRR daemon user";
+
# Members of the frrvty group can use vtysh to inspect the FRR daemons
+
frrvty = { members = [ "frr" ]; };
+
name = "frr/${service}.conf";
+
value.source = configFile service;
+
(map mkEtcLink (filter isEnabled allServices))) // {
+
"frr/vtysh.conf".text = "";
+
systemd.tmpfiles.rules = [
+
"d /run/frr 0750 frr frr -"
+
daemon = daemonName service;
+
nameValuePair daemon ({
+
wantedBy = [ "multi-user.target" ];
+
after = [ "network-pre.target" "systemd-sysctl.service" ] ++ lib.optionals (service != "zebra") [ "zebra.service" ];
+
bindsTo = lib.optionals (service != "zebra") [ "zebra.service" ];
+
wants = [ "network.target" ];
+
description = if service == "zebra" then "FRR Zebra routing manager"
+
else "FRR ${toUpper service} routing daemon";
+
unitConfig.Documentation = if service == "zebra" then "man:zebra(8)"
+
else "man:${daemon}(8) man:zebra(8)";
+
reloadIfChanged = true;
+
PIDFile = "frr/${daemon}.pid";
+
ExecStart = "${pkgs.frr}/libexec/frr/${daemon} -f /etc/frr/${service}.conf"
+
+ optionalString (scfg.vtyListenAddress != "") " -A ${scfg.vtyListenAddress}"
+
+ optionalString (scfg.vtyListenPort != null) " -P ${toString scfg.vtyListenPort}";
+
ExecReload = "${pkgs.python3.interpreter} ${pkgs.frr}/libexec/frr/frr-reload.py --reload --daemon ${daemonName service} --bindir ${pkgs.frr}/bin --rundir /run/frr /etc/frr/${service}.conf";
+
Restart = "on-abnormal";
+
listToAttrs (map frrService (filter isEnabled allServices));
+
meta.maintainers = with lib.maintainers; [ woffs ];