From 90f3a237eb51d7e3173f1502d468e99ff777d1b9 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 20 Apr 2019 03:02:44 +0200 Subject: [PATCH 1/2] libredirect: add support for openat and dlopen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit gobject-introspection uses glib’s g_module_open function, which in turn relies on dlopen. I also implemented openat, since I initially thought this function was used but turns out dlopen uses the openat signal directly. We might as well keep it, even thought I do not need it at the moment. --- pkgs/build-support/libredirect/libredirect.c | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/pkgs/build-support/libredirect/libredirect.c b/pkgs/build-support/libredirect/libredirect.c index ba1e6c57e12e..dcf3a2016bc2 100644 --- a/pkgs/build-support/libredirect/libredirect.c +++ b/pkgs/build-support/libredirect/libredirect.c @@ -91,6 +91,20 @@ int open64(const char * path, int flags, ...) return open64_real(rewrite(path, buf), flags, mode); } +int openat(int dirfd, const char * path, int flags, ...) +{ + int (*openat_real) (int, const char *, int, mode_t) = dlsym(RTLD_NEXT, "openat"); + mode_t mode = 0; + if (flags & O_CREAT) { + va_list ap; + va_start(ap, flags); + mode = va_arg(ap, mode_t); + va_end(ap); + } + char buf[PATH_MAX]; + return openat_real(dirfd, rewrite(path, buf), flags, mode); +} + FILE * fopen(const char * path, const char * mode) { FILE * (*fopen_real) (const char *, const char *) = dlsym(RTLD_NEXT, "fopen"); @@ -152,3 +166,10 @@ int execv(const char *path, char *const argv[]) char buf[PATH_MAX]; return execv_real(rewrite(path, buf), argv); } + +void *dlopen(const char *filename, int flag) +{ + void * (*__dlopen_real) (const char *, int) = dlsym(RTLD_NEXT, "dlopen"); + char buf[PATH_MAX]; + return __dlopen_real(rewrite(filename, buf), flag); +} From a961a289a9b2747e43c5475505eb6e4f58fe2ecc Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Sat, 20 Apr 2019 05:26:57 +0200 Subject: [PATCH 2/2] networkmanager: port to Meson All hail Meson! One serious issue is that building docs does not work. We patch gobject-introspection to use absolute paths for shared libraries in GIR files. Building the NetworkManager docs relies on the produced introspection data but since the library is not yet installed at the time the docs are generated, the build will fail. It works in Autotools for some reason; they probably use the pregenerated GIRs from the tarball. Disabling the docs completely is not possible at the moment either, since nmc [depends on them][1]. I have decided to fix this by pointing the installed location to the one in the build directory using libredirect. Unfortunately, we cannot just set the environment variables directly, since the build system runs the documentation generator in a clean environment. I have also added man, doc and devdoc outputs so the generated files have somewhere to go. Secondly, since Nix store is immutable, we also cannot use the package prefix for configuration and mutable state data. At the same time, we cannot write to the appropriate global directories during build. Autotools allowed to change this in installFlags but Meson lacks similar mechanism so we need to patch the build files. Finally, I also removed the at_console patch since the permission has been removed in 0.9.10. [1]: https://bugzilla.gnome.org/show_bug.cgi?id=796755 --- .../networking/network-manager/default.nix | 104 +++++++++--------- .../network-manager/fix-docs-build.patch | 11 ++ .../network-manager/fix-install-paths.patch | 25 +++++ 3 files changed, 91 insertions(+), 49 deletions(-) create mode 100644 pkgs/tools/networking/network-manager/fix-docs-build.patch create mode 100644 pkgs/tools/networking/network-manager/fix-install-paths.patch diff --git a/pkgs/tools/networking/network-manager/default.nix b/pkgs/tools/networking/network-manager/default.nix index 78aeb2a03edd..c4a34dc6a909 100644 --- a/pkgs/tools/networking/network-manager/default.nix +++ b/pkgs/tools/networking/network-manager/default.nix @@ -1,12 +1,14 @@ { stdenv, fetchurl, substituteAll, intltool, pkgconfig, dbus, dbus-glib -, gnome3, systemd, libuuid, polkit, gnutls, ppp, dhcp, iptables -, libgcrypt, dnsmasq, bluez5, readline +, gnome3, systemd, libuuid, polkit, gnutls, ppp, dhcp, iptables, python3, vala +, libgcrypt, dnsmasq, bluez5, readline, libselinux, audit , gobject-introspection, modemmanager, openresolv, libndp, newt, libsoup -, ethtool, gnused, coreutils, file, inetutils, kmod, jansson, libxslt -, python3Packages, docbook_xsl, openconnect, curl, autoreconfHook }: +, ethtool, gnused, coreutils, inetutils, kmod, jansson, gtk-doc, libxslt +, docbook_xsl, docbook_xml_dtd_412, docbook_xml_dtd_42, docbook_xml_dtd_43 +, openconnect, curl, meson, ninja, libpsl, libredirect }: let pname = "NetworkManager"; + pythonForDocs = python3.withPackages (pkgs: with pkgs; [ pygobject3 ]); in stdenv.mkDerivation rec { name = "network-manager-${version}"; version = "1.16.0"; @@ -16,44 +18,34 @@ in stdenv.mkDerivation rec { sha256 = "0b2x9hrg41cd17psqi0vacwj733v99hxczn53gdfs0yanqrji5lf"; }; - outputs = [ "out" "dev" ]; - - postPatch = '' - patchShebangs ./tools - ''; - - preConfigure = '' - substituteInPlace configure --replace /usr/bin/uname ${coreutils}/bin/uname - substituteInPlace configure --replace /usr/bin/file ${file}/bin/file - - # Fixes: error: po/Makefile.in.in was not created by intltoolize. - intltoolize --automake --copy --force - ''; + outputs = [ "out" "dev" "devdoc" "man" "doc" ]; # Right now we hardcode quite a few paths at build time. Probably we should # patch networkmanager to allow passing these path in config file. This will # remove unneeded build-time dependencies. - configureFlags = [ - "--with-dhclient=${dhcp}/bin/dhclient" - "--with-dnsmasq=${dnsmasq}/bin/dnsmasq" + mesonFlags = [ + "-Ddhclient=${dhcp}/bin/dhclient" + "-Ddnsmasq=${dnsmasq}/bin/dnsmasq" # Upstream prefers dhclient, so don't add dhcpcd to the closure - "--with-dhcpcd=no" - "--with-pppd=${ppp}/bin/pppd" - "--with-iptables=${iptables}/bin/iptables" + "-Ddhcpcd=no" + "-Dpppd=${ppp}/bin/pppd" + "-Diptables=${iptables}/bin/iptables" # to enable link-local connections - "--with-udev-dir=${placeholder "out"}/lib/udev" - "--with-resolvconf=${openresolv}/sbin/resolvconf" - "--sysconfdir=/etc" "--localstatedir=/var" - "--with-dbus-sys-dir=${placeholder "out"}/etc/dbus-1/system.d" - "--with-crypto=gnutls" "--disable-more-warnings" - "--with-systemdsystemunitdir=$(out)/etc/systemd/system" - "--with-kernel-firmware-dir=/run/current-system/firmware" - "--with-session-tracking=systemd" - "--with-modem-manager-1" - "--with-nmtui" - "--disable-gtk-doc" - "--with-libnm-glib" # legacy library, TODO: remove - "--disable-tests" + "-Dudev_dir=${placeholder "out"}/lib/udev" + "-Dresolvconf=${openresolv}/bin/resolvconf" + "-Ddbus_conf_dir=${placeholder "out"}/etc/dbus-1/system.d" + "-Dsystemdsystemunitdir=${placeholder "out"}/etc/systemd/system" + "-Dkernel_firmware_dir=/run/current-system/firmware" + "--sysconfdir=/etc" + "--localstatedir=/var" + "-Dcrypto=gnutls" + "-Dsession_tracking=systemd" + "-Dmodem_manager=true" + "-Dnmtui=true" + "-Ddocs=true" + "-Dlibnm_glib=true" # legacy library, TODO: remove + "-Dtests=no" + "-Dqt=false" ]; patches = [ @@ -63,31 +55,45 @@ in stdenv.mkDerivation rec { inherit (stdenv) shell; }) + # Meson does not support using different directories during build and + # for installation like Autotools did with flags passed to make install. + ./fix-install-paths.patch + + # Our gobject-introspection patches make the shared library paths absolute + # in the GIR files. When building docs, the library is not yet installed, + # though, so we need to replace the absolute path with a local one during build. + # We are replacing the variables in postPatch since substituteAll does not support + # placeholders. + ./fix-docs-build.patch ]; buildInputs = [ - systemd libuuid polkit ppp libndp curl + systemd libselinux audit libpsl libuuid polkit ppp libndp curl bluez5 dnsmasq gobject-introspection modemmanager readline newt libsoup jansson ]; - propagatedBuildInputs = [ dbus-glib gnutls libgcrypt python3Packages.pygobject3 ]; + propagatedBuildInputs = [ dbus-glib gnutls libgcrypt ]; - nativeBuildInputs = [ autoreconfHook intltool pkgconfig libxslt docbook_xsl ]; + nativeBuildInputs = [ + meson ninja intltool pkgconfig + vala gobject-introspection + dbus-glib # for dbus-binding-tool + # Docs + gtk-doc libxslt docbook_xsl docbook_xml_dtd_412 docbook_xml_dtd_42 docbook_xml_dtd_43 pythonForDocs + ]; doCheck = false; # requires /sys, the net - installFlags = [ - "sysconfdir=${placeholder "out"}/etc" - "localstatedir=${placeholder "out"}/var" - "runstatedir=${placeholder "out"}/run" - ]; + postPatch = '' + patchShebangs ./tools + patchShebangs libnm/generate-setting-docs.py + + substituteInPlace libnm/meson.build \ + --subst-var-by DOCS_LD_PRELOAD "${libredirect}/lib/libredirect.so" \ + --subst-var-by DOCS_NIX_REDIRECTS "${placeholder "out"}/lib/libnm.so.0=$PWD/build/libnm/libnm.so.0" + ''; postInstall = '' - mkdir -p $out/lib/NetworkManager - - # FIXME: Workaround until NixOS' dbus+systemd supports at_console policy - substituteInPlace $out/etc/dbus-1/system.d/org.freedesktop.NetworkManager.conf --replace 'at_console="true"' 'group="networkmanager"' - # systemd in NixOS doesn't use `systemctl enable`, so we need to establish # aliases ourselves. ln -s $out/etc/systemd/system/NetworkManager-dispatcher.service $out/etc/systemd/system/dbus-org.freedesktop.nm-dispatcher.service diff --git a/pkgs/tools/networking/network-manager/fix-docs-build.patch b/pkgs/tools/networking/network-manager/fix-docs-build.patch new file mode 100644 index 000000000000..45e18c42fbe1 --- /dev/null +++ b/pkgs/tools/networking/network-manager/fix-docs-build.patch @@ -0,0 +1,11 @@ +--- a/libnm/meson.build ++++ b/libnm/meson.build +@@ -262,6 +262,8 @@ + 'env', '-i', + 'GI_TYPELIB_PATH=' + gi_typelib_path, + 'LD_LIBRARY_PATH=' + ld_library_path, ++ 'LD_PRELOAD=' + '@DOCS_LD_PRELOAD@', ++ 'NIX_REDIRECTS=' + '@DOCS_NIX_REDIRECTS@', + ] + + name = 'nm-property-docs.xml' diff --git a/pkgs/tools/networking/network-manager/fix-install-paths.patch b/pkgs/tools/networking/network-manager/fix-install-paths.patch new file mode 100644 index 000000000000..068b9c8266b8 --- /dev/null +++ b/pkgs/tools/networking/network-manager/fix-install-paths.patch @@ -0,0 +1,25 @@ +--- a/meson.build ++++ b/meson.build +@@ -925,9 +925,9 @@ + join_paths('tools', 'meson-post-install.sh'), + nm_datadir, + nm_bindir, +- nm_pkgconfdir, ++ nm_prefix + nm_pkgconfdir, + nm_pkglibdir, +- nm_pkgstatedir, ++ nm_prefix + nm_pkgstatedir, + enable_docs ? 'install_docs' : '', + nm_mandir, + ) +--- a/src/settings/plugins/ifcfg-rh/meson.build ++++ b/src/settings/plugins/ifcfg-rh/meson.build +@@ -70,7 +70,7 @@ + ) + + meson.add_install_script('sh', '-c', +- 'mkdir -p $DESTDIR/@0@/sysconfig/network-scripts'.format(nm_sysconfdir)) ++ 'mkdir -p $DESTDIR/@0@/sysconfig/network-scripts'.format(nm_prefix + nm_sysconfdir)) + + if enable_tests + subdir('tests')