Collision between two seemingly identical tensorboard packages

In home manager I have Python set up as so:

pythonEnv = pkgs.python311.withPackages (ps: with ps; [
        numpy
        scikit-learn
        jupyter
        matplotlib
        pooch
        opencv4
        ffmpeg-python
        pygobject3
        keras
        pygame
        scikit-image
        trimesh
        notebook
        beautifulsoup4
        lxml
        requests
        termcolor
        flask
        pynput
        pyautogui
        keyboard
    ] ++ (if use-cuda then [tensorflowWithCuda torchWithCuda] else [tensorflow torch]));

which is later used in home.packages.

This results in a collision between:

/nix/store/cqmyr60p55x8sf1iknd1hhisi2vq6djr-python3.11-tensorboard-2.18.0/lib/python3.11/site-packages/tensorboard/data/proto/__pycache__/data_provider_pb2_grpc.cpython-311.pyc
/nix/store/19lp6vrvr3p1lsjx6674q8z0yhxdmvpz-python3.11-tensorboard-2.18.0/lib/python3.11/site-packages/tensorboard/data/proto/__pycache__/data_provider_pb2_grpc.cpython-311.pyc

Does anyone have any ideas why this might be happening?

Don’t put it in home.packages. Use dev shells, that’s what they’re designed for.
https://nix.dev/tutorials/first-steps/declarative-shell#declarative-reproducible-envs

You also have multiple versions of tensorflow here, likely one of which is coming from your explicit list and one that’s a dependency of something else (though I don’t know offhand which package depends on tensorflow, you’d have to use nix why-depends or nix-tree to dig into that).

Given how long tensorflow-gpu takes to compile (and how long other libraries take to download), I don’t want to put it into a dev shell where, as far as I am aware, it will be wiped when nix garbage collection is run.

You can create a GC root (or use nix-direnv which creates the GC root for you). Of course, you will get a rebuild if it or one of its dependencies are updated, but you’d have to take that time even now when you rebuild your config.