2022-01-05 14:28:59 +00:00
|
|
|
{ lib, stdenv, fetchurl
|
2019-05-19 13:05:54 +01:00
|
|
|
# native deps.
|
2021-01-19 06:50:56 +00:00
|
|
|
, runCommand, pkg-config, meson, ninja, makeWrapper
|
2019-05-19 13:05:54 +01:00
|
|
|
# build+runtime deps.
|
2020-11-18 07:38:23 +00:00
|
|
|
, knot-dns, luajitPackages, libuv, gnutls, lmdb
|
2023-01-26 17:19:22 +00:00
|
|
|
, jemalloc, systemd, libcap_ng, dns-root-data, nghttp2 # optionals, in principle
|
2024-01-25 15:06:08 +00:00
|
|
|
, fstrm, protobufc # more optionals
|
2019-05-19 13:05:54 +01:00
|
|
|
# test-only deps.
|
|
|
|
, cmocka, which, cacert
|
2017-09-22 10:27:59 +01:00
|
|
|
, extraFeatures ? false /* catch-all if defaults aren't enough */
|
2017-01-25 14:20:18 +00:00
|
|
|
}:
|
2018-02-01 16:15:28 +00:00
|
|
|
let # un-indented, over the whole file
|
2017-01-25 14:20:18 +00:00
|
|
|
|
2018-02-01 16:15:28 +00:00
|
|
|
result = if extraFeatures then wrapped-full else unwrapped;
|
|
|
|
|
2021-01-15 07:07:56 +00:00
|
|
|
inherit (lib) optional optionals optionalString;
|
2019-05-19 13:05:54 +01:00
|
|
|
lua = luajitPackages;
|
|
|
|
|
2018-02-01 16:15:28 +00:00
|
|
|
unwrapped = stdenv.mkDerivation rec {
|
2019-08-15 13:41:18 +01:00
|
|
|
pname = "knot-resolver";
|
2024-07-23 19:30:11 +01:00
|
|
|
version = "5.7.4";
|
2017-01-25 14:20:18 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
2019-08-15 13:41:18 +01:00
|
|
|
url = "https://secure.nic.cz/files/knot-resolver/${pname}-${version}.tar.xz";
|
2024-07-23 19:30:11 +01:00
|
|
|
hash = "sha256-a22m7PBoKAQa+tRN+iJ3gfCuNK0YOmZwCFCTVdGL2cg=";
|
2017-01-25 14:20:18 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
2020-02-05 18:27:16 +00:00
|
|
|
# Path fixups for the NixOS service.
|
|
|
|
postPatch = ''
|
|
|
|
patch meson.build <<EOF
|
|
|
|
@@ -50,2 +50,2 @@
|
2020-12-09 10:07:28 +00:00
|
|
|
-systemd_work_dir = prefix / get_option('localstatedir') / 'lib' / 'knot-resolver'
|
|
|
|
-systemd_cache_dir = prefix / get_option('localstatedir') / 'cache' / 'knot-resolver'
|
2020-02-05 18:27:16 +00:00
|
|
|
+systemd_work_dir = '/var/lib/knot-resolver'
|
|
|
|
+systemd_cache_dir = '/var/cache/knot-resolver'
|
|
|
|
EOF
|
|
|
|
|
|
|
|
# ExecStart can't be overwritten in overrides.
|
|
|
|
# We need that to use wrapped executable and correct config file.
|
|
|
|
sed '/^ExecStart=/d' -i systemd/kresd@.service.in
|
2022-08-24 17:14:26 +01:00
|
|
|
|
|
|
|
# On x86_64-darwin loading by soname fails to find the libs, surprisingly.
|
|
|
|
# Even though they should already be loaded and they're in RPATH, too.
|
|
|
|
for f in daemon/lua/{kres,zonefile}.lua; do
|
|
|
|
substituteInPlace "$f" \
|
|
|
|
--replace "ffi.load(" "ffi.load('${lib.getLib knot-dns}/lib/' .. "
|
|
|
|
done
|
2020-11-12 17:57:50 +00:00
|
|
|
''
|
|
|
|
# some tests have issues with network sandboxing, apparently
|
|
|
|
+ optionalString doInstallCheck ''
|
|
|
|
echo 'os.exit(77)' > daemon/lua/trust_anchors.test/bootstrap.test.lua
|
2021-07-29 15:39:35 +01:00
|
|
|
sed -E '/^[[:blank:]]*test_(dstaddr|headers),?$/d' -i \
|
2021-02-25 13:47:35 +00:00
|
|
|
tests/config/doh2.test.lua modules/http/http_doh.test.lua
|
2020-02-05 18:27:16 +00:00
|
|
|
'';
|
|
|
|
|
2019-05-19 13:05:54 +01:00
|
|
|
preConfigure = ''
|
|
|
|
patchShebangs scripts/
|
2020-02-05 18:27:16 +00:00
|
|
|
'';
|
2017-01-25 14:20:18 +00:00
|
|
|
|
2021-01-19 06:50:56 +00:00
|
|
|
nativeBuildInputs = [ pkg-config meson ninja ];
|
2017-01-25 21:41:07 +00:00
|
|
|
|
2017-09-22 10:27:59 +01:00
|
|
|
# http://knot-resolver.readthedocs.io/en/latest/build.html#requirements
|
2019-05-19 13:05:54 +01:00
|
|
|
buildInputs = [ knot-dns lua.lua libuv gnutls lmdb ]
|
2024-01-25 15:06:08 +00:00
|
|
|
## the rest are optional dependencies
|
2022-04-29 10:12:29 +01:00
|
|
|
++ optionals stdenv.hostPlatform.isLinux [ /*lib*/systemd libcap_ng ]
|
2023-01-26 17:19:22 +00:00
|
|
|
++ [ jemalloc nghttp2 ]
|
2024-01-25 15:06:08 +00:00
|
|
|
++ [ fstrm protobufc ] # dnstap support
|
2018-02-01 16:15:28 +00:00
|
|
|
;
|
2017-01-25 14:20:18 +00:00
|
|
|
|
2019-05-19 13:05:54 +01:00
|
|
|
mesonFlags = [
|
|
|
|
"-Dkeyfile_default=${dns-root-data}/root.ds"
|
|
|
|
"-Droot_hints=${dns-root-data}/root.hints"
|
|
|
|
"-Dinstall_kresd_conf=disabled" # not really useful; examples are inside share/doc/
|
2023-01-26 17:19:22 +00:00
|
|
|
"-Dmalloc=jemalloc"
|
2019-05-19 13:05:54 +01:00
|
|
|
"--default-library=static" # not used by anyone
|
|
|
|
]
|
2019-07-10 17:26:26 +01:00
|
|
|
++ optional doInstallCheck "-Dunit_tests=enabled"
|
2022-08-24 17:15:12 +01:00
|
|
|
++ optional doInstallCheck "-Dconfig_tests=enabled"
|
2020-02-05 18:27:16 +00:00
|
|
|
++ optional stdenv.hostPlatform.isLinux "-Dsystemd_files=enabled" # used by NixOS service
|
2019-05-19 13:05:54 +01:00
|
|
|
#"-Dextra_tests=enabled" # not suitable as in-distro tests; many deps, too.
|
2019-07-10 17:26:26 +01:00
|
|
|
;
|
2017-01-25 14:20:18 +00:00
|
|
|
|
2019-05-19 13:05:54 +01:00
|
|
|
postInstall = ''
|
|
|
|
rm "$out"/lib/libkres.a
|
2020-02-05 18:27:16 +00:00
|
|
|
rm "$out"/lib/knot-resolver/upgrade-4-to-5.lua # not meaningful on NixOS
|
2023-11-13 14:47:08 +00:00
|
|
|
'' + optionalString stdenv.hostPlatform.isLinux ''
|
2020-11-11 14:33:22 +00:00
|
|
|
rm -r "$out"/lib/sysusers.d/ # ATM more likely to harm than help
|
2017-01-25 14:20:18 +00:00
|
|
|
'';
|
|
|
|
|
2022-04-29 10:31:51 +01:00
|
|
|
doInstallCheck = with stdenv; hostPlatform == buildPlatform;
|
2023-01-21 12:00:00 +00:00
|
|
|
nativeInstallCheckInputs = [ cmocka which cacert lua.cqueues lua.basexx lua.http ];
|
2019-05-19 13:05:54 +01:00
|
|
|
installCheckPhase = ''
|
2023-02-03 09:54:27 +00:00
|
|
|
meson test --print-errorlogs --no-suite snowflake
|
2018-02-01 16:15:28 +00:00
|
|
|
'';
|
2017-01-25 14:20:18 +00:00
|
|
|
|
2021-01-11 07:54:33 +00:00
|
|
|
meta = with lib; {
|
2017-01-25 17:41:52 +00:00
|
|
|
description = "Caching validating DNS resolver, from .cz domain registry";
|
2020-04-01 02:11:51 +01:00
|
|
|
homepage = "https://knot-resolver.cz";
|
2017-01-25 14:20:18 +00:00
|
|
|
license = licenses.gpl3Plus;
|
2019-07-10 15:52:57 +01:00
|
|
|
platforms = platforms.unix;
|
2017-01-25 14:20:18 +00:00
|
|
|
maintainers = [ maintainers.vcunat /* upstream developer */ ];
|
2022-09-20 12:08:34 +01:00
|
|
|
mainProgram = "kresd";
|
2017-01-25 14:20:18 +00:00
|
|
|
};
|
2018-02-01 16:15:28 +00:00
|
|
|
};
|
|
|
|
|
2020-02-05 18:27:16 +00:00
|
|
|
wrapped-full = runCommand unwrapped.name
|
2020-01-27 14:14:42 +00:00
|
|
|
{
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
2020-02-05 18:27:16 +00:00
|
|
|
buildInputs = with luajitPackages; [
|
|
|
|
# For http module, prefill module, trust anchor bootstrap.
|
|
|
|
# It brings lots of deps; some are useful elsewhere (e.g. cqueues).
|
|
|
|
http
|
2024-04-18 22:21:27 +01:00
|
|
|
# used by policy.slice_randomize_psl()
|
|
|
|
psl
|
2020-02-05 18:27:16 +00:00
|
|
|
];
|
2018-02-01 16:15:28 +00:00
|
|
|
preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
2022-09-20 12:08:34 +01:00
|
|
|
inherit (unwrapped) meta;
|
2018-02-01 16:15:28 +00:00
|
|
|
}
|
2024-04-04 22:53:08 +01:00
|
|
|
(''
|
2020-02-05 18:27:16 +00:00
|
|
|
mkdir -p "$out"/bin
|
2019-05-01 10:19:49 +01:00
|
|
|
makeWrapper '${unwrapped}/bin/kresd' "$out"/bin/kresd \
|
2019-05-19 13:05:54 +01:00
|
|
|
--set LUA_PATH "$LUA_PATH" \
|
|
|
|
--set LUA_CPATH "$LUA_CPATH"
|
2019-07-05 09:42:08 +01:00
|
|
|
|
2020-02-05 18:27:16 +00:00
|
|
|
ln -sr '${unwrapped}/share' "$out"/
|
|
|
|
ln -sr '${unwrapped}/lib' "$out"/ # useful in NixOS service
|
2019-05-01 10:19:49 +01:00
|
|
|
ln -sr "$out"/{bin,sbin}
|
2023-06-21 17:36:55 +01:00
|
|
|
'' + lib.optionalString unwrapped.doInstallCheck ''
|
2019-07-05 10:00:51 +01:00
|
|
|
echo "Checking that 'http' module loads, i.e. lua search paths work:"
|
|
|
|
echo "modules.load('http')" > test-http.lua
|
|
|
|
echo -e 'quit()' | env -i "$out"/bin/kresd -a 127.0.0.1#53535 -c test-http.lua
|
2023-06-21 17:36:55 +01:00
|
|
|
'');
|
2018-02-01 16:15:28 +00:00
|
|
|
|
|
|
|
in result
|