From 919cd2199064ec268835f5e7911560b7bea908b7 Mon Sep 17 00:00:00 2001 From: DavHau Date: Tue, 22 Aug 2023 12:45:27 +0200 Subject: [PATCH] feat(pip): add option flattenedDependencies for requirements specifications without root --- modules/drv-parts/pip/default.nix | 27 ++++++++++++++++++++++++--- modules/drv-parts/pip/interface.nix | 7 +++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/modules/drv-parts/pip/default.nix b/modules/drv-parts/pip/default.nix index 00186798..9c5aed0f 100644 --- a/modules/drv-parts/pip/default.nix +++ b/modules/drv-parts/pip/default.nix @@ -81,12 +81,13 @@ doCheck = l.mkDefault false; nativeBuildInputs = - l.optionals config.deps.stdenv.isLinux [config.deps.autoPatchelfHook]; + [config.deps.unzip] + ++ (l.optionals config.deps.stdenv.isLinux [config.deps.autoPatchelfHook]); buildInputs = l.optionals config.deps.stdenv.isLinux [config.deps.manylinux1]; propagatedBuildInputs = let - depsByExtra = extra: metadata.targets.${extra}.${config.name} or []; - defaultDeps = metadata.targets.default.${config.name} or []; + depsByExtra = extra: targets.${extra}.${config.name} or []; + defaultDeps = targets.default.${config.name} or []; deps = defaultDeps ++ (l.concatLists (l.map depsByExtra cfg.buildExtras)); in l.map (name: cfg.drvs.${name}.public.out) deps; @@ -122,6 +123,26 @@ in { mkDerivation = { dontStrip = l.mkDefault true; + propagatedBuildInputs = + if cfg.flattenDependencies + then + if targets.default ? ${config.name} + then + throw '' + Top-level package ${config.name} is listed in the lockfile. + Set `pip.flattenDependencies` to false to use only the top-level dependencies. + '' + else let + topLevelDepNames = l.attrNames (targets.default); + in + l.map (name: cfg.drvs.${name}.public.out) topLevelDepNames + else if ! targets.default ? ${config.name} + then + throw '' + Top-level package ${config.name} is not listed in the lockfile. + Set `pip.flattenDependencies` to true to use all dependencies for the top-level package. + '' + else []; }; }; } diff --git a/modules/drv-parts/pip/interface.nix b/modules/drv-parts/pip/interface.nix index 5735488d..7a5976b1 100644 --- a/modules/drv-parts/pip/interface.nix +++ b/modules/drv-parts/pip/interface.nix @@ -9,6 +9,13 @@ t = l.types; in { options.pip = { + flattenDependencies = l.mkOption { + type = t.bool; + description = '' + Use all dependencies as top-level dependencies + ''; + default = false; + }; pypiSnapshotDate = l.mkOption { type = t.str; description = ''