Hi! I felt the need to open this topic after getting the following error while quickly making a new test project:
opening library failed (libX11.so: cannot open shared object file: No such file or directory)
I recently installed NixOS, and my workflow often requires making new GUI-based applications, among other arbitrary things that might require existing system libraries which I already have installed but not in my LD_LIBRARY_PATH as thatās against the Nix principles.
So my question is, whatās the best approach to allow me to easily make new projects without needing to add 2-4 files to my repo each time (flake.nix, direnv, the 2 other temp/lockfiles they both create)? Especially for simple projects that others will be looking at and working with too, I donāt want to pollute the repositories with extra configuration files that only I will ever use while others donāt even know what Nix is.
Like of course, hereās the most ācorrectā way of fixing my problem:
Apply that globally (without interfering with the other LD_LIBRARY_PATH paths already present)
Create easily re-usable shells that I can easily reference without adding them to my repository, and somehow making it work with vscode, preferably without needing to add a direnv still.
Overall, Iāve been loving the new workflows that NixOS has allowed me to make, e.g. for complex libraries such as custom LLVM builds, itās so easy to just describe it in a nix flake and include it in my environment. But for simple more ubiquitous libraries, itās a bit more of an issue. Would anyone have any suggestions on how to approach this?
I was under the assumption that environment variables must be strings, but I searched through nixpkgs and seems like some packages were using LD_LIBRARY_PATH as an array (e.g. opengl-driver), so I tried that and it worked.
My ideal goal here is to mix and match which parts of the Nix philosophy I want to use, and which parts of average linux shared environment stuff I want to use. Makes life a lot easier for me and other devs who look at my codebases.
But over time, Iāll try slowly integrating more nix shell stuff into my workflow, itās just a bit hard to transition everything (especially considering the gitignore stuff, which makes it a bit tedious). Hopefully Iāll find a way to automate that too.
Ironically, going full nix should make things easier for such, definitely for people who donāt contribute back. Even if they contribute, a nix shell (but not flake checks or such) will help them.
Traditional desktop use means missing dependencies because you have no idea whatās already lying around from other projects. Having a shell.nix canāt be worse than that, and any reader remotely willing to just read will get a clear indication of what youāre actually using - package names are parseable even if nix is completely unreadable to you.
Youād have to be deliberately dragging your feet for a nix shell to cause problems - if you encounter such people, you can appease them by copying the package list to your readme, bonus points for writing some script that matches repology against fedora package names or something.
If you insist on using flakes, the alternate flake uri that starts with path: as @NobbZ suggests makes it so you donāt need to commit your flake.nix (comes at a cost of copying everything to the nix store, though, so careful with uncommitted secrets and big VM files and such). You can also fall back to a traditional shell.nix, which does not need to be committed to work.
At that point you can add an ignore for it to your global git config. For projects in which you want whichever file you put your shell in, you can then explicitly git add it.
Right, thank you for the response, though I just want to double-check something because I feel like my understanding isnāt that great with shell.nix vs flake.nix. I jumped straight on flakes for my system config because that seemed to be āthe right future-proof thing to doā, and by extension, I assumed the same for dev shells. Also blog posts such as this one led me to believe flakes are the right way to go too.
if you encounter such people, you can appease them by copying the package list to your readme
I in my case, half the time āsuch peopleā are co-workers in private company repositories, usually ones that I donāt have ownership over myself, or I might have to hand ownership over to someone else at any time, hence me trying to minimize the āconfusingā configuration as people appear to be fairly opposed to adding repository ābloatā that theyāre not familiar with (it just works on their machine after all). And in most cases theyāre right, for basic apps with little system deps.
But yeah, assuming I do add a nix shell to my repository, do you recommend sticking to shell.nix unless required otherwise, even if everything else I use is flakes?
Yes, that requires more bravery than on your private stuff Personally I used the path: āhackā with direnv so I didnāt need to keep typing it out in those situations. And then mentally ignored the flake.nix, because adding it to global git ignores annoyed me for some reason.
Detsys are pushing flakes hard now, so maybe that will be resolved in the near future. But I was hoping for that two years ago, and as I see it flake stabilization is at least another two years outā¦
The main advantage is the input handling - channels are bloody confusing and trip up new users all the time. When you share your flakes, making sure others get exactly the same nixpkgs commits is useful, too.
Personally I use flakes because of that input handling and just accept the various annoyances.
If you donāt care for sharing your flake.nix though, I could see it argued that just learning how to pin your channels to your system flake inputs and using shell.nix is much more ergonomic.