Setting up a new project with nix use niv or flakes?

I am planning on making a game with godot 4 beta and i also plan on contributing to godot development.
I need to setup 3 development environments, one for developing godot, one for my gdextension library and one for my game, i want to setup my environments with nix.
I haven’t used nix much before so i am unfamiliar with the different alternatives.

I would like to know the strengths and weaknesses of using niv or flakes, so that i can choose the option which matches my requirements the best.

each development environment would have some dependencies but they also would depend on each other and the one for my gdextension library would also depend on the latest godot-cpp.
i would like to be able to switch between each project independently but my gextension library would depend on godot and my game would depend on my gdextension library.

besides that i haven’t started developing my game or my gdextension library, what should i use as a build system for my gdextension library? can nix build a c++ project without a build tool like cmake, scons ,bazel etc?

if the question is just “should I use niv or flakes?”, then the answer is “flakes”

Regarding the compilation, nix can basically build anything as soon as you can tell it the command to run to compile the software ^^ (to be honest if you use build tools that need to connect to internet at build time or download and run unpatched libraries, you need to disable sandbox and/or find a better alternative… but for c++ usually it’s not an issue)

You can also search derivations that package godot games to see how they proceed. For instance I can find oh-my-git that is a game based on godot nixpkgs/default.nix at d0c935df26d69847ddca8f5feda9752a6ae29e52 · NixOS/nixpkgs · GitHub that

I would not say it is that clear cut. Flakes are still experimental and the API can change. Personally, I am willing to update my projects when that happens but not everyone can do that. Choosing one way or another should depend on developer’s tollerance for project definition moving below their feet.

Also while flakes have some very nice features like pure builds by default, using them in a repo with a large asset files (like many games have) will be annoying until Copy local flakes to the store lazily · Issue #3121 · NixOS/nix · GitHub is fixed.

Niv may not be as hot as flakes but it is stable. Additionally, it is conceptually still a classic Nix so one does not need to learn another concept. And then keep up with its updates.


well, except niv. Also its development is pretty slow nowdays and several features are missing compared to flakes like following one input throughout your flakes or easily overriding an input with a local checkout.

I only used niv after already starting with flakes becuase some legacy projects at work were using it. My impression, since I didn’t use it too extensively, was that it was very much the old way of doing things, and flakes sort of make niv superflous. That said, @jtojnar’s comments about large asset files being copied to the store is legitimate for the time being, until the lazy-trees branch is merged at least.

And while it is true the API may change, I’d say that is fairly unlikely just because it has been mentioned that stabilization is coming soon, and even from the very beginning the flake API barely changed at all. Even the RFC to stabalize flakes mentions that it would be impractical to change the API at this point.