Flakes: why do I consistently see warnings about the git tree being dirty?

Curious flakes user here.

I am using flakes to power my continuous integration and bulletproof developer environments.
These projects are Git repositories and I run nix develop or nix shell in them.

I consistently see a message of “warning: Git tree ‘/some/path’ is dirty”.
From what I remember, git status shows a clean working directory.

As a nix flakes user, do you see this consistently?

Do you know why this message occurs? I’m confused since git status tells me otherwise.

4 Likes

I consistently see a message of “warning: Git tree ‘/some/path’ is dirty”.
From what I remember, git status shows a clean working directory.

As a nix flakes user, do you see this consistently?

I only see this message when the git tree is in fact dirty. Looks like a
bug to me. Would you mind putting together a reproducible example and an
issue on the github:nixos/nix repository?

1 Like

Great idea! I will give this a shot.

Maybe you’re running into one of the issues I am trying to address with this PR:
https://github.com/NixOS/nix/pull/5758

I still need to look into the remaining locale-related issue there.

1 Like

Perfect! That is the issue I see.
It happens consistently on GitLab CI repositories I clone to a custom location.

I can test any patches that are landed too.

self.rev not working in GitLab CI is why I was looking into this issue.

For now I do something like this in my .gitlab-ci.yml script:

# build nix from that PR with my workaround applied
- nix build --out-link nix "github:mschwaig/nix?rev=bc66c8316648a30b1e08e93d01a09f52333adcf4
# use that nix to run whatever command
- ./nix/bin/nix build  

If you want you can check if this fixes your issue as well - as long as your locale in git is English.

2 Likes

I usually set warn-dirty = false in my nix config. It seems like your underlying issue is different, but at least it’d hide that message.

4 Likes

Thanks for the tips folks! I’ll likely configure nix to ignore the warning for now.

I’m linking the nix bug / task for visibility:

In case someone wonders where to apply this exactly:

3 Likes

Another workaround (while the issue gets fixed) is to run:

nix build .\?rev=$(git rev-parse HEAD)

Source: Nix flakes always thinks worktree is dirty in github actions pull request builds · Issue #5302 · NixOS/nix · GitHub

2 Likes