Caching Problems with Python App

I want to use buildPythonApplication to build a python program using a nix flake. I’m using setup.py for the packaging, and the python code is in its own directory, so the directory structure is:

├── fetch_links
│   ├── fetch_links.py
│   └── __init__.py
├── flake.lock
├── flake.nix
├── setup.py

Unfortunately due to nix’s caching, changes to the python code don’t cause nix to rebuild the program, presumably because the hash of the src directory doesn’t change.

{
  description = "A Python program.";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs";

  outputs = { self, nixpkgs }:
    let
      pkgs = import nixpkgs { system = "x86_64-linux"; };
    in
    {
      packages.x86_64-linux.default = pkgs.python3Packages.buildPythonApplication {
        pname = "fetch_links";
        version = "1.0.0";

        src = builtins.path {
          path = ./.;
        };

        # Dependencies
        propagatedBuildInputs = with pkgs.python3Packages; [
          requests
          beautifulsoup4
        ];

        pythonImportsCheck = [ "fetch_links" ];

        # Metadata
        meta = with pkgs.lib; {
          description = "A Python program.";
          license = licenses.mit;
          maintainers = [ maintainers.your-name ];
        };
      };

      # App to run the program directly
      apps.default = {
        type = "app";
        program = "${self.packages.default}/bin/fetch-links";
      };
    };
}

Is there a way to force nix build to not cache src? I have tried nix build . --rebuild, but unsuccessfully.

That doesn’t make sense, changing the source code would change the NAR hash. As long as the src contains the relevant python code.

Is it fresh files that were never added to git with git add? One of the oddities of nix flakes is that it only tracks files that were added to git.

Thanks for clarifying. The src hash in the derivation does change, but that still doesn’t change the built program for some reason.

What made me think that the src hash only changes when there are changes in the parent src directory itself and not in any subdirectory of src, was because I created a virtual environment in the parent src directory and then ran pip install ., which adds some files to src. This does cause the program that is built by nix to be updated for some incredibly weird reason.

So if I change the python code in src/fetch_links/fetch_links.py and then run nix build ., the changes aren’t reflected in the nix build. But when I run pip install . before nix build . then the nix build does include the changes. ???

This is my setup.py file. Not sure if there’s anything wrong here (really not that familiar with python packaging):

from setuptools import setup, find_packages

setup(
    name="fetch_links",
    version="1.0.0",
    packages=["fetch_links"],
    install_requires=["requests", "beautifulsoup4"],
    entry_points={"console_scripts": ["fetch-links=fetch_links.fetch_links:main"]},
    description="Description",
    author="Your Name",
    author_email="your_email@example.com",
    license="MIT",
    python_requires=">=3.6",
)