From 773369673c7741af55a0a1e675e35c8f3248e1e0 Mon Sep 17 00:00:00 2001 From: Ben Wolsieffer Date: Sat, 3 Oct 2020 19:02:46 -0400 Subject: [PATCH] samba: fix cross-compilation --- pkgs/servers/samba/4.x.nix | 38 ++++++-- ...uilt-heimdal-build-tools-in-case-of-.patch | 87 +++++++++++++++++++ pkgs/top-level/all-packages.nix | 5 +- 3 files changed, 118 insertions(+), 12 deletions(-) create mode 100644 pkgs/servers/samba/build-find-pre-built-heimdal-build-tools-in-case-of-.patch diff --git a/pkgs/servers/samba/4.x.nix b/pkgs/servers/samba/4.x.nix index 3ae30699546..fe2891f2ac7 100644 --- a/pkgs/servers/samba/4.x.nix +++ b/pkgs/servers/samba/4.x.nix @@ -1,13 +1,15 @@ { lib, stdenv +, buildPackages , fetchurl -, python +, python3 +, wafHook , pkg-config , bison , flex , perl , libxslt +, heimdal , docbook_xsl -, rpcgen , fixDarwinDylibNames , docbook_xml_dtd_45 , readline @@ -17,7 +19,6 @@ , libarchive , zlib , liburing -, fam , gnutls , libunwind , systemd @@ -59,26 +60,30 @@ stdenv.mkDerivation rec { ./patch-source3__libads__kerberos_keytab.c.patch ./4.x-no-persistent-install-dynconfig.patch ./4.x-fix-makeflags-parsing.patch + ./build-find-pre-built-heimdal-build-tools-in-case-of-.patch ]; nativeBuildInputs = [ + python3 + wafHook pkg-config bison flex perl perl.pkgs.ParseYapp libxslt + buildPackages.stdenv.cc + heimdal docbook_xsl docbook_xml_dtd_45 cmocka rpcsvc-proto ] ++ optionals stdenv.isDarwin [ - rpcgen fixDarwinDylibNames ]; buildInputs = [ - python + python3 readline popt dbus @@ -86,7 +91,6 @@ stdenv.mkDerivation rec { libbsd libarchive zlib - fam libunwind gnutls libtasn1 @@ -102,6 +106,8 @@ stdenv.mkDerivation rec { ++ optional enableAcl acl ++ optional enablePam pam; + wafPath = "buildtools/bin/waf"; + postPatch = '' # Removes absolute paths in scripts sed -i 's,/sbin/,,g' ctdb/config/functions @@ -112,7 +118,11 @@ stdenv.mkDerivation rec { patchShebangs ./buildtools/bin ''; - configureFlags = [ + preConfigure = '' + export PKGCONFIG="$PKG_CONFIG" + ''; + + wafConfigureFlags = [ "--with-static-modules=NONE" "--with-shared-modules=ALL" "--enable-fhs" @@ -126,7 +136,15 @@ stdenv.mkDerivation rec { "--without-ads" ] ++ optional enableProfiling "--with-profiling-data" ++ optional (!enableAcl) "--without-acl-support" - ++ optional (!enablePam) "--without-pam"; + ++ optional (!enablePam) "--without-pam" + ++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [ + "--bundled-libraries=!asn1_compile,!compile_et" + ]; + + # python-config from build Python gives incorrect values when cross-compiling. + # If python-config is not found, the build falls back to using the sysconfig + # module, which works correctly in all cases. + PYTHON_CONFIG = "/invalid"; preBuild = '' export MAKEFLAGS="-j $NIX_BUILD_CORES" @@ -146,6 +164,10 @@ stdenv.mkDerivation rec { patchelf --shrink-rpath "\$BIN"; EOF find $out -type f -name \*.so -exec $SHELL -c "$SCRIPT" \; + + # Samba does its own shebang patching, but uses build Python + find "$out/bin" -type f -executable -exec \ + sed -i '1 s^#!${python3.pythonForBuild}/bin/python.*^#!${python3.interpreter}^' {} \; ''; passthru = { diff --git a/pkgs/servers/samba/build-find-pre-built-heimdal-build-tools-in-case-of-.patch b/pkgs/servers/samba/build-find-pre-built-heimdal-build-tools-in-case-of-.patch new file mode 100644 index 00000000000..b8636958ee2 --- /dev/null +++ b/pkgs/servers/samba/build-find-pre-built-heimdal-build-tools-in-case-of-.patch @@ -0,0 +1,87 @@ +From e002d2ef2688d5433d2bd03aa4d77a0ec5ac4e63 Mon Sep 17 00:00:00 2001 +From: Uri Simchoni +Date: Sun, 20 Oct 2019 00:03:14 +0300 +Subject: [PATCH] build: find pre-built heimdal build tools in case of embedded + heimdal + +This patch fixes the case of finding asn1_compile and compile_et for +building embedded heimdal, by setting +--bundled-libraries='!asn1_compile,!compile_et' as configure flags. + +The Heimdal build tools compile_et and asn1_compile are needed *only* +if we use the embedded heimdal (otherwise we don't build heimdal and +use headers that have been generated by those tools elsewhere). + +For cross-compilation with embedded heimdal, it is vital to use host build +tools, and so asn1_compile and compile_et must be supplied and not +built. One way of doing this would be to set the COMPILE_ET and +ASN1_COMPILE env vars to the location of supplied binaries. Another way, +which is more commonly used, is to exclude asn1_compile and compile_et +from bundled packages via the switch +-bundled-libraries='!asn1_compile,!compile_et'. When this is done, +the build script searches the path for those tools and sets the +ASN1_COMPILE and COMPILE_ET vars accordingly. (this is admittedly +kind of a round-about way of doing things but this has become the +de-facto standard amongst embedded distro builders). + +In commit 8061983d4882f3ba3f12da71443b035d7b672eec, this process of +finding the binaris has been moved to be carried out only in the +system heimdal case. As explained above, we only need these tools, +and hence the check, in bundled mode. + +BUG: https://bugzilla.samba.org/show_bug.cgi?id=14164 + +Signed-off-by: Uri Simchoni +Signed-off-by: Bernd Kuhls +[Bernd: rebased for version 4.11.13] +--- + wscript_configure_embedded_heimdal | 11 +++++++++++ + wscript_configure_system_heimdal | 11 ----------- + 2 files changed, 11 insertions(+), 11 deletions(-) + +diff --git a/wscript_configure_embedded_heimdal b/wscript_configure_embedded_heimdal +index 8c55ae2a938..4fdae8062c5 100644 +--- a/wscript_configure_embedded_heimdal ++++ b/wscript_configure_embedded_heimdal +@@ -1 +1,12 @@ + conf.RECURSE('source4/heimdal_build') ++ ++def check_system_heimdal_binary(name): ++ if conf.LIB_MAY_BE_BUNDLED(name): ++ return False ++ if not conf.find_program(name, var=name.upper()): ++ return False ++ conf.define('USING_SYSTEM_%s' % name.upper(), 1) ++ return True ++ ++check_system_heimdal_binary("compile_et") ++check_system_heimdal_binary("asn1_compile") +diff --git a/wscript_configure_system_heimdal b/wscript_configure_system_heimdal +index 0ff6dad2f55..f77c177442f 100644 +--- a/wscript_configure_system_heimdal ++++ b/wscript_configure_system_heimdal +@@ -37,14 +37,6 @@ def check_system_heimdal_lib(name, functions='', headers='', onlyif=None): + conf.define('USING_SYSTEM_%s' % name.upper(), 1) + return True + +-def check_system_heimdal_binary(name): +- if conf.LIB_MAY_BE_BUNDLED(name): +- return False +- if not conf.find_program(name, var=name.upper()): +- return False +- conf.define('USING_SYSTEM_%s' % name.upper(), 1) +- return True +- + check_system_heimdal_lib("com_err", "com_right_r com_err", "com_err.h") + + if check_system_heimdal_lib("roken", "rk_socket_set_reuseaddr", "roken.h"): +@@ -96,7 +96,4 @@ + #if conf.CHECK_BUNDLED_SYSTEM('tommath', checkfunctions='mp_init', headers='tommath.h'): + # conf.define('USING_SYSTEM_TOMMATH', 1) + +-check_system_heimdal_binary("compile_et") +-check_system_heimdal_binary("asn1_compile") +- + conf.define('USING_SYSTEM_KRB5', 1) +-- +2.20.1 diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix index 2ae2cee9d8d..164e82e4650 100644 --- a/pkgs/top-level/all-packages.nix +++ b/pkgs/top-level/all-packages.nix @@ -20027,10 +20027,7 @@ in deadpixi-sam-unstable = callPackage ../applications/editors/deadpixi-sam { }; - samba4 = callPackage ../servers/samba/4.x.nix { - rpcgen = netbsd.rpcgen; - python = python3; - }; + samba4 = callPackage ../servers/samba/4.x.nix { }; samba = samba4;