Project environments (flox.nix) without flox init

I was eager to try flox environments for developers | flox:docs as soon as I read the release notes flox/rl-0.1.2.md at main · flox/flox · GitHub.

I wanted to take this as an opportunity to try to replace the .envrc + default.nix setup for an existing project. I then guessed I would only need a flox.nix file in the top level of the project. I tried that but a flox activate activated the default flox environment instead (i.e. it was not respecting the flox.nix file). I then looked at what flox init ... does and saw that it also writes a flake.nix file. I then manually created a basic flake.nix file next to the flox.nix file and tried flox activate, but again the default environment is activated instead, not the project environment.

When I use flox init ... then a flox activate does activate the project environment. So as in subject: How to create project environment definition files without flox init ... (having the .envrc + default.nix combo in mind)? Am I missing something in the docs or is flox init ... the only supported way at the moment?

Hey @fleimgruber ,

We could do better with documentation here, thanks for flagging this. flox init is the only way to set up the flox.nix automatically at the moment. This will create the flake.nix and flox.nix files. You could then port whatever you had in the .envrc and default.nix there declaratively (manually) or just run flox install PACKAGE and the package will be reflected in your flox.nix.

Hope this helps. We’ll update the docs with more detail. Thanks!

Hi @jurraca,

thanks for checking back. I was just wondering if flox init did something else (e.g. registering the local environment in it’s config somewhere else) apart from creating flox.nix and flake.nix as it did not work when I created those two files manually - with the exact same contents as resulting from a flox init done in a different dir.

I see, yes it does create one more directory locally called .flox/ for the environment. This directory contains symlinks to environment files in the nix store and a shell path setup file. You wouldn’t be able to declare this, and flox init takes care of that. Feel free to check out the .flox/ directory to see what’s created there.

Let me know if I can clarify anything else!

Oh, thanks, now I see the .flox/ directory in the test env dir. In my .envrc + default.nix dir after flox init --template project only the flox.nix file was created (no flake.nix and no .flox/). flox activate still only activates the default env. FWIW, my project dir is an existing git clone. But for me it’s not a real issue, was just curious. Will try again with a newer version.