Merge pull request #89781 from mdlayher/mdl-corerad-settings
This commit is contained in:
commit
00e448172f
@ -4,14 +4,48 @@ with lib;
|
|||||||
|
|
||||||
let
|
let
|
||||||
cfg = config.services.corerad;
|
cfg = config.services.corerad;
|
||||||
|
|
||||||
|
writeTOML = name: x:
|
||||||
|
pkgs.runCommandNoCCLocal name { } ''
|
||||||
|
echo '${builtins.toJSON x}' | ${pkgs.go-toml}/bin/jsontoml > $out
|
||||||
|
'';
|
||||||
|
|
||||||
in {
|
in {
|
||||||
meta = {
|
meta.maintainers = with maintainers; [ mdlayher ];
|
||||||
maintainers = with maintainers; [ mdlayher ];
|
|
||||||
};
|
|
||||||
|
|
||||||
options.services.corerad = {
|
options.services.corerad = {
|
||||||
enable = mkEnableOption "CoreRAD IPv6 NDP RA daemon";
|
enable = mkEnableOption "CoreRAD IPv6 NDP RA daemon";
|
||||||
|
|
||||||
|
settings = mkOption {
|
||||||
|
type = types.uniq types.attrs;
|
||||||
|
example = literalExample ''
|
||||||
|
{
|
||||||
|
interfaces = [
|
||||||
|
# eth0 is an upstream interface monitoring for IPv6 router advertisements.
|
||||||
|
{
|
||||||
|
name = "eth0";
|
||||||
|
monitor = true;
|
||||||
|
}
|
||||||
|
# eth1 is a downstream interface advertising IPv6 prefixes for SLAAC.
|
||||||
|
{
|
||||||
|
name = "eth1";
|
||||||
|
advertise = true;
|
||||||
|
prefix = [{ prefix = "::/64"; }];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
# Optionally enable Prometheus metrics.
|
||||||
|
debug = {
|
||||||
|
address = "localhost:9430";
|
||||||
|
prometheus = true;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
description = ''
|
||||||
|
Configuration for CoreRAD, see <link xlink:href="https://github.com/mdlayher/corerad/blob/master/internal/config/default.toml"/>
|
||||||
|
for supported values. Ignored if configFile is set.
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
configFile = mkOption {
|
configFile = mkOption {
|
||||||
type = types.path;
|
type = types.path;
|
||||||
example = literalExample "\"\${pkgs.corerad}/etc/corerad/corerad.toml\"";
|
example = literalExample "\"\${pkgs.corerad}/etc/corerad/corerad.toml\"";
|
||||||
@ -27,6 +61,9 @@ in {
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
|
# Prefer the config file over settings if both are set.
|
||||||
|
services.corerad.configFile = mkDefault (writeTOML "corerad.toml" cfg.settings);
|
||||||
|
|
||||||
systemd.services.corerad = {
|
systemd.services.corerad = {
|
||||||
description = "CoreRAD IPv6 NDP RA daemon";
|
description = "CoreRAD IPv6 NDP RA daemon";
|
||||||
after = [ "network.target" ];
|
after = [ "network.target" ];
|
||||||
|
@ -3,7 +3,7 @@ import ./make-test-python.nix (
|
|||||||
nodes = {
|
nodes = {
|
||||||
router = {config, pkgs, ...}: {
|
router = {config, pkgs, ...}: {
|
||||||
config = {
|
config = {
|
||||||
# This machines simulates a router with IPv6 forwarding and a static IPv6 address.
|
# This machine simulates a router with IPv6 forwarding and a static IPv6 address.
|
||||||
boot.kernel.sysctl = {
|
boot.kernel.sysctl = {
|
||||||
"net.ipv6.conf.all.forwarding" = true;
|
"net.ipv6.conf.all.forwarding" = true;
|
||||||
};
|
};
|
||||||
@ -14,13 +14,25 @@ import ./make-test-python.nix (
|
|||||||
enable = true;
|
enable = true;
|
||||||
# Serve router advertisements to the client machine with prefix information matching
|
# Serve router advertisements to the client machine with prefix information matching
|
||||||
# any IPv6 /64 prefixes configured on this interface.
|
# any IPv6 /64 prefixes configured on this interface.
|
||||||
configFile = pkgs.writeText "corerad.toml" ''
|
#
|
||||||
[[interfaces]]
|
# This configuration is identical to the example in the CoreRAD NixOS module.
|
||||||
name = "eth1"
|
settings = {
|
||||||
advertise = true
|
interfaces = [
|
||||||
[[interfaces.prefix]]
|
{
|
||||||
prefix = "::/64"
|
name = "eth0";
|
||||||
'';
|
monitor = true;
|
||||||
|
}
|
||||||
|
{
|
||||||
|
name = "eth1";
|
||||||
|
advertise = true;
|
||||||
|
prefix = [{ prefix = "::/64"; }];
|
||||||
|
}
|
||||||
|
];
|
||||||
|
debug = {
|
||||||
|
address = "localhost:9430";
|
||||||
|
prometheus = true;
|
||||||
|
};
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@ -66,5 +78,12 @@ import ./make-test-python.nix (
|
|||||||
assert (
|
assert (
|
||||||
"/64 scope global temporary" in addrs
|
"/64 scope global temporary" in addrs
|
||||||
), "SLAAC temporary address was not configured on client after router advertisement"
|
), "SLAAC temporary address was not configured on client after router advertisement"
|
||||||
|
|
||||||
|
with subtest("Verify HTTP debug server is configured"):
|
||||||
|
out = router.succeed("curl localhost:9430/metrics")
|
||||||
|
|
||||||
|
assert (
|
||||||
|
"corerad_build_info" in out
|
||||||
|
), "Build info metric was not found in Prometheus output"
|
||||||
'';
|
'';
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user