]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
distro/nix: add
authorVladimír Čunát <vladimir.cunat@nic.cz>
Mon, 21 Jun 2021 15:59:28 +0000 (17:59 +0200)
committerVladimír Čunát <vladimir.cunat@nic.cz>
Tue, 27 Jul 2021 17:59:40 +0000 (19:59 +0200)
The generated default.nix exactly corresponds to what's on
https://github.com/NixOS/nixpkgs/blob/master/pkgs/servers/dns/knot-dns/default.nix
(except for tiny differences directly due to 3.0.8 vs. 3.1.0)

distro/pkg/nix/default.nix [new file with mode: 0644]
distro/pkg/nix/dont-create-run-time-dirs.patch [new file with mode: 0644]
distro/pkg/nix/runtime-deps.patch [new file with mode: 0644]
distro/pkg/nix/top-level.nix [new file with mode: 0644]

diff --git a/distro/pkg/nix/default.nix b/distro/pkg/nix/default.nix
new file mode 100644 (file)
index 0000000..2b3bdea
--- /dev/null
@@ -0,0 +1,70 @@
+{ lib, stdenv, fetchurl, pkg-config, gnutls, liburcu, lmdb, libcap_ng, libidn2, libunistring
+, systemd, nettle, libedit, zlib, libiconv, libintl, libmaxminddb, libbpf, nghttp2, libmnl
+, autoreconfHook, nixosTests
+}:
+
+let inherit (lib) optional optionals; in
+
+stdenv.mkDerivation rec {
+  pname = "knot-dns";
+  version = "{{ version }}";
+
+  src = fetchurl {
+    url = "https://secure.nic.cz/files/knot-dns/knot-${version}.tar.xz";
+    sha256 = "{{ src_hash }}";
+  };
+
+  outputs = [ "bin" "out" "dev" ];
+
+  configureFlags = [
+    "--with-configdir=/etc/knot"
+    "--with-rundir=/run/knot"
+    "--with-storage=/var/lib/knot"
+  ];
+
+  patches = [
+    # Don't try to create directories like /var/lib/knot at build time.
+    # They are later created from NixOS itself.
+    ./dont-create-run-time-dirs.patch
+    ./runtime-deps.patch
+  ];
+
+  nativeBuildInputs = [ pkg-config autoreconfHook ];
+  buildInputs = [
+    gnutls liburcu libidn2 libunistring
+    nettle libedit
+    libiconv lmdb libintl
+    nghttp2 # DoH support in kdig
+    libmaxminddb # optional for geoip module (it's tiny)
+    libmnl # required for knot >= 3.1
+    # without sphinx &al. for developer documentation
+    # TODO: add dnstap support?
+  ]
+    ++ optionals stdenv.isLinux [
+      libcap_ng systemd
+      libbpf # XDP support
+    ]
+    ++ optional stdenv.isDarwin zlib; # perhaps due to gnutls
+
+  enableParallelBuilding = true;
+
+  CFLAGS = [ "-O2" "-DNDEBUG" ];
+
+  doCheck = true;
+  checkFlags = "V=1"; # verbose output in case some test fails
+  doInstallCheck = true;
+
+  postInstall = ''
+    rm -r "$out"/lib/*.la
+  '';
+
+  passthru.tests = { inherit (nixosTests) knot; };
+
+  meta = with lib; {
+    description = "Authoritative-only DNS server from .cz domain registry";
+    homepage = "https://knot-dns.cz";
+    license = licenses.gpl3Plus;
+    platforms = platforms.unix;
+    maintainers = [ maintainers.vcunat ];
+  };
+}
diff --git a/distro/pkg/nix/dont-create-run-time-dirs.patch b/distro/pkg/nix/dont-create-run-time-dirs.patch
new file mode 100644 (file)
index 0000000..9fe165e
--- /dev/null
@@ -0,0 +1,32 @@
+diff --git a/samples/Makefile.am b/samples/Makefile.am
+index c253c91..107401d 100644
+--- a/samples/Makefile.am
++++ b/samples/Makefile.am
+@@ -19,11 +19,6 @@ EXTRA_DIST = knot.sample.conf.in example.com.zone
+ if HAVE_DAEMON
+-install-data-local: knot.sample.conf
+-      if [ \! -f $(DESTDIR)/$(config_dir)/knot.sample.conf ]; then \
+-        $(INSTALL) -d $(DESTDIR)/$(config_dir); \
+-        $(INSTALL_DATA) knot.sample.conf $(srcdir)/example.com.zone $(DESTDIR)/$(config_dir); \
+-      fi
+ uninstall-local:
+       -rm -rf $(DESTDIR)/$(config_dir)/knot.sample.conf \
+               $(DESTDIR)/$(config_dir)/example.com.zone
+diff --git a/src/utils/Makefile.inc b/src/utils/Makefile.inc
+index e6765d9..d859d23 100644
+--- a/src/utils/Makefile.inc
++++ b/src/utils/Makefile.inc
+@@ -79,11 +79,6 @@ endif HAVE_DNSTAP
+ endif HAVE_UTILS
+ if HAVE_DAEMON
+-# Create storage and run-time directories
+-install-data-hook:
+-      $(INSTALL) -d $(DESTDIR)/@config_dir@
+-      $(INSTALL) -d $(DESTDIR)/@run_dir@
+-      $(INSTALL) -d $(DESTDIR)/@storage_dir@
+ sbin_PROGRAMS = knotc knotd
diff --git a/distro/pkg/nix/runtime-deps.patch b/distro/pkg/nix/runtime-deps.patch
new file mode 100644 (file)
index 0000000..19fc9cd
--- /dev/null
@@ -0,0 +1,14 @@
+Remove unnecessary runtime dependencies.
+
+`knotc status configure` shows summary from the configure script,
+but that contains also references like include paths.
+Filter these at least in a crude way (whole lines).
+--- a/configure.ac
++++ b/configure.ac
+@@ -766,5 +766,5 @@ result_msg_base="  Knot DNS $VERSION
+-result_msg_esc=$(echo -n "$result_msg_base" | sed '$!s/$/\\n/' | tr -d '\n')
++result_msg_esc=$(echo -n "$result_msg_base" | grep -Fv "$NIX_STORE" | sed '$!s/$/\\n/' | tr -d '\n')
+ AC_DEFINE_UNQUOTED([CONFIGURE_SUMMARY],["$result_msg_esc"],[Configure summary])
diff --git a/distro/pkg/nix/top-level.nix b/distro/pkg/nix/top-level.nix
new file mode 100644 (file)
index 0000000..303923c
--- /dev/null
@@ -0,0 +1,8 @@
+
+with import <nixpkgs> {};
+
+(callPackage ./. {
+}).overrideAttrs (attrs: {
+  src = ./knot-{{ version }}.tar.xz;
+})
+