6 ms·
NixOS: Declarative Builds and Deployments
- thatxliner 3y agoHonestly, I don’t really understand the advantages (or the point of) NixOS over something like Docker.
- Asdrubalini 3y agoDocker is not reproducible, you just apt-get install what you want hoping that the RUN commands get you a version that is still compatible with your software and doesn't break anything. With NixOS, you can pin the specific hash of every software, and you don't need the entire Ubuntu 20.04 in a container to deploy a webapp.
- candiddevmike 3y agoYou can pin versions with apt-get install...
- UniqueUsername0 3y agoWhat's the model of the pinning? Is it an arbitrary semver? Is it a sha256 calculated by the content of the package (Content Addressed)? Is it a checksum calculated from all the inputs that were used to create the package install spec (Input Addressed)?
- deleted 3y ago[deleted]
- rho138 3y agoAll of the above? Nix isn’t the first package manager to do something unique.
- cstrahan 3y ago> All of the above? Nope. At best, you can do something like this: apt-get install gparted=0.16.1-1 That handles the semver case, but that doesn't address the rest of the "all of the above": - sha256 calculated by the content of the package (Content Addressed) - checksum calculated from all the inputs that were used to create the package install spec (Input Addressed) > Nix isn’t the first package manager to do something unique. Sure. But it is the first package manager to do the above unique things. After all, the reason for Nix's existence is just that: no other package manager before it has done what it does.
- cstrahan 3y agoHow does apt-get install handle the following scenario? You need the following software: - You need the latest release of Erlang for your app - A database (like Riak), whicn in turn happens to need an older version of Erlang - The new Erlang needs the latest libopenssl - The old Erlang needs an old v1.x libopenssl - You used some open source software written in C++, so you need libstdc++ - Some of your own C++ code has exposed a bug in libstdc++, so you need yet another libstdc++ with your patches, but just for that software - Etc How does apt-get install allow you to have multiple versions of a given dynamic library (with the same SONAME) and multiple binaries (erl, clang, etc) installed at the same time? The answer: it doesn't. Nix has no problem handling everything I described above, and it handles it easily. So, yes, you can pin versions with apt-get install, but you're out of luck if any of those packages have any transitive dependencies with different versions. Also, the pinning guarantees are higher with nix: you can be guaranteed that your packages and their transitive dependencies are byte-for-byte identical, every time. Pinning end-to-end across all packages (and every transitive dependency thereof) is not a normal, happy-path thing to do in apt, so you would be hard pressed to find anyone that does that, given how onerous that would be -- whereas it's trivial in Nix.
- jbboehr 3y agoMy experience with apt is that, while you can pin versions of packages once they're installed, they may not exist indefinitely in the mirrors. Whereas Nix keeps binaries around longer, but also includes the ability to automatically and reproducibly build from source.
- rgrmrts 3y agoYou can build containers with nix, but they’re completely different. One is an operating system built around a package manager and the other is a containerization tool. More appropriate comparisons would be: - NixOS and Ubuntu - nix and apt/homebrew
- domenkozar 3y agoBetter composability and abstraction, see for example how you can configure a process in https://devenv.sh/services/ https://devenv.sh/services/ that has first-class support for development environments using Nix. No need to use containers too, which bring cognitive/workflow overhead.
- drowsspa 3y agoAnd Nix doesn't? At least with Docker you can get something useful within 2 minutes
- UniqueUsername0 3y agoBut is it pure?
- cstrahan 3y ago> And Nix doesn't? If you're asking if installing/running software with Nix requires containers like Docker does: no, it does not. > At least with Docker you can get something useful within 2 minutes % nix shell 'nixpkgs#ruby' -c irb irb(main):001:0> puts "Hello, world!" Hello, world! => nil irb(main):002:0> That took me about 5 seconds to type out, and now I'm in an IRB REPL slinging Ruby code, despite having never installed Ruby prior to running that command. Add another 5 seconds for nix to fetch the necessary files (which are then cached locally, so a second `nix shell` invocation will be immediate) and we're sitting at roughly 10 seconds end-to-end. If it takes 2 whole minutes to use Docker, Docker must be pretty bad. I guess vintage things have their appeal, but apart from that I don't see why people would be so attached to such archaic, inferior technology.
- fnordlord 3y agoNixOS is also a declarative build of the entire machine as opposed to just a container also, so it's totally normal to have a NixOS build with multimedia apps, games, etc. To me, Docker is for building an entire environment for a single app to run in, whereas NixOS is for building an environment that runs multiple apps. Like a microservice vs a desktop machine.
- orbital-decay 3y ago> so it's totally normal to have a NixOS build with multimedia apps, games, etc Every time I try NixOS on a desktop with anything more complex than setting a couple flags (writing some derivations to work around the broken software, managing my dotfiles etc), my configuration ends up as an unholy mix of weird Nix trickery, FHS paths in a non-FHS environment, and foreign config includes. It's like writing (programming) your Emacs config by patching the existing one with a Python script, for twice the fun. Of course it also needs to be versioned and documented to keep track of it, otherwise what's the point. I can't help but think that the Arch approach (make the system management transparent, close and personal, and ignore the burning trashcan) is infinitely easier for personal usage than the Nix approach (describe everything with an additional layer of indirection). It's probably the opposite for huge deployments, of course.
- fnordlord 3y agoThat actually makes me feel little better. I spent a few weekends trying to get a little raspberry pi SNES emulationstation on NixOS going and it turned out to be a total waste. I quickly found myself deep into scripting custom configs and questioning whether the packages I was using actually work. Reproducible != Just works I assumed I was just a dummy for not getting it to work because there are tons of peoples' flakes on Github with their entire desktop environment declared. That's what gave me the impression that this was totally normal. It's super cool and impressive but I just haven't grokked reading Nix yet.
- earthling8118 3y agoThey aren't equivalent. Docker doesn't provide the same guarantees and is also more clunky to work with
- rtpg 3y agoyou know how if you edit the first line of a 50 line docker file you gotta sit there forever to rerun the entire build? You don't have that issue with Nix. You know how a Docker file barely has any structure, leading to a lot of bashisms to try and script certain behaviors? Nix doesn't have that issue. NixOS is an OS you can configure with Nix. A lot less "OK so edit these files to try and configure something, then reboot", a lot more "configure this data structure, then reboot". Makes your system configuration mostly be in the same place, as NixOS will distribute these changes across the file system as needed to get things working. It's pretty nice! Overall... it ends up being a bit easier to document why you're doing something in a Nix file relative to a Dockerfile, and caching and the like works much more smartly (lots less "move all this stuff to the top/bottom for caching reasons" you might do in a Dockerfile) ("Nix" here means "nix + nixpkgs", which is important since lots of nix-ism are basically downstream of how nixpkgs is written and the patterns used there)
- saidinesh5 3y agoDocker= issues / hacks with file/user permissions, More storage requirements, Additional hacks needed for gui to work But I'm yet to use NixOS, so i don't know what it's downsides are..
- jljljl 3y agoWe switched to using Nix at our startup because the rebuild time, reproducibility, and performance of Docker (especially on MacOS) were really slowing us down. Building and starting our dev container could take several minutes if we busted Docker's layer cache, but with Nix we never had to worry about that. We open sourced our Nix dev environment tool (Devbox), and wrote a bit about why we switched here: https://www.jetpack.io/blog/devbox-turn-a-1000-container-script-into-10-lines/ https://www.jetpack.io/blog/devbox-turn-a-1000-container-scr...
- bqmjjx0kac 3y agoI have had a great experience using the Nix package manager on other Linux distros. It's super easy to try out software with `nix-shell -p somepackage`. (It's a little rockier on macOS.) Another neat trick is reproducible shell scripts that use Nix to declare their dependencies in a sort of extended shebang line.
- bobajeff 3y agoI like the idea of nixos. Having one file responsible for all packages installed on the system is way better than what traditional distro use. I just don't like the quality of the packages. It would be nice if someone could do something like a os wide packages.json but for a mature packages repository like Debian.
- helloimhonk 3y agoAlpine linux has a /etc/apk/world which is just a full list of all the packages currently installed I'm not a fan of nix but I'd say the nixos repository is fairly mature.
- tkz1312 3y agonixpkgs is (and has been for many years) the largest and most up to date package set by a very large margin. source: https://repology.org/ https://repology.org/
- helloimhonk 3y agoi know, just was responding to the mention of maturity in the parent
- bobajeff 3y agoNix respiratory has a lot of good work done in it but I've found some bad packages. Alpine also sounds like a nice system but I'd bet it has an even worse issue with bad packages because of musl.
- mid-kid 3y agoAnd gentoo has /var/lib/portage/world, and pacman has "pacman -Qe", and apt has "apt-mark showmanual". ...I sometimes wonder how the world would be if the "explicitly installed packages" functionality was better exposed and advertised. I never see any guide for "installing development dependencies" use things like "pacman -S --asdeps" so you can clean them up later.
- kodama-lens 3y agoI first looked at nix-shell which you can use to create ephemeral environments just like Docker, with the difference that they are 100% reproducible and you don't need containerd or like. It is awesome to create scripts which run the same on EVERY system. Then looked at NixOS. I geht the point of having a deklarative like OS which you can rebuild in a couple of minutes, BUT the nix language is kind of unituitive and all the tools like flake and nix packages do some magic it con't quiet understand. It does not help that the docs are kind of meh.
- LatticeAnimal 3y ago> It does not help that the docs are kind of meh In my experience, they’ve improved massively over the last few years. Most of the time, the docs directly explain how to solve some problem I have while also giving good context. I recently was messing with my boot loader and the docs were perfect
- eikenberry 3y ago> I first looked at nix-shell which you can use to create ephemeral environments just like Docker, with the difference that they are 100% reproducible and you don't need containerd or like. Sounds like podman. What is the big differentiator from it?
- yencabulator 3y agonix shell is just another shell instance, with new things brought in via $PATH etc. Not a container, still part of your "current computer environment".
- eikenberry 3y agoSo more like virtualenv?
- yencabulator 3y agoSort of, but instead of being focused around a local directory, everything is stored in /nix/store/<hash>-<name>, declaratively created and reproducible, and there's a whole Linux distro built using that.
- baby 3y agoI think the idea is good but execution is poor to reach mass adoption because: 1. It tries to replace ALL package managers due its extreme philosophy. I had a lot of issues when it tries to replace Cargo for example 2. It uses a functional language, which will lose 95% of users 3. It never had a great user experience especially if you’re new and trying to learn or if you’re not using linux or if you bring your own tools (e.g. vscode) I think something like that could totally exist one day, but it’ll have to restart from scratch on a cleaner base IMO
- colordrops 3y agoWhat exactly would this "cleaner base" look like? A main goal of Nix is a completely reproducible deployment, and many tools are not built for declarative usage, so Nix must add a layer on top in order to make them declarative. If you only go part way, then the entire point of Nix is nullified. Might as well use Ansible. That being said, it's really not that difficult to use tools in their original form on Nix is you want. You can create temporary FHS shells in which tools just work. I do this with Python, as I can't be bothered to do it the "right" way when I just want to run some random script from github.
- baby 3y agoMy experience with Nix is that my own tools didn't work, even with the help of Nix experts. Then, after months of debugging we figured out that I had to quit vscode completely, and then start it from the console using the nix command with the -i option to clean up any environment variable (without that option it wouldn't work). There were some nix plugins for vscode, which would have been awesome if they had worked, but they didn't.
- cstrahan 3y ago> What exactly would this "cleaner base" look like? My interpretation would be something like: the abandonment of software that is so poorly designed that it is difficult to package and/or run under Nix. This commit message (from one of my commits) details some of the struggles supporting Ruby under Nix: https://github.com/NixOS/nixpkgs/commit/b6c06e216bb3bface40eb8ea6576b25f9b2971dd https://github.com/NixOS/nixpkgs/commit/b6c06e216bb3bface40e... Each of those problems is due to either: 1. Some unmotivated contrivance in Bundler, where the maintainers refused to make their stuff less needlessly broken, or 2. Ruby programmers in general not programming with packaging in mind (haven't touched Ruby/Rails professionally in a while, but when I did, it was par for the course to rsync/capistrano files around -- no one saw the utility of any sort of packaging) And the two really reinforce each other. Bundler is the de facto way to declare and pin dependencies at the app level, but then Bundler makes it nearly impossible (see the commit message for details) to package software using Bundler, which reinforces the "fuck it, we'll just rsync files around over SSH", which means no one pressures Bundler to Do The Right Thing. It's the same thing everywhere else. There are complaints elsewhere in this comment section about the nodejs/npm experience on Nix: same underlying problem. The design behind npm is so unnecessarily shit-tacular that it kinda sorta just barely works on its tier 1 platforms. I don't envy the brave souls that have worked on supporting npm packages on Nix.
- bsnnkv 3y agoNixOS is honestly the single most game-changing thing I've been introduced to in my last decade of experience in tech. If you're interested in trying out NixOS I highly recommend either running it as an WSL2 VM[1] if you have a Windows machine or deploying it on a cheap VPS[2] to play around with. I personally still use a Win11 desktop for compat with Adobe software and a few other bits and pieces, but I do all my serious work on a NixOS WSL2 VM. [1]: https://github.com/LGUG2Z/nixos-wsl-starter https://github.com/LGUG2Z/nixos-wsl-starter [2]: https://github.com/LGUG2Z/nixos-hetzner-cloud-starter https://github.com/LGUG2Z/nixos-hetzner-cloud-starter
- candiddevmike 3y agoI keep seeing this from people online but I have yet to see Nix in the wild at any large organization. For such a "game-changing" thing, it certainly doesn't have the meat space following you see online. To me, I tried Nix, got frustrated with packages, realized I'm just using someone else's abstractions for defining configuration files (with the same kind of quality you'd find on Ansible galaxy), and realized it's not solving a problem I have.
- colordrops 3y agoIt can be game changing for individuals - it was for me. But is hard to deploy at scale, at least to workstations, unless everyone on the team is motivated and skilled enough to do it, or the team started from the beginning with it. It also has a steep learning curve. There are several quant and defense firms that use it as their main workstation and deployment OS, where most individuals are highly skilled and rigorous accurate deployments are a must.
- nechuchelo 3y agoIs Google large enough? https://idx.dev/blog/post/nix-in-the-wild-project-idx https://idx.dev/blog/post/nix-in-the-wild-project-idx
- bsnnkv 3y agoNice, I didn't know this! I'll add that I know Nix is also used widely at Discord.
- dinkleberg 3y agoI'll be honest, the first few times I tried using Nix I just couldn't get into. It was too complex for the benefits I was getting. But that was using Nix on another OS. I recently switched to NixOS because I wanted what they were selling and the experience this time around was way better. Having no other option but to figure it out made me learn the essentials real quick (like an exchange program to a foreign country that speaks another language). If you think about it, when you used Ubuntu or Fedora or RHEL for the first time, and probably for a very long time, you could get by without learning the deep intricacies of what is going on behind the scenes. The same is true with NixOS. The things you need to learn are different, but once you get a basic setup with home-manager setup you're off to the races. (Btw, I used this "book" to get started and it was great: https://nixos-and-flakes.thiscute.world/ https://nixos-and-flakes.thiscute.world/) The best part about using NixOS so far is that things just work. Setting up my graphics card was as simple setting enabled = true. Same for configuring specific audio frameworks. And I had tried many times to get Davinci Resolve working on other distros and always encountered issues leading me to need to dual-boot Windows so I could do video editing. Now I just enabled Davinci Resolve and it works! No more Windows. If you're brand new to linux on the desktop, I wouldn't recommend it. But if you've been doing that for years, maybe try NixOS in 2024.
- colordrops 3y agoHaving been on NixOS exclusively for a couple years now, it's inconceivable for me to go back to a non-declarative OS. It would be analogous to from from Git to unversioned source code. My operating environment is a piece of compiled software itself now, and is remarkably reliable and predictable. Yes, it's difficult to learn and takes more work, but it's similar to Git in that respect - powerful tools are worth the effort if it's your vocation.
- tomberek 3y agoI work on Nix and think this paradigm has already impacted and will continue to influence software devopment in general. I want to make it easier for organizations/companies/groups to adopt it. Ideas and questions are welcome.
- aliasxneo 3y agoI'd start with getting some sort of working governance structure going. The sheer number of duplicate libraries all competing with each other has to be hurting Nix. Trying to figure out a TS/NodeJS build was an utter nightmare a year ago as I ended up going through five different projects, including the new "internal" solution, none of which worked reliably. I contributed to the community for about a year and have since left for a number of reasons, but this is near the top.
- tomberek 3y agoGovernance has been a difficult thing to make progress on. I can say that we did discuss recently cleaning up some of these old solutions and making official approaches clearly marked as such.
- sshine 3y agoI run NixOS on a VPS at work. It currently hosts a noVNC dashboard for monitoring. I didn’t nixify the app yet. I allocated a Debian and ran nixos-infect on it and started from scratch, even though I have done this for two other machines, because I’m still experimenting with the basic setup. I do commit changes to git and fork it on company git. But I don’t redeploy remotely: https://discourse.nixos.org/t/deploy-nixos-configurations-on-other-machines/22940 https://discourse.nixos.org/t/deploy-nixos-configurations-on... I’ll need to make noVNC a part of the deployment (not just its dependencies, like python3). I should deploy using AWS AMIs, and make a config for the dashboard. But the NixOS on Hetzner docs are not nearly as easy to guess the best path through. Can you recommend a way to boot NixOS on a Hetzner VPS that is better than nixos-infect? https://nixos.wiki/wiki/Install_NixOS_on_Amazon_EC2 https://nixos.wiki/wiki/Install_NixOS_on_Amazon_EC2 http://jackkelly.name/blog/archives/2020/08/30/building_and_importing_nixos_amis_on_ec2/ http://jackkelly.name/blog/archives/2020/08/30/building_and_...
- deleted 3y ago[deleted]
- flkiwi 3y agoI am not a (current) developer, though I have more dev experience than most laypeople. I have enough experience with languages to pick up a new one relatively easily but I’ve never done anything with a functional language. I installed NixOS after playing around with nix (the package manager) in Fedora. 1. While the WHAT of NixOS was obvious from the start, I have never had a more difficult time understanding HOW to get there with a piece of technology. The documentation is hilariously inconsistent. 2. I have also never encountered a more satisfying, useful, and time-saving piece of technology. I had a computer crash and it took me 15 minutes to be back to where I was on a completely different machine with about 2 commands. 3. Time-saving other than the vast learning curve anyway. 4. Unlike some tech projects, it’s not hard because it’s incomplete or poorly structured. It’s hard because it’s doing something different. (It’s arguable how different it is in 2024, but that’s a different conversation.) 5. To create my child’s account, I spent about 10 minutes editing a copy of my config to pick and choose the packages he needs, and it deployed (on the first go) in about 10 minutes, fully configured. Projects like fleek that put a simplified face on nix are incredibly valuable, because they can unlock 65% of the benefit of the platform with almost zero effort. I can’t tell you if the time investment for the extra 35% is worth it for someone managing family computers, but, y’all, I spend less time fiddling with them now and they break less often. That’s a … plus?