I work in a lot of repos which don’t use Nix, so I end up maintaining a local flake.nix for most of them which I don’t commit. This became a hassle juggling between branches and staged files when using git during development. Not to mention, many projects end up having flake.nix files which look almost identical. I love using nix-direnv, but it only works when a .envrc file is present and configured in a repo.
I made envoluntary so I could reduce the amount of packages installed in my system / user environment, but still have the packages I need for various projects. It integrates seamlessly with shells the same way direnv does, but is centrally configurable with a TOML file defining a regex pattern to match a flake.nix with directories:
[[entries]]
pattern = ".*/projects/my-website(/.*)?"
flake_reference = "~/nix-dev-shells/nodejs"
[[entries]]
pattern = ".*/projects/rust-.*"
flake_reference = "github:NixOS/templates/30a6f18?dir=rust"
The linked repo has instructions for how to run or install envoluntary if you want to try it out. I’m happy to accept any feedback or to review PRs if there’s a change someone wants to make!
This looks really cool! I maintain a few Nixpkgs packages where upstream doesn’t use Nix. This should make it easier to hack on those projects’ upstreams.
This is really cool! Is it possible to match based off files in the project? I dont typically name project folders based off the language used. For example, it would be useful to be able to use the rust env if a project has a Cargo.toml in it.
That’s an interesting idea! We could add an “adjacent file pattern”. It’d require searching up the directory hierarchy to work correctly though, but I don’t think that would be too slow. I’ll create a an issue to track this.
Edit: done, Add feature for "adjacent file patterns" · Issue #14 · dfrankland/envoluntary · GitHub
This seems like a nice project!
I’ve run into the same problem before, where I wasn’t allowed to include Nix files in my repo and had to juggle direnv and everything around, but for like 90% of the time I just edit .git/info/exclude (a repo-local .gitignore) to include the Nix and direnv files and move on with my day.
Still a cool project tho, I may end up using it someday :}
I’ve just merged and released the “adjacent pattern” feature
! Brilliant idea ![]()
Really nice project, would be useful for me too.
How it handles conflicts for two or more patterns matching the same location?
[[entries]]
pattern = ".*/projects/rust-.*"
flake_reference = "github:NixOS/templates/30a6f18?dir=rust"
[[entries]]
pattern = ".*/projects/.*-terraform"
flake_reference = "github:cachix/devenv?dir=templates/terraform"
and I’m in ~/projects/rust-terraform
Paths that match two or more flakes have their environment variables combined, last entry overrides. PATH and XDG_DATA_DIRS are merged however with the last entry prepending to this list of directories for both.
I just edit
.git/info/exclude(a repo-local .gitignore)
Nice, TIL! I do something similar, but with a global ignore on a folder named .private, which is where I place the flake.nix file (and other temporary stuff I may need).
Thanks @dfrankland for adding NixOS/HomeManager modules and install instructions.