Can I use flakes within a git repo without committing flake.nix?

Here’s a neat workaround:

  • Tell git to track flake.nix but without adding it:
    git add --intent-to-add flake.nix
    
  • Tell git to assume that flake.nix doesn’t have any changes:
    git update-index --assume-unchanged flake.nix
    

This way you end up with a clean git status, but flake.nix still being tracked by git and therefore accessible to Nix. The only restriction is that you can’t do git operations which would modify/remove the flake.nix

This sounds perfect for a local workaround

46 Likes