From fa417fe3f70bc446b3bb84b6028d00be954cf10d Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Mon, 7 Jul 2025 20:34:48 +0200 Subject: [PATCH 1/2] pylibfdt: Use the correct Python for tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit By default, Meson will find the version of Python that it itself is using, i.e. the default one in Nixpkgs. However, when building libfdt for other Python package sets, we need to make sure we match the version of the Python used for tests – otherwise the interpreter will not find the compiled module. Tweak meson.build to always use the Python interpreter that was passed to the expression, rather than the default one. --- pkgs/by-name/dt/dtc/package.nix | 11 ++++++++++- pkgs/by-name/dt/dtc/python-path.patch | 12 ++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 pkgs/by-name/dt/dtc/python-path.patch diff --git a/pkgs/by-name/dt/dtc/package.nix b/pkgs/by-name/dt/dtc/package.nix index 527ffe873bb2..ed41487a81b2 100644 --- a/pkgs/by-name/dt/dtc/package.nix +++ b/pkgs/by-name/dt/dtc/package.nix @@ -11,6 +11,7 @@ which, pythonSupport ? false, python ? null, + replaceVars, swig, libyaml, }: @@ -38,7 +39,15 @@ stdenv.mkDerivation (finalAttrs: { url = "https://github.com/dgibson/dtc/commit/ce1d8588880aecd7af264e422a16a8b33617cef7.patch"; hash = "sha256-t1CxKnbCXUArtVcniAIdNvahOGXPbYhPCZiTynGLvfo="; }) - ]; + ] + ++ + lib.optional pythonSupport + # Make Meson use our Python version, not the one it was built with itself + ( + replaceVars ./python-path.patch { + python_bin = lib.getExe python; + } + ); env.SETUPTOOLS_SCM_PRETEND_VERSION = finalAttrs.version; diff --git a/pkgs/by-name/dt/dtc/python-path.patch b/pkgs/by-name/dt/dtc/python-path.patch new file mode 100644 index 000000000000..6163dc0b294d --- /dev/null +++ b/pkgs/by-name/dt/dtc/python-path.patch @@ -0,0 +1,12 @@ +diff --git a/meson.build b/meson.build +index 310699f..4e2b8a4 100644 +--- a/meson.build ++++ b/meson.build +@@ -48,7 +48,7 @@ if not valgrind.found() + endif + + py = import('python') +-py = py.find_installation(required: get_option('python')) ++py = py.find_installation('@python_bin@', required: get_option('python')) + swig = find_program('swig', required: get_option('python')) + pylibfdt_enabled = not meson.is_cross_build() and py.found() and swig.found() ? true : false From 7bee2301502cb01fe7dc2cfde5d89955871df439 Mon Sep 17 00:00:00 2001 From: Kirill Elagin Date: Sun, 29 Jun 2025 15:15:21 +0200 Subject: [PATCH 2/2] libfdt: Rename the package to pylibfdt MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The “canonical” name of the Python libfdt package, i.e. the one used on PyPI and, hence, the one that is listed in the requirements of the dependent modules is `pylibfdt`, but the upstream build system produced a package called `libfdt`. Given that, realistically, everyone will be using `pylibfdt`, as seen on PyPI, our choices are to either patch / jailbreak the requirement in all dependent packages, or follow PyPI and rename the package itself. Rename the package once and for all, since it is easier than modifying every single dependent one. --- pkgs/by-name/dt/dtc/package.nix | 3 +++ pkgs/by-name/sn/snagboot/package.nix | 3 +-- .../development/python-modules/dtschema/default.nix | 5 ----- .../python-modules/dtschema/fix_libfdt_name.patch | 13 ------------- 4 files changed, 4 insertions(+), 20 deletions(-) delete mode 100644 pkgs/development/python-modules/dtschema/fix_libfdt_name.patch diff --git a/pkgs/by-name/dt/dtc/package.nix b/pkgs/by-name/dt/dtc/package.nix index ed41487a81b2..04db038594ac 100644 --- a/pkgs/by-name/dt/dtc/package.nix +++ b/pkgs/by-name/dt/dtc/package.nix @@ -69,6 +69,9 @@ stdenv.mkDerivation (finalAttrs: { postPatch = '' patchShebangs setup.py + + # Align the name with pypi + sed -i "s/name='libfdt',/name='pylibfdt',/" setup.py ''; # Required for installation of Python library and is innocuous otherwise. diff --git a/pkgs/by-name/sn/snagboot/package.nix b/pkgs/by-name/sn/snagboot/package.nix index 2582f8ac3077..d13ad71332a8 100644 --- a/pkgs/by-name/sn/snagboot/package.nix +++ b/pkgs/by-name/sn/snagboot/package.nix @@ -26,7 +26,6 @@ python3Packages.buildPythonApplication rec { ]; pythonRemoveDeps = [ - "pylibfdt" "swig" ]; @@ -40,7 +39,7 @@ python3Packages.buildPythonApplication rec { pyserial tftpy crccheck - # pylibfdt + libfdt # swig packaging ]; diff --git a/pkgs/development/python-modules/dtschema/default.nix b/pkgs/development/python-modules/dtschema/default.nix index 0550c0f481f5..73e982ae6079 100644 --- a/pkgs/development/python-modules/dtschema/default.nix +++ b/pkgs/development/python-modules/dtschema/default.nix @@ -25,11 +25,6 @@ buildPythonPackage rec { sha256 = "sha256-UJU8b9BzuuUSHRjnA6hOd1bMPNOlk4LNtrQV5aZmGhI="; }; - patches = [ - # Change name of pylibfdt to libfdt - ./fix_libfdt_name.patch - ]; - nativeBuildInputs = [ setuptools-scm ]; propagatedBuildInputs = [ diff --git a/pkgs/development/python-modules/dtschema/fix_libfdt_name.patch b/pkgs/development/python-modules/dtschema/fix_libfdt_name.patch deleted file mode 100644 index 093b13023fb3..000000000000 --- a/pkgs/development/python-modules/dtschema/fix_libfdt_name.patch +++ /dev/null @@ -1,13 +0,0 @@ -diff --git a/pyproject.toml b/pyproject.toml -index 2192a68..6a7ba95 100644 ---- a/pyproject.toml -+++ b/pyproject.toml -@@ -27,7 +27,7 @@ dependencies = [ - "ruamel.yaml>0.15.69", - "jsonschema>=4.1.2,<4.18", - "rfc3987", -- "pylibfdt", -+ "libfdt", - ] - - [project.scripts]