From d3f7baaad04e91b24ebe8d8195ae31d5da955377 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 3 Apr 2026 10:36:44 +0200 Subject: [PATCH 1/4] python3Packages.tyro: 1.0.10 -> 1.0.12 https://github.com/brentyi/tyro/releases/tag/v1.0.12 Drop obsolete runtime dependencies that upstream moved to optional extras, keep the lightweight dev-only check inputs that are still exercised in nixpkgs, document the wider terminal dimensions needed to keep the argparse output tests stable, and keep only the one Python 3.13 test skip that still reproduces in the Nix build environment. --- .../python-modules/tyro/default.nix | 47 ++++++++++--------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/pkgs/development/python-modules/tyro/default.nix b/pkgs/development/python-modules/tyro/default.nix index 1a50bfdaf78c..2bc2053f8e7a 100644 --- a/pkgs/development/python-modules/tyro/default.nix +++ b/pkgs/development/python-modules/tyro/default.nix @@ -9,71 +9,72 @@ # dependencies docstring-parser, - rich, - shtab, typeguard, typing-extensions, # tests attrs, - flax, - jax, ml-collections, msgspec, omegaconf, pydantic, pytestCheckHook, - torch, + shtab, universal-pathlib, }: buildPythonPackage (finalAttrs: { pname = "tyro"; - version = "1.0.10"; + version = "1.0.12"; pyproject = true; src = fetchFromGitHub { owner = "brentyi"; repo = "tyro"; tag = "v${finalAttrs.version}"; - hash = "sha256-k8f0eSeBBCROSsf7WooapDIFoy1G4Guxpbb7eNbj6ps="; + hash = "sha256-e4LIJzZ7lIkvhqbOz/EGHgPo9ri1HNiMp0j+I1S0/J4="; }; build-system = [ hatchling ]; dependencies = [ docstring-parser - rich - shtab typeguard typing-extensions ]; + # Upstream's neural-network integration tests are optional and skipped when + # flax/torch are unavailable, so keep the lightweight dev extras only. nativeCheckInputs = [ attrs - flax - jax ml-collections msgspec omegaconf pydantic pytestCheckHook - torch + shtab universal-pathlib ]; - disabledTests = lib.optionals (pythonAtLeast "3.13") [ - # Bash path completion relies on the programmable-completion builtin `compgen`, - # which is unavailable in the stdenv build shell. - "test_bash_path_completion_marker" + disabledTests = + lib.optionals (pythonAtLeast "3.13") [ + # The bash path-completion functional test still returns no file + # completions in the Nix build environment. + "test_bash_path_completion_marker" + ] + ++ lib.optionals (pythonAtLeast "3.14") [ + # Upstream checks that the literal substring `bc` never appears in the + # help text, but under Nix the `python -m pytest` runner path can include + # that substring in the store hash used for `sys.argv[0]`. + "test_suppress_subcommand" + ]; - # In Nix builds, the long `python -m pytest` argv[0] path gets line-wrapped in - # argparse error output, splitting `class-b` and `)` so this literal-match fails. - "test_similar_arguments_subcommands_multiple_contains_match" - - # Same wrapped-output literal-match issue as above for the cascading-args variant. - "test_similar_arguments_subcommands_multiple_contains_match_cascading" - ]; + # Keep argparse help output on a single line where possible so the + # literal-output tests do not fail due to terminal line wrapping. + preCheck = '' + export COLUMNS=200 + export LINES=200 + ''; pythonImportsCheck = [ "tyro" ]; From a424a303876a23705e49731cf9cd30c6f65bca64 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 3 Apr 2026 10:36:48 +0200 Subject: [PATCH 2/4] python3Packages.trl: 0.27.0 -> 0.24.0 https://github.com/huggingface/trl/releases/tag/v0.24.0 Keep trl within the version range required by unsloth and unsloth-zoo, retain the missing packaging and rich runtime dependencies, and keep the package expression on finalAttrs. --- .../python-modules/trl/default.nix | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/pkgs/development/python-modules/trl/default.nix b/pkgs/development/python-modules/trl/default.nix index 3a9e73c30233..8ab0fb06b06a 100644 --- a/pkgs/development/python-modules/trl/default.nix +++ b/pkgs/development/python-modules/trl/default.nix @@ -5,35 +5,33 @@ # build-system setuptools, - setuptools-scm, # dependencies accelerate, datasets, + packaging, rich, transformers, }: -buildPythonPackage rec { +buildPythonPackage (finalAttrs: { pname = "trl"; - version = "0.27.0"; + version = "0.24.0"; pyproject = true; src = fetchFromGitHub { owner = "huggingface"; repo = "trl"; - tag = "v${version}"; - hash = "sha256-NEvIWrirHqcLJpyA894NgNFPn/Svg+ND/xDMIRHW8d0="; + tag = "v${finalAttrs.version}"; + hash = "sha256-t0wOuEKlcZzFlQeS4PYHykFsz+43hYc0gJ9u4emr8HI="; }; - build-system = [ - setuptools - setuptools-scm - ]; + build-system = [ setuptools ]; dependencies = [ accelerate datasets + packaging rich transformers ]; @@ -46,8 +44,8 @@ buildPythonPackage rec { meta = { description = "Train transformer language models with reinforcement learning"; homepage = "https://github.com/huggingface/trl"; - changelog = "https://github.com/huggingface/trl/releases/tag/${src.tag}"; + changelog = "https://github.com/huggingface/trl/releases/tag/${finalAttrs.src.tag}"; license = lib.licenses.asl20; maintainers = with lib.maintainers; [ hoh ]; }; -} +}) From 4261ff373704e61d6730b9c5509141c8cbf007b8 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 3 Apr 2026 10:47:22 +0200 Subject: [PATCH 3/4] python3Packages.unsloth-zoo: 2026.3.4 -> 2026.4.2 https://pypi.org/project/unsloth-zoo/2026.4.2/ Update the declared runtime dependencies to match the new upstream metadata, narrow the relaxed dependency bounds to the ones still needed in nixpkgs, keep only the patch hunk that removes the hard runtime requirement on unsloth, correct the package license metadata to LGPL-3.0-or-later, disable the import check because importing unsloth_zoo now touches torch.cuda and queries device memory at import time, and add a GPU-only passthru smoke test for that import path. --- .../python-modules/unsloth-zoo/default.nix | 59 +++++++++++++++---- .../unsloth-zoo/dont-require-unsloth.patch | 14 ----- 2 files changed, 49 insertions(+), 24 deletions(-) diff --git a/pkgs/development/python-modules/unsloth-zoo/default.nix b/pkgs/development/python-modules/unsloth-zoo/default.nix index ef2be47691bf..810628911f66 100644 --- a/pkgs/development/python-modules/unsloth-zoo/default.nix +++ b/pkgs/development/python-modules/unsloth-zoo/default.nix @@ -11,30 +11,42 @@ accelerate, cut-cross-entropy, datasets, + filelock, hf-transfer, huggingface-hub, msgspec, + numpy, packaging, peft, + pillow, + protobuf, psutil, + regex, sentencepiece, torch, + torchao, + triton, tqdm, transformers, trl, tyro, + typing-extensions, + + # tests + cudaPackages, + python, }: buildPythonPackage (finalAttrs: { pname = "unsloth-zoo"; - version = "2026.3.4"; + version = "2026.4.2"; pyproject = true; # no tags on GitHub src = fetchPypi { pname = "unsloth_zoo"; inherit (finalAttrs) version; - hash = "sha256-24w8UV5cLG5XWrU73xfmg+Jk32zl+QSPdqXLzMtmP1E="; + hash = "sha256-l0OTaZjPrNnrxVYIfZcf6pYr1tJS9EGj+iguU6S+D28="; }; postPatch = '' @@ -47,14 +59,11 @@ buildPythonPackage (finalAttrs: { "setuptools-scm" ''; - # pyproject.toml requires an obsolete version of protobuf, - # but it is not used. - # Upstream issue: https://github.com/unslothai/unsloth-zoo/pull/68 + # Upstream constrains datasets/torch more tightly than the versions + # currently shipped in nixpkgs, but the package still builds and works with + # the newer dependency set here. pythonRelaxDeps = [ "datasets" - "protobuf" - "transformers" - "trl" "torch" ]; @@ -72,29 +81,59 @@ buildPythonPackage (finalAttrs: { accelerate cut-cross-entropy datasets + filelock hf-transfer huggingface-hub msgspec + numpy packaging peft + pillow + protobuf psutil + regex sentencepiece torch + torchao + triton tqdm transformers trl tyro + typing-extensions ]; # No tests doCheck = false; - pythonImportsCheck = [ "unsloth_zoo" ]; + # Importing touches torch.cuda at module import time and queries GPU memory. + dontUsePythonImportsCheck = true; + + # Cover the import path on GPU-enabled runners instead of pure builders. + passthru.gpuCheck = + (cudaPackages.writeGpuTestPython.override { python3Packages = python.pkgs; } + { + libraries = ps: [ ps.unsloth-zoo ]; + } + '' + import torch + + assert torch.cuda.is_available(), "CUDA is not available" + assert torch.ones(1, device="cuda").is_cuda + + import unsloth_zoo # noqa: F401 + from unsloth_zoo.device_type import DEVICE_COUNT, DEVICE_TYPE + + assert DEVICE_TYPE == "cuda", DEVICE_TYPE + assert DEVICE_COUNT > 0, DEVICE_COUNT + print(f"Unsloth Zoo detected {DEVICE_COUNT} CUDA device(s)") + '' + ).gpuCheck; meta = { description = "Utils for Unsloth"; homepage = "https://github.com/unslothai/unsloth_zoo"; - license = lib.licenses.mit; + license = lib.licenses.lgpl3Plus; maintainers = with lib.maintainers; [ hoh ]; }; }) diff --git a/pkgs/development/python-modules/unsloth-zoo/dont-require-unsloth.patch b/pkgs/development/python-modules/unsloth-zoo/dont-require-unsloth.patch index b5f7c9d8ddd7..7716354de65f 100644 --- a/pkgs/development/python-modules/unsloth-zoo/dont-require-unsloth.patch +++ b/pkgs/development/python-modules/unsloth-zoo/dont-require-unsloth.patch @@ -21,17 +21,3 @@ index 8c4404c..dc1666f 100644 try: print("🦥 Unsloth: Will patch your computer to enable 2x faster free finetuning.") except: -diff --git a/unsloth_zoo/device_type.py b/unsloth_zoo/device_type.py -index 11136fb..8f8dafc 100644 ---- a/unsloth_zoo/device_type.py -+++ b/unsloth_zoo/device_type.py -@@ -209,6 +209,9 @@ def get_device_type(): - return "cuda" - elif hasattr(torch, "xpu") and torch.xpu.is_available(): - return "xpu" -+ else: -+ # Allow import during tests -+ return None - # Check torch.accelerator - if hasattr(torch, "accelerator"): - if not torch.accelerator.is_available(): From df5ff49c7152782bc395f117583ef9f1a5904756 Mon Sep 17 00:00:00 2001 From: Hugo Herter Date: Fri, 3 Apr 2026 10:47:46 +0200 Subject: [PATCH 4/4] python3Packages.unsloth: 2026.3.8 -> 2026.4.1 https://github.com/unslothai/unsloth/releases/tag/2026.4.1 Propagate the hoh packaging cleanup that strips the AGPL-only CLI and Studio sources from the Apache-licensed Python package, remove the corresponding runtime-only dependencies, and add the cuda passthru alias expected by the top-level test. --- .../python-modules/unsloth/default.nix | 50 ++++++++++++++++--- 1 file changed, 44 insertions(+), 6 deletions(-) diff --git a/pkgs/development/python-modules/unsloth/default.nix b/pkgs/development/python-modules/unsloth/default.nix index 657f2bbf1a20..07447392d21f 100644 --- a/pkgs/development/python-modules/unsloth/default.nix +++ b/pkgs/development/python-modules/unsloth/default.nix @@ -11,6 +11,7 @@ bitsandbytes, numpy, packaging, + psutil, torch, unsloth-zoo, xformers, @@ -53,16 +54,40 @@ in buildPythonPackage (finalAttrs: { pname = "unsloth"; - version = "2026.3.8"; + version = "2026.4.1"; pyproject = true; # Tags on the GitHub repo don't match src = fetchPypi { pname = "unsloth"; inherit (finalAttrs) version; - hash = "sha256-2HXsaYhsMxNEm6ctKDZDrA9MY/fUKhAo0EPYC5RwBNc="; + hash = "sha256-RGpVxrcFzKbHxV7o0/OYaADo/Pqxx/c+FaxcV05gHGU="; }; + postPatch = '' + substituteInPlace pyproject.toml \ + --replace-fail 'requires = ["setuptools==80.9.0", "setuptools-scm==9.2.0"]' \ + 'requires = ["setuptools", "setuptools-scm"]' + + # Upstream's datasets guard says only 4.4.0 and 4.4.1 recurse, but the + # current check blocks the whole 4.4.0 .. 4.5.0 range. Narrow it to the + # versions the upstream comment actually calls out. + substituteInPlace unsloth/import_fixes.py \ + --replace-fail 'if (datasets_version <= Version("4.5.0")) and (' \ + 'if (datasets_version <= Version("4.4.1")) and (' + + # Strip AGPL-licensed CLI, Studio, and grouped-GEMM sources from the + # Apache-licensed Python package. + rm -rf \ + unsloth_cli \ + studio \ + unsloth/kernels/moe \ + COPYING + + # Drop the entry point after removing the CLI package above. + sed -i '/^\[project\.scripts\]/,/^$/d' pyproject.toml + ''; + build-system = [ setuptools setuptools-scm @@ -72,6 +97,7 @@ buildPythonPackage (finalAttrs: { bitsandbytes numpy packaging + psutil torch unsloth-zoo xformers @@ -90,8 +116,7 @@ buildPythonPackage (finalAttrs: { torchvision ]; - # pyproject.toml requires an obsolete version of protobuf, - # but it is not used. + # pyproject.toml pins obsolete versions for several runtime deps. # Upstream issue: https://github.com/unslothai/unsloth-zoo/pull/68 pythonRelaxDeps = [ "datasets" @@ -100,6 +125,17 @@ buildPythonPackage (finalAttrs: { "torch" ]; + # Upstream currently lists CLI/studio dependencies as runtime requirements, + # but they are not part of the packaged library here. + pythonRemoveDeps = [ + "tyro" + "wheel" + "typer" + "pydantic" + "pyyaml" + "nest-asyncio" + ]; + # The source repository contains no test doCheck = false; @@ -107,8 +143,8 @@ buildPythonPackage (finalAttrs: { # NotImplementedError: Unsloth: No NVIDIA GPU found? Unsloth currently only supports GPUs! dontUsePythonImportsCheck = true; - passthru.tests = { - qlora-train-and-merge = + passthru.tests = rec { + cuda = # FIXME: Replace python3.pkgs with python3Packages once possible, as to unbeak splicing. # Cf. https://github.com/NixOS/nixpkgs/pull/394838#issuecomment-3319287038 cudaPackages.writeGpuTestPython.override { python3Packages = python.pkgs; } @@ -135,6 +171,8 @@ buildPythonPackage (finalAttrs: { run_name="__main__" ) ''; + + qlora-train-and-merge = cuda; }; meta = {