13 ms·
Fast, Declarative, Reproduble and Composable Developer Environments Using Nix
- RcouF1uZ4gsC 2y agoOne of my favorite things about Rust is that it uses the file system as the basis for a fast, reproducible, and composable developer environment. I can unzip a directory, cd into it and cargo build it and for the most part it just works. The fact that we have added shared libraries and environmental variables and so many other magic incantations that we need massively complicated second systems is an indictment of our culture of complexity. I believe Go also embraces that level of simplicity. And when it comes to deployment, instead of needing a simulation of a whole operating system (containers), I can just remote copy a directory and just have it work.
- anotherhue 2y agoAssuming that you're happy with whatever cargo is available on that machine, and that that version won't change?
- School-Cotton 2y agoLots of rust software has dependencies on non-rust software and build scripts that need various things to be in the path or in other environment variables. For example, anything using bindgen needs libclang, and to make matters worse, doesn't look in the conventional LIBRARY_PATH but requires a special environment variable LIBCLANG_PATH.
- ceving 2y agoThere was a time where shared libraries were necessary, because otherwise the programs would not fit into memory.
- JonChesterfield 2y agoThere may still be arguments around shared cache between programs though the security inspired rearranging things might thwart that. I like static binaries a lot. Whole load of failure modes just gone. Building a clang that targets musl by default on glibc systems is loosely practical these days. That builds self contained binaries that only depend on syscall. (It took me a few days, a lot of cursing at cmakes ideas about cross compilation and patching trunk slightly, but it can be done and enough of the patches stuck.)
- JustLurking2022 2y agoYou appear to misunderstand containers.
- duped 2y agoNow cross compile something that has a dependency on a system library
- JustLurking2022 2y agoDownvote though you may, you misunderstand containers - they are not simulating a whole operating system (that would be a VM), they are using features built into Linux to isolate tasks running on the same OS kernel to be isolated from each other.
- yewenjie 2y agoI gave devenv multiple tries, and I am sorry to say there are multiple annoying issues that forced me to give up every time. Some of these 200+ issues are unsolved for a fairly long time. https://github.com/cachix/devenv/issues https://github.com/cachix/devenv/issues
- domenkozar 2y agoDo you have a particular in mind or does the general number bother you? It's a very ambitious project, so a lot of issues are related to either Nix or general support for each language/service.
- FireInsight 2y agoOfftopic: upvoted for the username
- crabbone 2y ago* Fast -- in what way? How can you even measure the speed of an environment?.. * Declarative -- as a developer, I don't care... Why is this important? Also, declarative means there's a bunch of imperative code hiding behind it. It just makes it harder to debug when things break. * Composable -- in over 25 years of being a developer not even once did I want my dev. environment to compose with another... And the article opens up with: > Simple JSON-like language Why on earth?.. And things down the road that announce "features" like "run processes"... Is this some kind of April 1st joke that is meant to be funny because its two weeks too late?
- weatherlight 2y agoI'm sorry that you've been a dev for 25 years and you've never worked anywhere where microservices and distributed systems are the norm, being able to modularly combine and recombine systems can be invaluable for rapid development and testing.
- goodpoint 2y agoReply with some real explanation instead of snark.
- helf 2y ago[dead]
- crabbone 2y agoYou really set up your development environment using microservices? How is this subject relevant to development environment setup? If you are interested in my job history: it includes two of the top-ten largest US s/w companies. My area of expertise is storage (more in the direction of SDS as this was a fashion when I got into this field) and more recently HPC. I'm less familiar with the aspects of modern programming s.a. making Web sites for example, and somehow, I have a feeling that programmers who make Web sites really like talking about microservices. So, maybe this will explain my lack of understanding of how you set up your development environment using microservies.
- dpatterbee 2y agoThere are a fair few nix based dev environment systems (devenv, devshell, devbox) and I've tried out a few, but devenv is the one I've stuck with. I don't typically have complicated dev environments, I just use it for installing packages and adding convenience scripts which will automatically be activated and deactivated with direnv.
- discardedrefuse 2y agoI just started using devbox for basically the same thing yesterday. Its very easy to work with. Any particular reason why devenv won for you?
- woile 2y agoI've been using devenv + flake parts and so far it's done it's job perfectly. I build a rust and a node application in the ci. Both local and ci build every time. It will only fail from time to time when i make an update, otherwise no errors at all
- gigatexal 2y agoI want to use nix it's the language that hurts for me. I keep trying to get into it, I have it on a mac laptop but Brew has gotten so good since I last used it almost 4 years ago that I go back to that. Of course this is a whole env thing and not just a package thing but I dunno I'd almost rather build a container and work within that than write nix to get this functionality, the ergonomics of teh language are that galling for me.
- ghthor 2y agoI read this a lot and it prevented me from trying nix many years ago, instead I looked to guix and guile. Turns out, I don’t like schemes all that much. Started using nix this year, language is easy to use. Has very few concepts and syntax, it’s a standard functional language with all those goodies and a clean syntax in my opinion.
- __MatrixMan__ 2y agoI agree. I think the language gets blamed when it's a docs problem, and the docs get blamed because nix scratches the itch for so many different sorts of people. If you're a dev trying to replace poetry you're in a different world than a sysadmin trying to replace ansible, but documenting nix means addressing the needs of both parties. That's hard. The language is fine, especially compared with its alternatives (e.g. templated yaml, yuck).
- Jhsto 2y agoDevenv is often used with direnv, which just means that the environment is activated when you cd in to the folder. This is arguably a bit more than just a docker.
- gigatexal 2y agothat's actually kinda nice ...
- llm_trw 2y agoWhat gets me is the contradicting documentation. How are you meant to install a piece of software and keep it up to date? Is it a channel or flake? Are flakes stable or only for testing? So what's homemanager for? Good luck getting answers on those questions other than "read the source code" and then followed by "no, not that source code, this branch here". I really like the idea of Nix, but the communities priorities leave a lot to be desired of.
- emmelaich 2y agoReproduble -> reproducible
- k8svet 2y agoI wish just one of these would allow for multi-instantiation of services. I have projects where I need to spin up multiple independent postgres. Instead, many of these tools repeat the patterns used in nixpkgs.
- Cyph0n 2y agoIf you’re on NixOS (the distro), the only way to run multiple services of the same type (eg, Nginx) is using containers. These can either be NixOS containers or standard Docker/Podman containers [1]. If you want to run a Compose project, I maintain a tool that help simplify this [2]. [1] https://nixos.wiki/wiki/NixOS_Containers https://nixos.wiki/wiki/NixOS_Containers [2] https://github.com/aksiksi/compose2nix https://github.com/aksiksi/compose2nix
- s900mhz 2y agoThis is great! Thanks for sharing
- Twey 2y agoAs GP implies, NixOS supports running multiple instances of any service you like, but the way some of the modules are written doesn't make it easy. Thankfully one of the advantages of NixOS is that it's pretty easy to add a configuration module to your personal configuration! In general, you can configure systemd yourself through `systemd.services`, where you can write systemd service files ‘directly’ in Nix syntax. Services for which multiple instances make sense often (unfortunately, not always) provide configuration that allows you to specify multiple instances (i.e. their top-level configuration object will be a list or attrset of instance configurations). I've written a little bit about patterns to do this here: https://twey.io/nix-patterns/inputs-and-outputs/ https://twey.io/nix-patterns/inputs-and-outputs/ If you needed, say, multiple instances of Postgres, it's not too challenging to copy-paste the nixpkgs implementation, change it a bit to parameterize the config on (e.g.) a service name for namespacing, then import that module into your NixOS configuration to allow you to define multiple instances. For example, I did this here for the Rainloop email client: https://github.com/Twey/dotfiles/blob/main/nixos/modules/services/rainloop.nix https://github.com/Twey/dotfiles/blob/main/nixos/modules/ser...
- megaloblasto 2y agoThis might get down voted, but here goes. I agree that the Nix documentation can be confusing and even contradictory at times. I agree that there is a steep learning curve to getting started with Nix and NixOS. However, I do not think that Nix has ever claimed or intended to be a tool that can be used easily by everyone. If the ideas seem pointless and confusing to you, that's fine, don't use it. There are bunch of great package managers and linux distros that will probably suit you better. But, if you see the need for declarative package management, then Nix is for you. I'm a phd student in computational science. I use a bunch of different packages on my computer and I need to know exactly what I've installed and I do not have time to debug problems from dependency hell. Nix and NixOS have been two of the most interesting and useful tools I have every used. Not only have a gained huge productivity boost from having reproducible environments and declarative package management, but I've thoroughly enjoyed the process of learning these unique tools that, for me, are leagues better than any package management system I've used in the past. If it didn't work for you, I hope you find a tool that suits you better. But that doesn't mean its bad. It might just mean it wasn't intended for you.
- jimbokun 2y agoWhat are the productivity advantages over using Docker images?
- ngruhn 2y agoFor me the big advantage is that it integrates much easier with my development environment. For example if I have a language server for some programming language running in Docker, it’s not obvious to me how to make it talk to my editor on the host. I can expose a port but both the editor and the language server need access to the code base I’m working on. I can mount the code base as a volume but the language server gets confused about absolute paths that are not matching and stuff like this.
- chriswarbo 2y agoDocker images of what? Docker cannot read minds; it has to be told what to put in those images. Nix is a tool for saying what you want; in a more sensible way than the de facto standard of "grab an entire Ubuntu installation, then run `apt-get -y` commands because I don't understand dpkg".
- angra_mainyu 2y agoI've been a long time user of devenv.sh and can definitely recommend it as a nice wrapper around nix. I often want to have some packages/tools installed when I'm working on a project and docker isn't always the right fit, which is where devenv comes it. I basically use it as a generalized version of venv.
- jimbokun 2y agoWhat are the cases where Nix is a better fit than Docker?
- chriswarbo 2y agoNix works natively on systems like macOS
- avtar 2y agoNix can be used to create Docker images https://nix.dev/tutorials/nixos/building-and-running-docker-images.html https://nix.dev/tutorials/nixos/building-and-running-docker-...
- angra_mainyu 2y agoPackages that need to cross docker's isolation or are graphical. Some recent examples: - Downloaded a .7z file, nix-shell -p p7zip, extract, exit shell. - Was working on a paper, set up texstudio w/ devenv. - Needed to use vagrant and virtualbox, however apt installing them was impossible due to a dependency issue (incompatible on pop os at the time). Trivially fixed by just: devenv init -> add to devenv.nix file -> devenv shell
- deleted 2y ago[deleted]
- mrd3v0 2y agoI have been using this for a while, great project! Though something that annoyed me with the recent v1 release is that it changed the default repository where it pulls the package definitions from Nix's official to a fork made by the author. That is dangerous and also lags behind an incredibly active and large upstream. If you want to patch things, use proper Nix overrides or apply the patches using devenv code, don't fork a +80,000-big rolling release package repository.
- bPspGiJT8Y 2y agoNot fast at all in my experience. Just running (for the first time) what would take seconds with something like `asdf` could take up to half an hour with Nix.