Python with Protobuf flake error

I’m not super sure what’s happening here. I thought it’d be a good idea to get going quickly with flakes for a throwaway python project, so I pulled something from dev-templates and tweaked it.

I ended up with this:

{
  description = "A Nix-flake-based Python development environment";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/release-22.11";
    flake-utils.url = "github:numtide/flake-utils";
    mach-nix.url = "github:/DavHau/mach-nix";
  };

  outputs =
    { self
    , nixpkgs
    , flake-utils
    , mach-nix
    }:

    flake-utils.lib.eachDefaultSystem (system:
    let
      # overlays = [
      #   (self: super: {
      #     python = super.python311;
      #   })
      # ];

      # pkgs = import nixpkgs { inherit overlays system; };
      pkgs = import nixpkgs { inherit system; };
    in
    {
      devShells.default = pkgs.mkShell {
        packages = with pkgs; [ python311 virtualenv protobuf ] ++
          (with pkgs.python311Packages; [ pip protobuf ]);

        shellHook = ''
          ${pkgs.python}/bin/python --version
        '';
      };
    });
}

which throws a relatively weird error.

error: builder for '/nix/store/8v2nc3j1z6m1k3fzw51nn8sxlmxjp0h0-python3.11-pyext-0.8.drv' failed with exit code 1;
       last 10 log lines:
       > Executing setuptoolsBuildPhase
       > Traceback (most recent call last):
       >   File "/private/tmp/nix-build-python3.11-pyext-0.8.drv-0/source/nix_run_setup", line 8, in <module>
       >     exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\\r\\n', '\\n'), __file__, 'exec'))
       >   File "setup.py", line 6, in <module>
       >     import pyext
       >   File "/private/tmp/nix-build-python3.11-pyext-0.8.drv-0/source/pyext.py", line 118, in <module>
       >     oargspec = inspect.getargspec
       >                ^^^^^^^^^^^^^^^^^^
       > AttributeError: module 'inspect' has no attribute 'getargspec'. Did you mean: 'getargs'?
       For full logs, run 'nix log /nix/store/8v2nc3j1z6m1k3fzw51nn8sxlmxjp0h0-python3.11-pyext-0.8.drv'.
error: 1 dependencies of derivation '/nix/store/45hvqqc10rgqjyn716cpb23x3xf2qhq1-python3.11-protobuf-4.21.8.drv' failed to build
error: 1 dependencies of derivation '/nix/store/ixisv4p5j0yw8l9d8a372x7xg3gyic5q-nix-shell-env.drv' failed to build

Not sure how to even start debugging this.

Ticket for the same on Github: Tweaked Python file throws error · Issue #20 · the-nix-way/dev-templates · GitHub

What’s weird about it? Looks like a fairly normal Python error stack.

Seems to lead pretty directly to

Try sticking to 3.10.

It also looks like this problem led to pyext being removed from nixpkgs after the 22.11 branch-off:

If I’m reading those right, updating the flake to use a 23.05 nixpkgs input may also do the trick.

Why would installing packages using this particular package manager throw a python error? When installing python packages I rarely get python errors and those that I get are pretty obscure.

So I changed the line to read:

nixpkgs.url = "github:NixOS/nixpkgs/release-23.05";

Now I get an even weirder error:

error: Package ‘python-2.7.18.6’ in /nix/store/k6k1ydb9gpcznys4pybzifmy6wg7wfkl-source/pkgs/development/interpreters/python/cpython/2.7/default.nix:330 is marked as insecure, refusing to evaluate.


       Known issues:
        - Python 2.7 has reached its end of life after 2020-01-01. See https://www.python.org/doc/sunset-python-2/.

       You can install it anyway by allowing this package, using the
       following methods:

       a) To temporarily allow all insecure packages, you can use an environment
          variable for a single invocation of the nix tools:

            $ export NIXPKGS_ALLOW_INSECURE=1

        Note: For `nix shell`, `nix build`, `nix develop` or any other Nix 2.4+
        (Flake) command, `--impure` must be passed in order to read this
        environment variable.

       b) for `nixos-rebuild` you can add ‘python-2.7.18.6’ to
          `nixpkgs.config.permittedInsecurePackages` in the configuration.nix,
          like so:

            {
              nixpkgs.config.permittedInsecurePackages = [
                "python-2.7.18.6"
              ];
            }

       c) For `nix-env`, `nix-build`, `nix-shell` or any other Nix command you can add
          ‘python-2.7.18.6’ to `permittedInsecurePackages` in
          ~/.config/nixpkgs/config.nix, like so:

            {
              permittedInsecurePackages = [
                "python-2.7.18.6"
              ];
            }
(use '--show-trace' to show detailed location information)

I’m not sure how or why it is trying to install python2.7.

I got help. Wiping the overlay made ${pkgs.python}/bin/python --version refer to python2.7. Replacing python with python3 fixed it.