Cannot get Flask CLI to see Python plugin without using nix-shell

I’ve got a simple case, I’ve created a derivation for flask-digest-static with Nix. Here is my attempt to provide it as a plugin to the flask cli. I can only get flask to see the plugin by using nix-shell first, and I do not understand why.

  1. Put this into test.nix and run nix-shell test.nix
{ pkgs ? import (fetchTarball https://github.com/nixos/nixpkgs/archive/release-21.11.tar.gz) {} }:
let
  flask-static-digest = pkgs.python39Packages.buildPythonPackage rec {
   pname = "Flask-Static-Digest";
   version = "0.2.1";
   buildInputs = [ pkgs.python39Packages.flask ];
   src = pkgs.python39Packages.fetchPypi {
     inherit pname version;
     sha256 = "sha256-dSiwiiwS3DqCgJa2buJhLzI9UL420B8oF7dn+7HOym4=";
   };
  };
in
{
  y = pkgs.python39Packages.flask.overrideAttrs (old: {
    propagatedBuildInputs = old.propagatedBuildInputs ++ [ flask-static-digest ];
  });
}
  1. nix-shell -p python39Packages.flask
  2. run flask --help
  3. Observe that digest is available in the help.

Full example

user: matthew swordfish in ~/tmp 
❯ cat test.nix 
{ pkgs ? import (fetchTarball https://github.com/nixos/nixpkgs/archive/release-21.11.tar.gz) {} }:
let
  flask-static-digest = pkgs.python39Packages.buildPythonPackage rec {
   pname = "Flask-Static-Digest";
   version = "0.2.1";
   buildInputs = [ pkgs.python39Packages.flask ];
   src = pkgs.python39Packages.fetchPypi {
     inherit pname version;
     sha256 = "sha256-dSiwiiwS3DqCgJa2buJhLzI9UL420B8oF7dn+7HOym4=";
   };
  };
in
{
  y = pkgs.python39Packages.flask.overrideAttrs (old: {
    propagatedBuildInputs = old.propagatedBuildInputs ++ [ flask-static-digest ];
  });
}

user: matthew swordfish in ~/tmp 
❯ nix build -f test.nix 

user: matthew swordfish in ~/tmp took 6s 
❯ ./result/bin/flask --help | grep digest
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.


user: matthew swordfish in ~/tmp 
❯ nix-shell test.nix 
Sourcing python-remove-tests-dir-hook
Sourcing python-catch-conflicts-hook.sh
Sourcing python-remove-bin-bytecode-hook.sh
Sourcing setuptools-build-hook
Using setuptoolsBuildPhase
Using setuptoolsShellHook
Sourcing pip-install-hook
Using pipInstallPhase
Sourcing python-imports-check-hook.sh
Using pythonImportsCheckPhase
Sourcing python-namespaces-hook
Sourcing setuptools-check-hook
Using setuptoolsCheckPhase
Sourcing pytest-check-hook
Using pytestCheckPhase
Removing setuptoolsCheckPhase
Executing setuptoolsShellHook
Finished executing setuptoolsShellHook

user: matthew swordfish in ~/tmp via ❄️  impure (python3.9-Flask-2.0.2) 
❯ ./result/bin/flask --help | grep digest
Error: Could not locate a Flask application. You did not provide the "FLASK_APP" environment variable, and a "wsgi.py" or "app.py" module was not found in the current directory.

  digest  md5 tag and gzip static files.

use overridePythonAttrs

This does not change the outcome. I get the same result whether I use overrideAttrs or overridePythonAttrs.

https://github.com/NixOS/nixpkgs/issues/72345

It turns out the cause of the problem was a lack of setuptools in the buildInputs for Flask in Nixpkgs. This PR fixes that:

https://github.com/NixOS/nixpkgs/pull/155245

Thanks to K900 for finding this.

2 Likes