feat: allow specifying env for fetchPipMetadata

This helps for configuring pip with environment variables. See https://github.com/nix-community/dream2nix/discussions/697 for more context.

pip: remove callPackage
This commit is contained in:
Jairo Llopis 2023-09-22 07:50:13 +01:00 committed by mergify[bot]
parent 4c0d029add
commit cf853080a3
3 changed files with 36 additions and 13 deletions

View File

@ -122,7 +122,7 @@ in {
# with the intention to keep modules independent.
fetchPipMetadataScript = import ../../../pkgs/fetchPipMetadata/script.nix {
inherit lib;
inherit (cfg) pypiSnapshotDate pipFlags pipVersion requirementsList requirementsFiles nativeBuildInputs;
inherit (cfg) env pypiSnapshotDate pipFlags pipVersion requirementsList requirementsFiles nativeBuildInputs;
inherit (config.deps) writePureShellScript nix;
inherit (config.paths) findRoot;
inherit (nixpkgs) gitMinimal nix-prefetch-scripts python3 writeText;
@ -141,18 +141,22 @@ in {
# if any of the invalidationData changes, the lock file will be invalidated
# and the user will be promted to re-generate it.
lock.invalidationData = {
pip = {
inherit
(config.pip)
pypiSnapshotDate
pipFlags
pipVersion
requirementsList
requirementsFiles
;
# don't invalidate on bugfix version changes
pythonVersion = lib.init (lib.splitVersion config.deps.python.version);
};
pip =
{
inherit
(config.pip)
pypiSnapshotDate
pipFlags
pipVersion
requirementsList
requirementsFiles
;
# don't invalidate on bugfix version changes
pythonVersion = lib.init (lib.splitVersion config.deps.python.version);
}
# including env conditionally to not invalidate all existing lockfiles
# TODO: refactor once compat is broken through something else
// (lib.optionalAttrs (config.pip.env != {}) config.pip.env);
};
pip = {

View File

@ -22,6 +22,18 @@ in {
};
# user interface
env = l.mkOption {
type = t.attrsOf t.str;
default = {};
description = ''
environment variables exported while locking
'';
example = lib.literalExpression ''
{
PIP_FIND_LINKS = "${config.deps.setuptools.dist}";
}
'';
};
pypiSnapshotDate = l.mkOption {
type = t.nullOr t.str;
description = ''

View File

@ -26,6 +26,7 @@
requirementsFiles ? [],
pipFlags ? [],
pipVersion ? "23.1",
env ? {},
wheelVersion ? "0.40.0",
nativeBuildInputs ? [],
# maximum release date for packages
@ -86,6 +87,12 @@
writePureShellScript
path
''
${
lib.foldlAttrs
(acc: name: value: acc + "\nexport " + lib.toShellVar name value)
""
env
}
${package}/bin/fetch_pip_metadata \
--json-args-file ${args} \
--project-root $(${findRoot})