2021-05-20 23:08:51 +00:00
|
|
|
{ lib, stdenv, fetchurl
|
2020-04-24 23:36:52 +00:00
|
|
|
# native deps.
|
2021-02-05 17:12:51 +00:00
|
|
|
, runCommand, pkg-config, meson, ninja, makeWrapper
|
2020-04-24 23:36:52 +00:00
|
|
|
# build+runtime deps.
|
2020-11-19 00:13:47 +00:00
|
|
|
, knot-dns, luajitPackages, libuv, gnutls, lmdb
|
|
|
|
, systemd, libcap_ng, dns-root-data, nghttp2 # optionals, in principle
|
2020-04-24 23:36:52 +00:00
|
|
|
# test-only deps.
|
|
|
|
, cmocka, which, cacert
|
|
|
|
, extraFeatures ? false /* catch-all if defaults aren't enough */
|
|
|
|
}:
|
|
|
|
let # un-indented, over the whole file
|
|
|
|
|
|
|
|
result = if extraFeatures then wrapped-full else unwrapped;
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
inherit (lib) optional optionals optionalString;
|
2020-04-24 23:36:52 +00:00
|
|
|
lua = luajitPackages;
|
|
|
|
|
|
|
|
unwrapped = stdenv.mkDerivation rec {
|
|
|
|
pname = "knot-resolver";
|
2021-08-22 07:53:02 +00:00
|
|
|
version = "5.4.1";
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
src = fetchurl {
|
|
|
|
url = "https://secure.nic.cz/files/knot-resolver/${pname}-${version}.tar.xz";
|
2021-08-22 07:53:02 +00:00
|
|
|
sha256 = "fb8b962dd9ef744e2551c4f052454bc2a30e39c1f662f4f3522e8f221d8e3d66";
|
2020-04-24 23:36:52 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
outputs = [ "out" "dev" ];
|
|
|
|
|
|
|
|
# Path fixups for the NixOS service.
|
|
|
|
postPatch = ''
|
|
|
|
patch meson.build <<EOF
|
|
|
|
@@ -50,2 +50,2 @@
|
2020-12-09 12:39:15 +00:00
|
|
|
-systemd_work_dir = prefix / get_option('localstatedir') / 'lib' / 'knot-resolver'
|
|
|
|
-systemd_cache_dir = prefix / get_option('localstatedir') / 'cache' / 'knot-resolver'
|
2020-04-24 23:36:52 +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
|
2020-11-19 00:13:47 +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-08-05 21:33:18 +00:00
|
|
|
sed -E '/^[[:blank:]]*test_(dstaddr|headers),?$/d' -i \
|
2021-03-09 03:18:52 +00:00
|
|
|
tests/config/doh2.test.lua modules/http/http_doh.test.lua
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
preConfigure = ''
|
|
|
|
patchShebangs scripts/
|
|
|
|
'';
|
|
|
|
|
2021-02-05 17:12:51 +00:00
|
|
|
nativeBuildInputs = [ pkg-config meson ninja ];
|
2020-04-24 23:36:52 +00:00
|
|
|
|
|
|
|
# http://knot-resolver.readthedocs.io/en/latest/build.html#requirements
|
|
|
|
buildInputs = [ knot-dns lua.lua libuv gnutls lmdb ]
|
2020-11-19 00:13:47 +00:00
|
|
|
++ optionals stdenv.isLinux [ systemd libcap_ng ]
|
|
|
|
++ [ nghttp2 ]
|
|
|
|
## optional dependencies; TODO: dnstap
|
2020-04-24 23:36:52 +00: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/
|
|
|
|
"--default-library=static" # not used by anyone
|
|
|
|
]
|
|
|
|
++ optional doInstallCheck "-Dunit_tests=enabled"
|
|
|
|
++ optional (doInstallCheck && !stdenv.isDarwin) "-Dconfig_tests=enabled"
|
|
|
|
++ optional stdenv.isLinux "-Dsystemd_files=enabled" # used by NixOS service
|
|
|
|
#"-Dextra_tests=enabled" # not suitable as in-distro tests; many deps, too.
|
|
|
|
;
|
|
|
|
|
|
|
|
postInstall = ''
|
|
|
|
rm "$out"/lib/libkres.a
|
|
|
|
rm "$out"/lib/knot-resolver/upgrade-4-to-5.lua # not meaningful on NixOS
|
2020-11-19 00:13:47 +00:00
|
|
|
'' + optionalString stdenv.targetPlatform.isLinux ''
|
2020-11-12 09:05:59 +00:00
|
|
|
rm -r "$out"/lib/sysusers.d/ # ATM more likely to harm than help
|
2020-04-24 23:36:52 +00:00
|
|
|
'';
|
|
|
|
|
2021-06-28 23:13:55 +00:00
|
|
|
doInstallCheck = with stdenv; hostPlatform == buildPlatform
|
|
|
|
&& !(isDarwin && isAarch64); # avoid luarocks, as it's broken ATM on the platform
|
2020-11-19 00:13:47 +00:00
|
|
|
installCheckInputs = [ cmocka which cacert lua.cqueues lua.basexx lua.http ];
|
2020-04-24 23:36:52 +00:00
|
|
|
installCheckPhase = ''
|
|
|
|
meson test --print-errorlogs
|
|
|
|
'';
|
|
|
|
|
2021-01-15 22:18:51 +00:00
|
|
|
meta = with lib; {
|
2020-04-24 23:36:52 +00:00
|
|
|
description = "Caching validating DNS resolver, from .cz domain registry";
|
|
|
|
homepage = "https://knot-resolver.cz";
|
|
|
|
license = licenses.gpl3Plus;
|
|
|
|
platforms = platforms.unix;
|
|
|
|
maintainers = [ maintainers.vcunat /* upstream developer */ ];
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
wrapped-full = runCommand unwrapped.name
|
|
|
|
{
|
|
|
|
nativeBuildInputs = [ makeWrapper ];
|
|
|
|
buildInputs = with luajitPackages; [
|
|
|
|
# For http module, prefill module, trust anchor bootstrap.
|
|
|
|
# It brings lots of deps; some are useful elsewhere (e.g. cqueues).
|
|
|
|
http
|
|
|
|
# psl isn't in nixpkgs yet, but policy.slice_randomize_psl() seems not important.
|
|
|
|
];
|
|
|
|
preferLocalBuild = true;
|
|
|
|
allowSubstitutes = false;
|
|
|
|
}
|
|
|
|
''
|
|
|
|
mkdir -p "$out"/bin
|
|
|
|
makeWrapper '${unwrapped}/bin/kresd' "$out"/bin/kresd \
|
|
|
|
--set LUA_PATH "$LUA_PATH" \
|
|
|
|
--set LUA_CPATH "$LUA_CPATH"
|
|
|
|
|
|
|
|
ln -sr '${unwrapped}/share' "$out"/
|
|
|
|
ln -sr '${unwrapped}/lib' "$out"/ # useful in NixOS service
|
|
|
|
ln -sr "$out"/{bin,sbin}
|
|
|
|
|
|
|
|
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
|
|
|
|
'';
|
|
|
|
|
|
|
|
in result
|