Flake and Python and PyYAML==3.13

I always struggle to run python on my NixOS machine and today is no exception :sob: Would one of you kind folk please tell me what I’m doing wrong here!?

I think this flake.nix file should work:

{
  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";

    mach-nix = {
      url = "mach-nix/3.5.0";
      inputs.nixpkgs.follows = "nixpkgs";
      inputs.flake-utils.follows = "flake-utils";
    };
  };

  outputs = { self, nixpkgs, flake-utils, mach-nix }:
    flake-utils.lib.eachDefaultSystem (system:
      let
        pkgs = import nixpkgs { inherit system; };
        mach = import mach-nix {
          inherit pkgs;
          python = "python39";
        };

        requirements = ''
          coloredlogs==7.3
          python-jenkins==0.4.16
          PyYAML==3.13
          requests==2.20.0
          tqdm==4.28
        '';

        python = mach.mkPython {
          inherit requirements;
        };
      in rec {
        defaultPackage = mach.buildPythonPackage {
          inherit requirements;
          src = ./.;
        };

        devShell = pkgs.mkShell {
          buildInputs = [
            python
          ];
        };
      });
}

It fails to build python3.9-pyyaml-3.13, the only errors that I can find apear to be logic errors in the code:

ext/_yaml.c: In function ‘__Pyx_modinit_type_init_code’:
ext/_yaml.c:25698:25: error: ‘PyTypeObject’ {aka ‘struct _typeobject’} has no member named ‘tp_print’
25698 |   __pyx_type_5_yaml_Mark.tp_print = 0;
      |                         ^
ext/_yaml.c:25718:28: error: ‘PyTypeObject’ {aka ‘struct _typeobject’} has no member named ‘tp_print’
25718 |   __pyx_type_5_yaml_CParser.tp_print = 0;
      |                            ^
ext/_yaml.c:25732:29: error: ‘PyTypeObject’ {aka ‘struct _typeobject’} has no member named ‘tp_print’
25732 |   __pyx_type_5_yaml_CEmitter.tp_print = 0;
      |                             ^

(Line 25,698… WTF!) The full log is below here: nix log /nix/store/g6ifi449xh98f5n5jbgp37f7889w2s7y-python3.9-pyyaml-3.13.drv

For the full picture I am trying to run the script in this repo: Librem5 / librem5-flash-image · GitLab.

I’m really hoping there’s something dumb that I’m missing and someone smarter with more experience can spot it right away :crossed_fingers:

That’s part of the python C api, pyyaml seems to be compiling against it. My guess is that you need to either update pyyaml to a more recent version that supports python39 or downgrade python to an older version that still has those bits of API.

Sadly, this is a facet of trying to do reproducible python packaging on any distro. It can be really hard to match compatible python version + a set of compatible dependencies, especially recently.

Edit: Oh yeah, duh, that version of pyyaml is half a decade old. No wonder it’s not compiling against the modern python C API.