From fb9727a19874b60d85690dc5a4046301328289b1 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Fri, 24 Jan 2025 18:14:22 +0800 Subject: [PATCH 1/4] makeOverridablePythonPackage: allow buildPython* to take fixed-point arguments --- .../interpreters/python/python-packages-base.nix | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pkgs/development/interpreters/python/python-packages-base.nix b/pkgs/development/interpreters/python/python-packages-base.nix index c513561ce6fb..dfb19b651285 100644 --- a/pkgs/development/interpreters/python/python-packages-base.nix +++ b/pkgs/development/interpreters/python/python-packages-base.nix @@ -23,7 +23,11 @@ let origArgs: let result = f origArgs; - overrideWith = newArgs: origArgs // lib.toFunction newArgs origArgs; + overrideWith = + if lib.isFunction origArgs then + newArgs: lib.extends (_: lib.toFunction newArgs) origArgs + else + newArgs: origArgs // lib.toFunction newArgs origArgs; in if lib.isAttrs result then result From 0969c6624713e3a3093bc586d5997ef93509ee76 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Fri, 24 Jan 2025 18:35:39 +0800 Subject: [PATCH 2/4] buildPython*: support fixed-point arguments via lib.extendMkDerivation Postpone formatting to minimize diff and to ease merging. --- .../python/mk-python-derivation.nix | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 4092c64ba713..1c5eddd453e4 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -99,7 +99,12 @@ let "wheel" ]; - cleanAttrs = flip removeAttrs [ +in + +lib.extendMkDerivation { + constructDrv = stdenv.mkDerivation; + + excludeDrvArgNames = [ "disabled" "checkPhase" "checkInputs" @@ -114,8 +119,8 @@ let "build-system" ]; -in - + extendDrvArgs = + finalAttrs: { # Build-time dependencies for the package nativeBuildInputs ? [ ], @@ -197,10 +202,6 @@ in ... }@attrs: -let - # Keep extra attributes from `attrs`, e.g., `patchPhase', etc. - self = stdenv.mkDerivation ( - finalAttrs: let getFinalPassthru = let @@ -283,8 +284,7 @@ let name = namePrefix + attrs.name or "${finalAttrs.pname}-${finalAttrs.version}"; in - (cleanAttrs attrs) - // { + { inherit name; inherit catchConflicts; @@ -448,7 +448,7 @@ let "enabledTests" ] attrs ) - ); + ; # This derivation transformation function must be independent to `attrs` # for fixed-point arguments support in the future. @@ -468,6 +468,4 @@ let }; in drv: disablePythonPackage (toPythonModule drv); - -in -transformDrv self +} From 7e1f654883711e756eaf128da749dc6c18100671 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 17 Feb 2025 06:41:22 +0800 Subject: [PATCH 3/4] buildPython*: format expressions --- .../python/mk-python-derivation.nix | 123 +++++++++--------- 1 file changed, 61 insertions(+), 62 deletions(-) diff --git a/pkgs/development/interpreters/python/mk-python-derivation.nix b/pkgs/development/interpreters/python/mk-python-derivation.nix index 1c5eddd453e4..1025d9a79516 100644 --- a/pkgs/development/interpreters/python/mk-python-derivation.nix +++ b/pkgs/development/interpreters/python/mk-python-derivation.nix @@ -121,86 +121,86 @@ lib.extendMkDerivation { extendDrvArgs = finalAttrs: -{ - # Build-time dependencies for the package - nativeBuildInputs ? [ ], + { + # Build-time dependencies for the package + nativeBuildInputs ? [ ], - # Run-time dependencies for the package - buildInputs ? [ ], + # Run-time dependencies for the package + buildInputs ? [ ], - # Dependencies needed for running the checkPhase. - # These are added to buildInputs when doCheck = true. - checkInputs ? [ ], - nativeCheckInputs ? [ ], + # Dependencies needed for running the checkPhase. + # These are added to buildInputs when doCheck = true. + checkInputs ? [ ], + nativeCheckInputs ? [ ], - # propagate build dependencies so in case we have A -> B -> C, - # C can import package A propagated by B - propagatedBuildInputs ? [ ], + # propagate build dependencies so in case we have A -> B -> C, + # C can import package A propagated by B + propagatedBuildInputs ? [ ], - # Python module dependencies. - # These are named after PEP-621. - dependencies ? [ ], - optional-dependencies ? { }, + # Python module dependencies. + # These are named after PEP-621. + dependencies ? [ ], + optional-dependencies ? { }, - # Python PEP-517 build systems. - build-system ? [ ], + # Python PEP-517 build systems. + build-system ? [ ], - # DEPRECATED: use propagatedBuildInputs - pythonPath ? [ ], + # DEPRECATED: use propagatedBuildInputs + pythonPath ? [ ], - # Enabled to detect some (native)BuildInputs mistakes - strictDeps ? true, + # Enabled to detect some (native)BuildInputs mistakes + strictDeps ? true, - outputs ? [ "out" ], + outputs ? [ "out" ], - # used to disable derivation, useful for specific python versions - disabled ? false, + # used to disable derivation, useful for specific python versions + disabled ? false, - # Raise an error if two packages are installed with the same name - # TODO: For cross we probably need a different PYTHONPATH, or not - # add the runtime deps until after buildPhase. - catchConflicts ? (python.stdenv.hostPlatform == python.stdenv.buildPlatform), + # Raise an error if two packages are installed with the same name + # TODO: For cross we probably need a different PYTHONPATH, or not + # add the runtime deps until after buildPhase. + catchConflicts ? (python.stdenv.hostPlatform == python.stdenv.buildPlatform), - # Additional arguments to pass to the makeWrapper function, which wraps - # generated binaries. - makeWrapperArgs ? [ ], + # Additional arguments to pass to the makeWrapper function, which wraps + # generated binaries. + makeWrapperArgs ? [ ], - # Skip wrapping of python programs altogether - dontWrapPythonPrograms ? false, + # Skip wrapping of python programs altogether + dontWrapPythonPrograms ? false, - # Don't use Pip to install a wheel - # Note this is actually a variable for the pipInstallPhase in pip's setupHook. - # It's included here to prevent an infinite recursion. - dontUsePipInstall ? false, + # Don't use Pip to install a wheel + # Note this is actually a variable for the pipInstallPhase in pip's setupHook. + # It's included here to prevent an infinite recursion. + dontUsePipInstall ? false, - # Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs - permitUserSite ? false, + # Skip setting the PYTHONNOUSERSITE environment variable in wrapped programs + permitUserSite ? false, - # Remove bytecode from bin folder. - # When a Python script has the extension `.py`, bytecode is generated - # Typically, executables in bin have no extension, so no bytecode is generated. - # However, some packages do provide executables with extensions, and thus bytecode is generated. - removeBinBytecode ? true, + # Remove bytecode from bin folder. + # When a Python script has the extension `.py`, bytecode is generated + # Typically, executables in bin have no extension, so no bytecode is generated. + # However, some packages do provide executables with extensions, and thus bytecode is generated. + removeBinBytecode ? true, - # pyproject = true <-> format = "pyproject" - # pyproject = false <-> format = "other" - # https://github.com/NixOS/nixpkgs/issues/253154 - pyproject ? null, + # pyproject = true <-> format = "pyproject" + # pyproject = false <-> format = "other" + # https://github.com/NixOS/nixpkgs/issues/253154 + pyproject ? null, - # Several package formats are supported. - # "setuptools" : Install a common setuptools/distutils based package. This builds a wheel. - # "wheel" : Install from a pre-compiled wheel. - # "pyproject": Install a package using a ``pyproject.toml`` file (PEP517). This builds a wheel. - # "egg": Install a package from an egg. - # "other" : Provide your own buildPhase and installPhase. - format ? null, + # Several package formats are supported. + # "setuptools" : Install a common setuptools/distutils based package. This builds a wheel. + # "wheel" : Install from a pre-compiled wheel. + # "pyproject": Install a package using a ``pyproject.toml`` file (PEP517). This builds a wheel. + # "egg": Install a package from an egg. + # "other" : Provide your own buildPhase and installPhase. + format ? null, - meta ? { }, + meta ? { }, - doCheck ? true, + doCheck ? true, - ... -}@attrs: + ... + }@attrs: let getFinalPassthru = @@ -447,8 +447,7 @@ lib.extendMkDerivation { "enabledTestPaths" "enabledTests" ] attrs - ) - ; + ); # This derivation transformation function must be independent to `attrs` # for fixed-point arguments support in the future. From db639b411544c73badd81f2c838548b9c492e2f4 Mon Sep 17 00:00:00 2001 From: Yueh-Shun Li Date: Mon, 29 May 2023 05:43:54 +0800 Subject: [PATCH 4/4] pyspread: use fixed-point arguments --- pkgs/by-name/py/pyspread/package.nix | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/pkgs/by-name/py/pyspread/package.nix b/pkgs/by-name/py/pyspread/package.nix index 1eef51e14bae..3e19974c4fe4 100644 --- a/pkgs/by-name/py/pyspread/package.nix +++ b/pkgs/by-name/py/pyspread/package.nix @@ -8,21 +8,20 @@ }: let - # get rid of rec - pname = "pyspread"; - version = "2.4"; - src = fetchPypi { - inherit pname version; - hash = "sha256-MZlR2Rap5oMRfCmswg9W//FYFkSEki7eyMNhLoGZgJM="; - }; inherit (libsForQt5) qtsvg wrapQtAppsHook ; in -python3.pkgs.buildPythonApplication { +python3.pkgs.buildPythonApplication (finalAttrs: { format = "setuptools"; - inherit pname version src; + pname = "pyspread"; + version = "2.4"; + src = fetchPypi { + pname = "pyspread"; + inherit (finalAttrs) version; + hash = "sha256-MZlR2Rap5oMRfCmswg9W//FYFkSEki7eyMNhLoGZgJM="; + }; nativeBuildInputs = [ copyDesktopItems @@ -86,4 +85,4 @@ python3.pkgs.buildPythonApplication { mainProgram = "pyspread"; maintainers = [ ]; }; -} +})