Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 44 additions & 29 deletions pkgs/development/interpreters/python/cpython/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,23 @@
pkg-config,
python-setup-hook,

# high level switches
withMinimalDeps ? false,

# runtime dependencies
bzip2,
withExpat ? true,
withExpat ? !withMinimalDeps,
expat,
libffi,
libuuid,
withLibxcrypt ? !withMinimalDeps,
libxcrypt,
withMpdecimal ? true,
withMpdecimal ? !withMinimalDeps,
mpdecimal,
ncurses,
withOpenssl ? !withMinimalDeps,
openssl,
withSqlite ? !withMinimalDeps,
sqlite,
xz,
zlib,
Expand All @@ -35,12 +41,12 @@
# optional dependencies
bluezSupport ? false,
bluez,
mimetypesSupport ? true,
mimetypesSupport ? !withMinimalDeps,
mailcap,
tzdata,
withGdbm ? !stdenv.hostPlatform.isWindows,
withGdbm ? !withMinimalDeps && !stdenv.hostPlatform.isWindows,
gdbm,
withReadline ? !stdenv.hostPlatform.isWindows,
withReadline ? !withMinimalDeps && !stdenv.hostPlatform.isWindows,
readline,
x11Support ? false,
tcl,
Expand All @@ -63,13 +69,13 @@
sourceVersion,
hash,
passthruFun,
stripConfig ? false,
stripIdlelib ? false,
stripTests ? false,
stripTkinter ? false,
rebuildBytecode ? true,
stripConfig ? withMinimalDeps,
stripIdlelib ? withMinimalDeps,
stripTests ? withMinimalDeps,
stripTkinter ? withMinimalDeps,
rebuildBytecode ? !withMinimalDeps,
stripBytecode ? true,
includeSiteCustomize ? true,
includeSiteCustomize ? !withMinimalDeps,
static ? stdenv.hostPlatform.isStatic,
enableFramework ? false,
noldconfigPatch ? ./. + "/${sourceVersion.major}.${sourceVersion.minor}/no-ldconfig.patch",
Expand All @@ -85,7 +91,8 @@

# enabling LTO on 32bit arch causes downstream packages to fail when linking
enableLTO ?
stdenv.hostPlatform.isDarwin || (stdenv.hostPlatform.is64bit && stdenv.hostPlatform.isLinux),
!withMinimalDeps
&& (stdenv.hostPlatform.isDarwin || (stdenv.hostPlatform.is64bit && stdenv.hostPlatform.isLinux)),

# enable asserts to ensure the build remains reproducible
reproducibleBuild ? false,
Expand All @@ -97,7 +104,9 @@
testers,

# allow pythonMinimal to prevent accidental dependencies it doesn't want
allowedReferenceNames ? [ ],
# Having this as an option is useful to allow overriding, eg. adding things to
# python3Minimal
allowedReferenceNames ? if withMinimalDeps then [ "bashNonInteractive" ] else [ ],

}@inputs:

Expand Down Expand Up @@ -140,12 +149,12 @@ let
;

# mixes libc and libxcrypt headers and libs and causes segfaults on importing crypt
libxcrypt = if stdenv.hostPlatform.isFreeBSD then null else inputs.libxcrypt;
libxcrypt = if stdenv.hostPlatform.isFreeBSD && withMinimalDeps then null else inputs.libxcrypt;

buildPackages = pkgsBuildHost;
inherit (passthru) pythonOnBuildForHost;

tzdataSupport = tzdata != null && passthru.pythonAtLeast "3.9";
tzdataSupport = !withMinimalDeps && tzdata != null && passthru.pythonAtLeast "3.9";

passthru =
let
Expand Down Expand Up @@ -200,11 +209,11 @@ let
nativeBuildInputs = [
nukeReferences
]
++ optionals (!stdenv.hostPlatform.isDarwin) [
++ optionals (!stdenv.hostPlatform.isDarwin && !withMinimalDeps) [
autoconf-archive # needed for AX_CHECK_COMPILE_FLAG
autoreconfHook
]
++ optionals (!stdenv.hostPlatform.isDarwin || passthru.pythonAtLeast "3.14") [
++ optionals ((!stdenv.hostPlatform.isDarwin || passthru.pythonAtLeast "3.14") && !withMinimalDeps) [
pkg-config
]
++ optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
Expand All @@ -223,26 +232,32 @@ let
];

buildInputs = lib.filter (p: p != null) (
[
optionals (!withMinimalDeps) [
bzip2
libffi
libuuid
libxcrypt
ncurses
openssl
sqlite
xz
zlib
]
++ optionals (passthru.pythonAtLeast "3.14") [
zstd
++ optionals withLibxcrypt [
libxcrypt
]
++ optionals withOpenssl [
openssl
]
++ optionals withSqlite [
sqlite
]
++ optionals withMpdecimal [
mpdecimal
]
++ optionals withExpat [
expat
]
++ optionals (passthru.pythonAtLeast "3.14") [
zstd
]
++ optionals bluezSupport [
bluez
]
Expand Down Expand Up @@ -435,7 +450,7 @@ stdenv.mkDerivation (finalAttrs: {
env = {
CPPFLAGS = concatStringsSep " " (map (p: "-I${getDev p}/include") buildInputs);
LDFLAGS = concatStringsSep " " (map (p: "-L${getLib p}/lib") buildInputs);
LIBS = "${optionalString (!stdenv.hostPlatform.isDarwin && libxcrypt != null) "-lcrypt"}";
LIBS = "${optionalString (!stdenv.hostPlatform.isDarwin && withLibxcrypt) "-lcrypt"}";
NIX_LDFLAGS = lib.optionalString (stdenv.cc.isGNU && !stdenv.hostPlatform.isStatic) (
{
"glibc" = "-lgcc_s";
Expand All @@ -457,7 +472,7 @@ stdenv.mkDerivation (finalAttrs: {
++ optionals withMpdecimal [
"--with-system-libmpdec"
]
++ optionals (openssl != null) [
++ optionals withOpenssl [
"--with-openssl=${openssl.dev}"
]
++ optionals tzdataSupport [
Expand All @@ -484,10 +499,10 @@ stdenv.mkDerivation (finalAttrs: {
++ optionals enableDebug [
"--with-pydebug"
]
++ optionals (sqlite != null) [
++ optionals withSqlite [
"--enable-loadable-sqlite-extensions"
]
++ optionals (libxcrypt != null) [
++ optionals withLibxcrypt [
"CFLAGS=-I${libxcrypt}/include"
"LIBS=-L${libxcrypt}/lib"
]
Expand Down Expand Up @@ -592,7 +607,7 @@ stdenv.mkDerivation (finalAttrs: {
[
(placeholder "out")
]
++ lib.optional (libxcrypt != null) libxcrypt
++ lib.optional withLibxcrypt libxcrypt
++ lib.optional tzdataSupport tzdata
);
in
Expand Down Expand Up @@ -758,7 +773,7 @@ stdenv.mkDerivation (finalAttrs: {
# Enforce that we don't have references to the OpenSSL -dev package, which we
# explicitly specify in our configure flags above.
disallowedReferences =
lib.optionals (openssl != null && !static && !enableFramework) [
lib.optionals (withOpenssl && !static && !enableFramework) [
openssl.dev
]
++ lib.optionals (stdenv.hostPlatform != stdenv.buildPlatform) [
Expand Down
32 changes: 1 addition & 31 deletions pkgs/development/interpreters/python/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -105,37 +105,7 @@
inherit passthruFun;
pythonAttr = "python3Minimal";
# strip down that python version as much as possible
openssl = null;
readline = null;
ncurses = null;
gdbm = null;
sqlite = null;
tzdata = null;
libuuid = null;
bzip2 = null;
libxcrypt = null;
xz = null;
zlib = null;
libffi = null;
stripConfig = true;
stripIdlelib = true;
stripTests = true;
stripTkinter = true;
rebuildBytecode = false;
stripBytecode = true;
includeSiteCustomize = false;
enableOptimizations = false;
enableLTO = false;
mimetypesSupport = false;
withExpat = false;
withMpdecimal = false;
/*
The actual 'allowedReferences' attribute is set inside the cpython derivation.
This is necessary in order to survive overrides of dependencies.
*/
allowedReferenceNames = [
"bashNonInteractive"
];
withMinimalDeps = true;
}
// sources.python313
)).overrideAttrs
Expand Down
Loading