From 948d0cf589ee818549e20c4315429c6aae2802a0 Mon Sep 17 00:00:00 2001 From: Audrey Dutcher Date: Tue, 14 May 2024 13:32:44 -0700 Subject: [PATCH] python3: fix build on native FreeBSD * Make use of libxcrypt conditional (documented inline) * Patch use of uname to to not pull in some impure information * Various cases where behavior is split out among operating systems are now inclusive of FreeBSD --- .../interpreters/python/cpython/default.nix | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/pkgs/development/interpreters/python/cpython/default.nix b/pkgs/development/interpreters/python/cpython/default.nix index 37b9d19fe88d..f32787c04c8d 100644 --- a/pkgs/development/interpreters/python/cpython/default.nix +++ b/pkgs/development/interpreters/python/cpython/default.nix @@ -121,6 +121,9 @@ let versionOlder ; + # mixes libc and libxcrypt headers and libs and causes segfaults on importing crypt + libxcrypt = if stdenv.hostPlatform.isFreeBSD then null else inputs.libxcrypt; + buildPackages = pkgsBuildHost; inherit (passthru) pythonOnBuildForHost; @@ -261,6 +264,7 @@ let multiarch = if isDarwin then "darwin" + else if isFreeBSD then "" else if isWindows then "" else "${multiarchCpu}-${machdep}-${pythonAbiName}"; @@ -445,7 +449,11 @@ in with passthru; stdenv.mkDerivation (finalAttrs: { "LDFLAGS=-static" ]; - preConfigure = optionalString (pythonOlder "3.12") '' + preConfigure = '' + # Attempt to purify some of the host info collection + sed -E -i -e 's/uname -r/echo/g' -e 's/uname -n/echo nixpkgs/g' config.guess + sed -E -i -e 's/uname -r/echo/g' -e 's/uname -n/echo nixpkgs/g' configure + '' + optionalString (pythonOlder "3.12") '' # Improve purity for path in /usr /sw /opt /pkg; do substituteInPlace ./setup.py --replace-warn $path /no-such-path @@ -476,10 +484,10 @@ in with passthru; stdenv.mkDerivation (finalAttrs: { postInstall = let # References *not* to nuke from (sys)config files keep-references = concatMapStringsSep " " (val: "-e ${val}") ([ - (placeholder "out") libxcrypt - ] ++ optionals tzdataSupport [ - tzdata - ]); + (placeholder "out") + ] ++ lib.optional (libxcrypt != null) libxcrypt + ++ lib.optional tzdataSupport tzdata + ); in lib.optionalString enableFramework '' for dir in include lib share; do ln -s $out/Library/Frameworks/Python.framework/Versions/Current/$dir $out/$dir @@ -661,7 +669,7 @@ in with passthru; stdenv.mkDerivation (finalAttrs: { ''; license = licenses.psfl; pkgConfigModules = [ "python3" ]; - platforms = platforms.linux ++ platforms.darwin ++ platforms.windows; + platforms = platforms.linux ++ platforms.darwin ++ platforms.windows ++ platforms.freebsd; mainProgram = executable; }; })