Martin Weinelt 2025-07-26 04:16:11 +02:00
parent 088e4e0aa8
commit 66e035f411
No known key found for this signature in database
GPG Key ID: 87C1E9888F856759
4 changed files with 125 additions and 95 deletions

View File

@ -2,6 +2,7 @@
config,
lib,
pkgs,
utils,
...
}:
let
@ -34,11 +35,11 @@ let
DhcpDdns = cfg.dhcp-ddns.settings;
}
);
package = pkgs.kea;
in
{
options.services.kea = with lib.types; {
package = lib.mkPackageOption pkgs "kea" { };
ctrl-agent = lib.mkOption {
description = ''
Kea Control Agent configuration
@ -60,7 +61,7 @@ in
type = nullOr path;
default = null;
description = ''
Kea Control Agent configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
Kea Control Agent configuration as a path, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/agent.html>.
Takes preference over [settings](#opt-services.kea.ctrl-agent.settings).
Most users should prefer using [settings](#opt-services.kea.ctrl-agent.settings) instead.
@ -71,7 +72,7 @@ in
type = format.type;
default = null;
description = ''
Kea Control Agent configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html>.
Kea Control Agent configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/agent.html>.
'';
};
};
@ -99,7 +100,7 @@ in
type = nullOr path;
default = null;
description = ''
Kea DHCP4 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
Kea DHCP4 configuration as a path, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp4-srv.html>.
Takes preference over [settings](#opt-services.kea.dhcp4.settings).
Most users should prefer using [settings](#opt-services.kea.dhcp4.settings) instead.
@ -136,7 +137,7 @@ in
];
};
description = ''
Kea DHCP4 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html>.
Kea DHCP4 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp4-srv.html>.
'';
};
};
@ -164,7 +165,7 @@ in
type = nullOr path;
default = null;
description = ''
Kea DHCP6 configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
Kea DHCP6 configuration as a path, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp6-srv.html>.
Takes preference over [settings](#opt-services.kea.dhcp6.settings).
Most users should prefer using [settings](#opt-services.kea.dhcp6.settings) instead.
@ -202,7 +203,7 @@ in
];
};
description = ''
Kea DHCP6 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html>.
Kea DHCP6 configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp6-srv.html>.
'';
};
};
@ -230,7 +231,7 @@ in
type = nullOr path;
default = null;
description = ''
Kea DHCP-DDNS configuration as a path, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
Kea DHCP-DDNS configuration as a path, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/ddns.html>.
Takes preference over [settings](#opt-services.kea.dhcp-ddns.settings).
Most users should prefer using [settings](#opt-services.kea.dhcp-ddns.settings) instead.
@ -255,7 +256,7 @@ in
};
};
description = ''
Kea DHCP-DDNS configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html>.
Kea DHCP-DDNS configuration as an attribute set, see <https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/ddns.html>.
'';
};
};
@ -266,9 +267,10 @@ in
config =
let
commonEnvironment = {
KEA_CONTROL_SOCKET_DIR = "/run/kea";
KEA_LOCKFILE_DIR = "/run/kea";
KEA_PIDFILE_DIR = "/run/kea";
# Allow hook scripts only when they originate from the system configuration
KEA_HOOK_SCRIPTS_PATH = lib.mkDefault "/nix/store";
# Allow hooks to originate from the configured package
KEA_HOOKS_PATH = lib.mkDefault "${cfg.package}/lib/kea/hooks";
};
commonServiceConfig = {
@ -291,7 +293,7 @@ in
lib.mkIf (cfg.ctrl-agent.enable || cfg.dhcp4.enable || cfg.dhcp6.enable || cfg.dhcp-ddns.enable) (
lib.mkMerge [
{
environment.systemPackages = [ package ];
environment.systemPackages = [ cfg.package ];
users.users.kea = {
isSystemUser = true;
@ -314,7 +316,7 @@ in
description = "Kea Control Agent";
documentation = [
"man:kea-ctrl-agent(8)"
"https://kea.readthedocs.io/en/kea-${package.version}/arm/agent.html"
"https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/agent.html"
];
wants = [
@ -337,7 +339,14 @@ in
];
serviceConfig = {
ExecStart = "${package}/bin/kea-ctrl-agent -c /etc/kea/ctrl-agent.conf ${lib.escapeShellArgs cfg.ctrl-agent.extraArgs}";
ExecStart = utils.escapeSystemdExecArgs (
[
(lib.getExe' cfg.package "kea-ctrl-agent")
"-c"
"/etc/kea/ctrl-agent.conf"
]
++ cfg.ctrl-agent.extraArgs
);
KillMode = "process";
Restart = "on-failure";
}
@ -359,7 +368,7 @@ in
description = "Kea DHCP4 Server";
documentation = [
"man:kea-dhcp4(8)"
"https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp4-srv.html"
"https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp4-srv.html"
];
after = [
@ -380,7 +389,14 @@ in
];
serviceConfig = {
ExecStart = "${package}/bin/kea-dhcp4 -c /etc/kea/dhcp4-server.conf ${lib.escapeShellArgs cfg.dhcp4.extraArgs}";
ExecStart = utils.escapeSystemdExecArgs (
[
(lib.getExe' cfg.package "kea-dhcp4")
"-c"
"etc/kea/dhcp4-server.conf"
]
++ cfg.dhcp4.extraArgs
);
# Kea does not request capabilities by itself
AmbientCapabilities = [
"CAP_NET_BIND_SERVICE"
@ -409,7 +425,7 @@ in
description = "Kea DHCP6 Server";
documentation = [
"man:kea-dhcp6(8)"
"https://kea.readthedocs.io/en/kea-${package.version}/arm/dhcp6-srv.html"
"https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/dhcp6-srv.html"
];
after = [
@ -430,7 +446,14 @@ in
];
serviceConfig = {
ExecStart = "${package}/bin/kea-dhcp6 -c /etc/kea/dhcp6-server.conf ${lib.escapeShellArgs cfg.dhcp6.extraArgs}";
ExecStart = utils.escapeSystemdExecArgs (
[
(lib.getExe' cfg.package "kea-dhcp6")
"-c"
"/etc/kea/dhcp6-server.conf"
]
++ cfg.dhcp6.extraArgs
);
# Kea does not request capabilities by itself
AmbientCapabilities = [
"CAP_NET_BIND_SERVICE"
@ -457,7 +480,7 @@ in
description = "Kea DHCP-DDNS Server";
documentation = [
"man:kea-dhcp-ddns(8)"
"https://kea.readthedocs.io/en/kea-${package.version}/arm/ddns.html"
"https://kea.readthedocs.io/en/kea-${cfg.package.version}/arm/ddns.html"
];
wants = [ "network-online.target" ];
@ -476,7 +499,14 @@ in
];
serviceConfig = {
ExecStart = "${package}/bin/kea-dhcp-ddns -c /etc/kea/dhcp-ddns.conf ${lib.escapeShellArgs cfg.dhcp-ddns.extraArgs}";
ExecStart = utils.escapeSystemdExecArgs (
[
(lib.getExe' cfg.package "kea-dhcp-ddns")
"-c"
"/etc/kea/dhcp-ddns.conf"
]
++ cfg.dhcp-ddns.extraArgs
);
AmbientCapabilities = [
"CAP_NET_BIND_SERVICE"
];

View File

@ -0,0 +1,15 @@
diff --git a/meson.build b/meson.build
index 24ab9b5bd7..8f44076cf7 100644
--- a/meson.build
+++ b/meson.build
@@ -1118,10 +1118,6 @@ top_docs = [
]
install_data(top_docs, install_dir: DATADIR / 'doc/kea')
-install_emptydir(LOGDIR)
-install_emptydir(RUNSTATEDIR)
-install_emptydir(SHAREDSTATEDIR)
-
# Meson is annoying with its opinionated alteration of certain paths based on whether prefix is default or not.
# So we revert what it does..
# In case prefix is default, install to hardcoded path.

View File

@ -1,34 +0,0 @@
diff --git a/Makefile.am b/Makefile.am
index a81f4cc..5d61407 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -173,18 +173,6 @@ cppcheck:
docs:
$(MAKE) -C doc/sphinx
-
-# These steps are necessary during installation. chmod is for reinstallation/upgrade.
-install-exec-hook:
- mkdir -m 750 -p "$(DESTDIR)${localstatedir}/lib/${PACKAGE_NAME}"
- chmod 750 "$(DESTDIR)${localstatedir}/lib/${PACKAGE_NAME}"
- mkdir -m 750 -p "$(DESTDIR)${localstatedir}/log/${PACKAGE_NAME}"
- chmod 750 "$(DESTDIR)${localstatedir}/log/${PACKAGE_NAME}"
- mkdir -m 750 -p "$(DESTDIR)${runstatedir}/${PACKAGE_NAME}"
- chmod 750 "$(DESTDIR)${runstatedir}/${PACKAGE_NAME}"
- mkdir -m 750 -p "$(DESTDIR)${sysconfdir}/${PACKAGE_NAME}"
- chmod 750 "$(DESTDIR)${sysconfdir}/${PACKAGE_NAME}"
-
EXTRA_DIST = tools/path_replacer.sh
EXTRA_DIST += tools/mk_cfgrpt.sh
diff --git a/src/lib/dhcpsrv/Makefile.am b/src/lib/dhcpsrv/Makefile.am
index 7e0f3c4..08c53d8 100644
--- a/src/lib/dhcpsrv/Makefile.am
+++ b/src/lib/dhcpsrv/Makefile.am
@@ -420,6 +420,3 @@ libkea_dhcpsrv_parsers_include_HEADERS = \
parsers/shared_networks_list_parser.h \
parsers/simple_parser4.h \
parsers/simple_parser6.h
-
-install-data-local:
- $(mkinstalldirs) $(DESTDIR)$(dhcp_data_dir)

View File

@ -4,87 +4,108 @@
fetchurl,
# build time
autoreconfHook,
bison,
flex,
meson,
ninja,
pkg-config,
python3Packages,
# runtime
withMysql ? stdenv.buildPlatform.system == stdenv.hostPlatform.system,
withPostgres ? stdenv.buildPlatform.system == stdenv.hostPlatform.system,
boost186,
libmysqlclient,
boost,
log4cplus,
openssl,
libpq,
python3,
withKrb5 ? true,
krb5,
withMysql ? stdenv.buildPlatform.system == stdenv.hostPlatform.system,
libmysqlclient,
withPostgresql ? stdenv.buildPlatform.system == stdenv.hostPlatform.system,
libpq,
# tests
nixosTests,
}:
stdenv.mkDerivation rec {
stdenv.mkDerivation (finalAttrs: {
pname = "kea";
version = "2.6.3"; # only even minor versions are stable
version = "3.0.0"; # only even minor versions are stable
src = fetchurl {
url = "https://ftp.isc.org/isc/${pname}/${version}/${pname}-${version}.tar.gz";
hash = "sha256-ACQaWVX/09IVosCYxFJ/nX9LIDGIsnb5o2JQ3T2d1hI=";
url = "https://ftp.isc.org/isc/kea/${finalAttrs.version}/kea-${finalAttrs.version}.tar.xz";
hash = "sha256-v5Y9HhCVHYxXDGBCr8zyfHCdReA4E70mOde7HPxP7nY=";
};
patches = [
./dont-create-var.patch
./dont-create-system-paths.patch
];
postPatch = ''
substituteInPlace ./src/bin/keactrl/Makefile.am --replace-fail '@sysconfdir@' "$out/etc"
# darwin special-casing just causes trouble
substituteInPlace ./m4macros/ax_crypto.m4 --replace-fail 'apple-darwin' 'nope'
patchShebangs \
scripts/grabber.py \
doc/sphinx/*.sh.in
'';
outputs = [
"out"
"doc"
"man"
"python"
];
configureFlags = [
"--enable-perfdhcp"
"--enable-shell"
"--localstatedir=/var"
"--with-openssl=${lib.getDev openssl}"
]
++ lib.optional withPostgres "--with-pgsql=${libpq.pg_config}/bin/pg_config"
++ lib.optional withMysql "--with-mysql=${lib.getDev libmysqlclient}/bin/mysql_config";
mesonFlags = [
(lib.mesonOption "crypto" "openssl")
(lib.mesonEnable "krb5" withKrb5)
(lib.mesonEnable "mysql" withMysql)
(lib.mesonEnable "netconf" false) # missing libyang-cpp, sysinfo, libsysrepo-cpp
(lib.mesonEnable "postgresql" withPostgresql)
(lib.mesonOption "localstatedir" "/var")
(lib.mesonOption "runstatedir" "/run")
];
postConfigure = ''
# Mangle embedded paths to dev-only inputs.
sed -e "s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i config.report
for file in config.report meson-info/intro*.json; do
sed -e "s|$NIX_STORE/[a-z0-9]\{32\}-|$NIX_STORE/eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee-|g" -i "$file"
done
'';
nativeBuildInputs = [
autoreconfHook
bison
flex
meson
ninja
pkg-config
python3
]
++ (with python3Packages; [
sphinxHook
sphinx
sphinx-rtd-theme
]);
sphinxBuilders = [
"html"
"man"
];
sphinxRoot = "doc/sphinx";
buildInputs = [
boost186 # does not build with 1.87 yet, see https://gitlab.isc.org/isc-projects/kea/-/merge_requests/2523
libmysqlclient
boost
log4cplus
openssl
python3
]
++ lib.optionals withMysql [
libmysqlclient
]
++ lib.optionals withPostgresql [
libpq
]
++ lib.optionals withKrb5 [
krb5
];
enableParallelBuilding = true;
postBuild = ''
ninja doc
'';
postFixup = ''
mkdir -p $python/lib
mv $out/lib/python* $python/lib/
'';
passthru.tests = {
kea = nixosTests.kea;
@ -98,9 +119,7 @@ stdenv.mkDerivation rec {
};
meta = {
# error: implicit instantiation of undefined template 'std::char_traits<unsigned char>'
broken = stdenv.hostPlatform.isDarwin;
changelog = "https://downloads.isc.org/isc/kea/${version}/Kea-${version}-ReleaseNotes.txt";
changelog = "https://gitlab.isc.org/isc-projects/kea/-/wikis/Release-Notes/release-notes-${finalAttrs.version}";
homepage = "https://kea.isc.org/";
description = "High-performance, extensible DHCP server by ISC";
longDescription = ''
@ -117,4 +136,4 @@ stdenv.mkDerivation rec {
hexa
];
};
}
})