TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Automate Project Environments with Devbox and Direnv (2023)

96 pointsby jljljl10 months ago

17 comments

arnorhs10 months ago
&gt; The problem with using Direnv is that despite it being a very useful tool, its setup requires investing time and getting over the Nix ecosystem&#x27;s learning curve.<p>I&#x27;m a bit confused. Direnv is rather simple, is it not.. ?<p>1. put env variables into .envrc 2. direnv allow<p>I don&#x27;t use nix and I don&#x27;t think I&#x27;m over its learning curve. I don&#x27;t remember investing any time into it..
评论 #40928105 未加载
评论 #40925632 未加载
评论 #40925308 未加载
评论 #40926715 未加载
srid10 months ago
Direnv is very useful for switching between projects, we have an article: <a href="https:&#x2F;&#x2F;nixos.asia&#x2F;en&#x2F;direnv" rel="nofollow">https:&#x2F;&#x2F;nixos.asia&#x2F;en&#x2F;direnv</a><p>But if you are comfortable with Nix you don&#x27;t need Devbox per se, as you can get by with using Flakes. Here are some examples -- just `git clone` and run `direnv allow` (once), then you are put in the corresponding devShell<p>Haskell: <a href="https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;haskell-template">https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;haskell-template</a><p>Rust: <a href="https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;rust-nix-template">https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;rust-nix-template</a><p>home-manager: <a href="https:&#x2F;&#x2F;github.com&#x2F;juspay&#x2F;nix-dev-home">https:&#x2F;&#x2F;github.com&#x2F;juspay&#x2F;nix-dev-home</a><p>Dioxus: <a href="https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;dioxus-desktop-template">https:&#x2F;&#x2F;github.com&#x2F;srid&#x2F;dioxus-desktop-template</a>
评论 #40927674 未加载
depingus10 months ago
I started messing around with Devbox a few weeks ago and I like it as a faster alternative to toolbox&#x2F;distrobox containers. I&#x27;ve been adding my environment variables directly into the devbox.json file as normal EXPORT statements. From the article tho, I couldn&#x27;t grasp what Direnv adds to this. Same Devbox shell, different environment variables per directory?
评论 #40927779 未加载
zamalek10 months ago
I try to contribute a lot, which has resulting in me adding .direnv and .envrc to my global gitignores (for other Nix+hm folks[1]). .direnv for obvious reasons, it&#x27;s a cache, and doesn&#x27;t frequently show up in project gitignores.<p>I add .envrc to not only avoid committing it to projects that don&#x27;t use it, but also because it turns out that it&#x27;s still pretty environment dependent. There&#x27;s 100 different ways to skin the dependency problem: Nix, pipenv, nvm, rustup, etc. There&#x27;s no telling which a contributor prefers to use, so .envrc doesn&#x27;t belong in git IMHO. What could be committed is something like .envrc-flake (which can then be sourced into .envrc).<p>As for needing a flake in the repo, I have found a workaround. `use flake` accepts parameters, including the path to the flake. I have a bunch of shells[2] that I can import with e.g. `use flake ~&#x2F;Nix#rust`.<p>[1]: <a href="https:&#x2F;&#x2F;codeberg.org&#x2F;jcdickinson&#x2F;nix&#x2F;src&#x2F;branch&#x2F;main&#x2F;home&#x2F;common&#x2F;git.nix#L44" rel="nofollow">https:&#x2F;&#x2F;codeberg.org&#x2F;jcdickinson&#x2F;nix&#x2F;src&#x2F;branch&#x2F;main&#x2F;home&#x2F;co...</a> [2]: <a href="https:&#x2F;&#x2F;codeberg.org&#x2F;jcdickinson&#x2F;nix&#x2F;src&#x2F;branch&#x2F;main&#x2F;flake.nix#L221" rel="nofollow">https:&#x2F;&#x2F;codeberg.org&#x2F;jcdickinson&#x2F;nix&#x2F;src&#x2F;branch&#x2F;main&#x2F;flake.n...</a>
aerzen10 months ago
This is the way. We should make it a standard practice for oss projects that one is able to git clone, direnv allow and build the project.<p>Regardless of the distro or even OS. An easy thing to say, but hard to execute on actual projects with patched versions of cPython and some obscure in-house build tool.
评论 #40926231 未加载
评论 #40926141 未加载
评论 #40927064 未加载
评论 #40925169 未加载
cquintana9210 months ago
Been using Devbox recently both at work and for personal projects and I can only say good things. It abstracts away the complexity of nix, defining the dependencies in a simple json with a lock file, the shell starts quite fast and from then on you have everything under your PATH, and it works the same in macOS and Linux.<p>Also, as a benefit, by tracking the JSON and lockfile, the CI can work with the exact same environment. I highly recommend giving it a try.
评论 #40926024 未加载
评论 #40932144 未加载
Mathnerd31410 months ago
&gt; despite it being a very useful tool, its setup requires investing time and getting over the Nix ecosystem&#x27;s learning curve.<p>They mention Nix but I guess they are referring to the use_nix integration built-in to direnv? There is a fairly detailed (but old) comparison in <a href="https:&#x2F;&#x2F;github.com&#x2F;direnv&#x2F;direnv&#x2F;wiki&#x2F;Nix#some-factors-to-consider">https:&#x2F;&#x2F;github.com&#x2F;direnv&#x2F;direnv&#x2F;wiki&#x2F;Nix#some-factors-to-co...</a> and in the meantime lorri and nix-direnv are the only ones still maintained. But you aren&#x27;t limited to Nix when using direnv, for example there is nvm. <a href="https:&#x2F;&#x2F;github.com&#x2F;direnv&#x2F;direnv&#x2F;wiki&#x2F;Node#using-nvm">https:&#x2F;&#x2F;github.com&#x2F;direnv&#x2F;direnv&#x2F;wiki&#x2F;Node#using-nvm</a><p>Actually, the post&#x27;s solution, besides being built on top of direnv, uses Devbox, which itself is built on top of Nix... <a href="https:&#x2F;&#x2F;www.jetify.com&#x2F;devbox&#x2F;docs&#x2F;faq&#x2F;#how-does-devbox-work" rel="nofollow">https:&#x2F;&#x2F;www.jetify.com&#x2F;devbox&#x2F;docs&#x2F;faq&#x2F;#how-does-devbox-work</a> So they are saying they are outside the Nix ecosystem when in fact they are in it. It is yet another set of nice scripts on top of Nix.
评论 #40924724 未加载
评论 #40924584 未加载
undecisive10 months ago
My experience of Devbox on Linux has been highly disappointing. I gave it a good go, had it running on my main project from February to May.<p>In case you hadn&#x27;t realised, the very concept of having two sets of binary distributions on one machine, vying for superiority and the correct version of glibc... is fraught.<p>Most of my use was with rails projects, and I can&#x27;t recommend it.<p>Coupled with an abstraction that tries to save you from Nix, but almost entirely fails, you end up with a bloated hellscape where every time you load your project it will unnecessarily reinstall your packages and several times an hour it will have forgotten curl exists and so you have to manually reinstall curl (not-so-slowly increasing your &#x2F;nix folder&#x27;s size), every week or two a new version of devbox completely changes the workarounds you need to do, and don&#x27;t try to garbage collect nix or it will delete vital files, and you end up scrubbing it all and starting again.<p>In python, it overrode the path so I couldn&#x27;t get it to reliably use the binaries in the venv. Pip and Python were using packages in different places and I couldn&#x27;t get them to converge for love nor money.<p>The devbox team were great and really tried to get things working, but in the end I couldn&#x27;t get it to work with enough stability to properly recommend it to my team, and if I wanted it to half-work for any substantial length of time I had to lock to a version of devbox.<p>Obviously, ymmv, please do give it a try, it&#x27;s an impressive project. But my view is that it&#x27;s trying to do something that is very very hard, and for that you need a very clever solution. And this is a very clever solution, with very clever bugs, and so it&#x27;s not something I&#x27;d recommend jumping into with both feet.
评论 #40924937 未加载
评论 #40927477 未加载
weitzj10 months ago
Great project which you can also use as your package manager on your system. This works nice if your developers have a MacBook with an Arm processor and want to have the build process close to what you do in your ci server which might be a Linux amd64
queil10 months ago
I wrote myself a small tool for dev workspaces in containers: <a href="https:&#x2F;&#x2F;github.com&#x2F;queil&#x2F;rooz">https:&#x2F;&#x2F;github.com&#x2F;queil&#x2F;rooz</a> - still WIP but I&#x27;ve been using it for quite a while
jbverschoor10 months ago
I created container-shell with a similar goal in mind. It’s super light weight, but does not yet support a package manager. It simply gives you a shell using a specified docker image inside the current directory, isolating both software installs as well as the rest of your filesystem<p><a href="https:&#x2F;&#x2F;github.com&#x2F;jrz&#x2F;container-shell">https:&#x2F;&#x2F;github.com&#x2F;jrz&#x2F;container-shell</a>
h1fra10 months ago
I think this is my biggest pet peeves when working on different projects. Plus port allocation conflict; if you have multiple docker databases or multiple project using the same default port it&#x27;s not smooth and obviously changing port is not always an option on legacy projects :&#x2F;
azaras10 months ago
Why do not use asdf?
评论 #40924543 未加载
评论 #40924348 未加载
Iridescent_10 months ago
It looks quite smaller in scope than devenv (<a href="https:&#x2F;&#x2F;devenv.sh&#x2F;" rel="nofollow">https:&#x2F;&#x2F;devenv.sh&#x2F;</a>)
评论 #40926194 未加载
crabbone10 months ago
This looks like a huge overkill to solve the problem that&#x27;s while real, isn&#x27;t really so difficult to solve with existing tools... Kind of reminds me of Jucero.<p>Also, any solution of this kind will inevitably introduce a number of new problems proportionate to the internal complexity of such solution. I.e. this is just asking for a lot of problems, while offering very little in return.
julius-fx10 months ago
Devbox is really interesting stuff, gonna try it out soon. Thank you!
minhdanh7210 months ago
This is so cool. Thanks!