Skip to content

Python 3.10 fails to apply python-3.x-distutils-C++.patch #115

@allonhadaya-maven

Description

@allonhadaya-maven

Describe the bug

Using devenv 1.8.2 (aarch64-darwin) I am able to build the following minimal Python 3.10 shell without error:

$ devenv shell
• Added input 'nixpkgs-python':
    'github:cachix/nixpkgs-python/188ffc273f679a2d95a1c8aba0be083545417bdd' (2026-03-03)
• Added input 'nixpkgs-python/flake-compat':
    'github:edolstra/flake-compat/5edf11c44bc78a0d334f6334cdaf7d60d732daab' (2025-12-29)
• Added input 'nixpkgs-python/nixpkgs':
    follows 'nixpkgs'
• Using Cachix caches: nixpkgs-python, devenv
✓ Building shell in 456s
✨ devenv 1.8.2 is out of date. Please update to 2.0.4: https://devenv.sh/getting-started/#installation
$ python3 --version
Python 3.10.20
$ which python3
/nix/store/xjlknfhl0aig8g3m55y4anvvn9ar4i8r-python3-3.10.20-env/bin/python3

Using a recent rev from main devenv 2.0.5+7cd1a09 (aarch64-darwin), I encounter the following error building the shell:

    ✗ error: Cannot build '/nix/store/631qixg0k9kw3a5l0qmgrrm336d63nx9-python3-3.10.20.drv'.
    ✗ error: Cannot build '/nix/store/d00b7dm95ab4q61sqhw4gqb512c4y3x6-python3-3.10.20-env.drv'.
    ✗ error: Build failed due to failed dependency
    ✗ error: Cannot build '/nix/store/3jzxarill8v5mixjbji84zi9k1qfhrhs-devenv-profile.drv'.
    ✗ error: Cannot build '/nix/store/ygwam62hrmh2mqjzclllbhl9hzalib0w-devenv-shell.drv'.

error: Cannot build '/nix/store/d00b7dm95ab4q61sqhw4gqb512c4y3x6-python3-3.10.20-env.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/31h9ywaz3nkbrbbpydkmvah95bznj7xd-python3-3.10.20-env
error: Cannot build '/nix/store/3jzxarill8v5mixjbji84zi9k1qfhrhs-devenv-profile.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/xihqnwjv3qrs3y2gb6r1k1xlr3k4vhql-devenv-profile
error: Cannot build '/nix/store/631qixg0k9kw3a5l0qmgrrm336d63nx9-python3-3.10.20.drv'.
       Reason: builder failed with exit code 1.
       Output paths:
         /nix/store/70b7qbdm9kh3ahl86b2s8g3wpjprlzy5-python3-3.10.20
       Last 25 log lines:
       > applying patch /nix/store/n97jb2skcqcwh9dyxlgjf2pidsc74f77-3.10-no-ldconfig.patch
       > patching file Lib/ctypes/util.py
       > applying patch /nix/store/r112dk8w7zvdjipki58ch00m825li7fq-virtualenv-permissions.patch
       > patching file Lib/venv/__init__.py
       > Hunk cachix/devenv#1 succeeded at 451 with fuzz 2 (offset 72 lines).
       > applying patch /nix/store/lpfs02z2i2hamz9f50p4bz6v0fs0600j-mimetypes.patch
       > patching file Lib/mimetypes.py
       > Hunk cachix/devenv#1 succeeded at 46 (offset 6 lines).
       > applying patch /nix/store/9kwzs3pplms8sijf55sdryypzvic4x1s-python-3.x-distutils-C++.patch
       > patching file Lib/_osx_support.py
       > patching file Lib/distutils/cygwinccompiler.py
       > Hunk cachix/devenv#1 succeeded at 123 (offset -2 lines).
       > Hunk cachix/devenv#2 succeeded at 140 (offset -2 lines).
       > Hunk cachix/devenv#3 succeeded at 170 (offset -2 lines).
       > Hunk cachix/devenv#4 succeeded at 310 (offset -2 lines).
       > patching file Lib/distutils/sysconfig.py
       > Hunk cachix/devenv#1 FAILED at 170.
       > Hunk cachix/devenv#2 FAILED at 187.
       > Hunk cachix/devenv#3 succeeded at 254 (offset 46 lines).
       > 2 out of 3 hunks FAILED -- saving rejects to file Lib/distutils/sysconfig.py.rej
       > patching file Lib/distutils/unixccompiler.py
       > Hunk cachix/devenv#3 FAILED at 183.
       > 1 out of 3 hunks FAILED -- saving rejects to file Lib/distutils/unixccompiler.py.rej
       > patching file Makefile.pre.in
       > Hunk cachix/devenv#1 succeeded at 626 (offset 42 lines).
       For full logs, run:
         nix log /nix/store/631qixg0k9kw3a5l0qmgrrm336d63nx9-python3-3.10.20.drv
error: Build failed due to failed dependency
error: Cannot build '/nix/store/ygwam62hrmh2mqjzclllbhl9hzalib0w-devenv-shell.drv'.
       Reason: 1 dependency failed.
       Output paths:
         /nix/store/c32pgv99v7fmv8l07nr2yr0dhlnsd1xs-devenv-shell

Looking at the various spots in nixpkgs-python/flake.nix where we replacePatch or filterOutPatch on python-3.x-distutils-C++.patch, I don't see any conditions that should match the 3.10.20 version:

{
  condition = version: versionInBetween version "3.7.3" "3.7.1";
  override = replacePatch "python-3.x-distutils-C++.patch" ...;
}
{
  condition = version: versionInBetween version "3.7.4" "3.7.3";
  override = replacePatch "python-3.x-distutils-C++.patch" ./patches/python-3.7.3-distutils-C++.patch;
}
{
  condition =
    version: versionInBetween version "3.7.2" "3.7" || versionInBetween version "3.6.8" "3.6.6";
  override = replacePatch "python-3.x-distutils-C++.patch" ...;
}
{
  condition = version: versionInBetween version "3.6.6" "3.4";
  override = replacePatch "python-3.x-distutils-C++.patch" ...;
}
# no C++ patch for 3.3
{
  condition = version: versionInBetween version "3.4" "3.0";
  override = filterOutPatch "python-3.x-distutils-C++.patch";
}

Presumably we're attempting to apply this patch defined upstream in nixpkgs from the else branch:

  ++ optionals (hasDistutilsCxxPatch && pythonOlder "3.12") [
    # Fix for http://bugs.python.org/issue1222585
    # Upstream distutils is calling C compiler to compile C++ code, which
    # only works for GCC and Apple Clang. This makes distutils to call C++
    # compiler when needed.
    (
      if pythonAtLeast "3.11" then
        ./3.11/python-3.x-distutils-C++.patch
      else
        fetchpatch {
          url = "https://bugs.python.org/file48016/python-3.x-distutils-C++.patch";
          sha256 = "1h18lnpx539h5lfxyk379dxwr8m2raigcjixkf133l4xy3f4bzi2";
        }
    )
  ]

To reproduce

devenv.nix:

{
  languages.python = {
    enable = true;
    version = "3.10";
  };
}

devenv.yaml:

inputs:
  nixpkgs-python:
    url: github:cachix/nixpkgs-python
    inputs:
      nixpkgs:
        follows: nixpkgs
devenv.lock:
{
  "nodes": {
    "devenv": {
      "locked": {
        "dir": "src/modules",
        "lastModified": 1773714831,
        "narHash": "sha256-qUJ59Zj+M3OomXnPVx/R+AtloTuzH2zZBsK1vrVo9SA=",
        "owner": "cachix",
        "repo": "devenv",
        "rev": "6e82f48e9ae25c7a2560fce5324d873d8944a008",
        "type": "github"
      },
      "original": {
        "dir": "src/modules",
        "owner": "cachix",
        "repo": "devenv",
        "type": "github"
      }
    },
    "flake-compat": {
      "flake": false,
      "locked": {
        "lastModified": 1747046372,
        "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=",
        "owner": "edolstra",
        "repo": "flake-compat",
        "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885",
        "type": "github"
      },
      "original": {
        "owner": "edolstra",
        "repo": "flake-compat",
        "type": "github"
      }
    },
    "nixpkgs": {
      "inputs": {
        "nixpkgs-src": "nixpkgs-src"
      },
      "locked": {
        "lastModified": 1773704619,
        "narHash": "sha256-LKtmit8Sr81z8+N2vpIaN/fyiQJ8f7XJ6tMSKyDVQ9s=",
        "owner": "cachix",
        "repo": "devenv-nixpkgs",
        "rev": "906534d75b0e2fe74a719559dfb1ad3563485f43",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "ref": "rolling",
        "repo": "devenv-nixpkgs",
        "type": "github"
      }
    },
    "nixpkgs-python": {
      "inputs": {
        "flake-compat": "flake-compat",
        "nixpkgs": [
          "nixpkgs"
        ]
      },
      "locked": {
        "lastModified": 1772559541,
        "narHash": "sha256-1cWCYOnOz3K7FchI9IbIbu1qhi68mSNZSuYlE5jEv1I=",
        "owner": "cachix",
        "repo": "nixpkgs-python",
        "rev": "188ffc273f679a2d95a1c8aba0be083545417bdd",
        "type": "github"
      },
      "original": {
        "owner": "cachix",
        "repo": "nixpkgs-python",
        "type": "github"
      }
    },
    "nixpkgs-src": {
      "flake": false,
      "locked": {
        "lastModified": 1773597492,
        "narHash": "sha256-hQ284SkIeNaeyud+LS0WVLX+WL2rxcVZLFEaK0e03zg=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "a07d4ce6bee67d7c838a8a5796e75dff9caa21ef",
        "type": "github"
      },
      "original": {
        "owner": "NixOS",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "devenv": "devenv",
        "nixpkgs": "nixpkgs",
        "nixpkgs-python": "nixpkgs-python"
      }
    }
  },
  "root": "root",
  "version": 7
}

Version

devenv 2.0.5+7cd1a09 (aarch64-darwin)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions