nixpkgs/pkgs/servers/dns/knot-resolver/default.nix
Vladimír Čunát 9efdd2e434
knot-resolver: 3.2.1 -> 4.0.0
https://lists.nic.cz/pipermail/knot-resolver-users/2019/000136.html

Similar commit worked fine for me, including the nixos service.
I'd like to still improve the service to support easy passing of sockets
to http module.
2019-07-10 17:40:04 +02:00

114 lines
3.6 KiB
Nix

{ stdenv, fetchurl
# native deps.
, runCommand, pkgconfig, meson, ninja, makeWrapper
# build+runtime deps.
, knot-dns, luajitPackages, libuv, gnutls, lmdb, systemd, dns-root-data
# 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;
inherit (stdenv.lib) optional optionals concatStringsSep;
lua = luajitPackages;
# FIXME: remove these usages once resolving
# https://github.com/NixOS/nixpkgs/pull/63108#issuecomment-508670438
exportLuaPathsFor = luaPkgs: ''
export LUA_PATH='${ concatStringsSep ";" (map lua.getLuaPath luaPkgs)}'
export LUA_CPATH='${concatStringsSep ";" (map lua.getLuaCPath luaPkgs)}'
'';
unwrapped = stdenv.mkDerivation rec {
name = "knot-resolver-${version}";
version = "4.0.0";
src = fetchurl {
url = "https://secure.nic.cz/files/knot-resolver/${name}.tar.xz";
sha256 = "37161d931e64535ce38c33b9635f06a43cd1541945bf2c79a55e37f230de1631";
};
outputs = [ "out" "dev" ];
preConfigure = ''
patchShebangs scripts/
''
+ stdenv.lib.optionalString doInstallCheck (exportLuaPathsFor [ lua.cqueues lua.basexx ]);
nativeBuildInputs = [ pkgconfig meson ninja ];
# http://knot-resolver.readthedocs.io/en/latest/build.html#requirements
buildInputs = [ knot-dns lua.lua libuv gnutls lmdb ]
++ optional stdenv.isLinux systemd # passing sockets, sd_notify
## optional dependencies; TODO: libedit, dnstap
;
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
]
++ optionals doInstallCheck [
"-Dunit_tests=enabled"
"-Dconfig_tests=enabled"
#"-Dextra_tests=enabled" # not suitable as in-distro tests; many deps, too.
];
postInstall = ''
rm "$out"/lib/libkres.a
'';
doInstallCheck = stdenv.hostPlatform == stdenv.buildPlatform;
installCheckInputs = [ cmocka which cacert ];
installCheckPhase = ''
meson test --print-errorlogs
'';
meta = with stdenv.lib; {
description = "Caching validating DNS resolver, from .cz domain registry";
homepage = https://knot-resolver.cz;
license = licenses.gpl3Plus;
# Platforms using negative pointers for stack won't work ATM due to LuaJIT impl.
platforms = filter (p: p != "aarch64-linux") platforms.unix;
maintainers = [ maintainers.vcunat /* upstream developer */ ];
};
};
# FIXME: revert this back after resolving
# https://github.com/NixOS/nixpkgs/pull/63108#issuecomment-508670438
wrapped-full =
with stdenv.lib;
with luajitPackages;
let
luaPkgs = [
luasec luasocket # trust anchor bootstrap, prefill module
luafilesystem # prefill module
http # for http module; brings lots of deps; some are useful elsewhere
cqueues fifo lpeg lpeg_patterns luaossl compat53 basexx binaryheap
];
in runCommand unwrapped.name
{
nativeBuildInputs = [ makeWrapper ];
preferLocalBuild = true;
allowSubstitutes = false;
}
(exportLuaPathsFor luaPkgs
+ ''
mkdir -p "$out"/{bin,share}
makeWrapper '${unwrapped}/bin/kresd' "$out"/bin/kresd \
--set LUA_PATH "$LUA_PATH" \
--set LUA_CPATH "$LUA_CPATH"
ln -sr '${unwrapped}/share/man' "$out"/share/
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