fix: infinite recursion in passthru

This commit is contained in:
DavHau 2020-10-26 01:07:12 +07:00
parent ddddcaa774
commit ffd51659df
3 changed files with 12 additions and 11 deletions

View file

@ -38,7 +38,7 @@ class OverridesGenerator(ExpressionGenerator):
def _gen_imports(self):
out = f"""
{{ pkgs, ... }}:
{{ pkgs, python, ... }}:
with builtins;
with pkgs.lib;
let
@ -85,17 +85,18 @@ class OverridesGenerator(ExpressionGenerator):
);
in
toString res.value;
get_passthru = python: pypi_name: nix_name:
get_passthru = pypi_name: nix_name:
# if pypi_name is in nixpkgs, we must pick it, otherwise risk infinite recursion.
let
pname = if hasAttr "${{pypi_name}}" python then pypi_name else nix_name;
python_pkgs = python.pkgs;
pname = if hasAttr "${{pypi_name}}" python_pkgs then pypi_name else nix_name;
in
if hasAttr "${{pname}}" python then
if hasAttr "${{pname}}" python_pkgs then
let result = (tryEval
(if isNull python."${{pname}}" then
(if isNull python_pkgs."${{pname}}" then
{{}}
else
python."${{pname}}".passthru));
python_pkgs."${{pname}}".passthru));
in
if result.success then result.value else {{}}
else {{}};
@ -147,7 +148,7 @@ class OverridesGenerator(ExpressionGenerator):
"{name}" = override python-super.{nix_name} ( oldAttrs: {{
pname = "{name}";
version = "{ver}";
passthru = (get_passthru python-super "{name}" "{nix_name}") // {{ provider = "{provider}"; }};
passthru = (get_passthru "{name}" "{nix_name}") // {{ provider = "{provider}"; }};
buildInputs = with python-self; (replace_deps oldAttrs "buildInputs" self) ++ [ {build_inputs_str} ];
propagatedBuildInputs = with python-self; (replace_deps oldAttrs "propagatedBuildInputs" self) ++ [ {prop_build_inputs_str} ];"""
if not keep_src:
@ -166,7 +167,7 @@ class OverridesGenerator(ExpressionGenerator):
pname = "{name}";
version = "{ver}";
src = fetchPypi "{name}" "{ver}";
passthru = (get_passthru python-super "{name}" "{nix_name}") // {{ provider = "sdist"; }};"""
passthru = (get_passthru "{name}" "{nix_name}") // {{ provider = "sdist"; }};"""
if circular_deps:
out += f"""
pipInstallFlags = "--no-dependencies";"""
@ -191,7 +192,7 @@ class OverridesGenerator(ExpressionGenerator):
src = fetchPypiWheel "{name}" "{ver}" "{fname}";
format = "wheel";
dontStrip = true;
passthru = (get_passthru python-super "{name}" "{nix_name}") // {{ provider = "wheel"; }};"""
passthru = (get_passthru "{name}" "{nix_name}") // {{ provider = "wheel"; }};"""
if circular_deps:
out += f"""
pipInstallFlags = "--no-dependencies";"""

View file

@ -19,7 +19,7 @@ rec {
# Returns `overrides` and `select_pkgs` which satisfy your requirements
compileOverrides = args:
let
result = import "${compileExpression args}/share/mach_nix_file.nix" { pkgs = args.pkgs; };
result = import "${compileExpression args}/share/mach_nix_file.nix" { inherit (args) pkgs python; };
manylinux =
if args.pkgs.stdenv.hostPlatform.system == "x86_64-darwin" then
[]

View file

@ -54,7 +54,6 @@ def env(args, nixpkgs_rev, nixpkgs_sha256):
python_nix_file = f"{target_dir}/python.nix"
python_nix_content = dedent(f"""
let
result = import ./machnix.nix {{ inherit pkgs; }};
nixpkgs_commit = "{nixpkgs_rev}";
nixpkgs_sha256 = "{nixpkgs_sha256}";
pkgs = import (builtins.fetchTarball {{
@ -63,6 +62,7 @@ def env(args, nixpkgs_rev, nixpkgs_sha256):
sha256 = nixpkgs_sha256;
}}) {{ config = {{}}; overlays = []; }};
python = pkgs.python{str(py_ver.digits())};
result = import ./machnix.nix {{ inherit pkgs python; }};
manylinux1 = pkgs.pythonManylinuxPackages.manylinux1;
overrides = result.overrides manylinux1 pkgs.autoPatchelfHook;
py = python.override {{ packageOverrides = overrides; }};