Couldn’t find an official definition in official git documentation resources, but there were 2 mentions1 that seem to be consistent with Nix’s usage:
A git repo is dirty if there are modified tracked files and/or staged changes, but untracked content doesn’t count. Or, to put in another, a repo is clean if the output of git diff-index HEAD2 is empty.
That’s exactly what it means in nix, as you mention
Specifically, that warning pops up when you build a flake (and probably perform certain other operations on them, like nix flake check), if that flake is a git repository and git considers it “dirty” (i.e., modified, except for files that git has not yet been told to track with git add).
The warning is probably there because nix is supposed to make sure that it builds exactly the state of the flake’s git repository - in pursuit of reproducibility it was decided that nix should add flakes to the store before building them, exactly as if someone was cloning your repository, so that you don’t get surprised by missing files down the line.
It would be really annoying if you had to make a commit for every tiny change though, so nix will build dirty repositores for you anyway (but un-tracked files will be missing).
The warning makes sure that you know your repository currently isn’t as reproducible as nix would like, despite its best efforts.
For completeness sake, I stumbled upon it while playing with builtins.fetchGit to see what happens fetching local repos of varying internal states, and when the repo was “dirty”, the builtin’s behaviour would change:
The currently checked-out branch in the my-project repo is feature, with only a couple untracked files, but in otherwise pristine state, and the command below indeed retrieves the snapshot at the HEAD of feature: