by shantnutiwari · 4y ago · 0 comments
As someone who tried Nix-- never understood what the big selling point is-- what can Nix do my existing tools can't? (without me spending 6 months)
Nix can create isolated environments, but as far as I see, you can only install the tools Nix repo supports. And the official examples only give toy examples --here's a simple python script you can run with Nix-- but I can just run this simple script in a virtual env, or docker if I have 2-3 different scripts.
What problem is Nix solving? What pain does it fix that is so important it would justify me spending 6 months on it?
And then there is NixOS, which again, I have no idea-- I can create my own Linux distribution that is what, reproducible? Again, is this a real problem anyone faces (and that isnt fixed by docker or ansible or any of the other hundreds of tools)?
My point is: Why is Nix getting so much hype when I dont see them solving any real problems? Sure, they promise a lot, but I have yet to see any real solutions.
Hence the Nix Hype Machine
- everything from kernel and drivers up is specified declaratively in a uniform, expressive way. You version control your entire infrastructure. Not in the sense of a Dockerfile. The Ansible stuff, the Dockerfile, the build of your library, the build of your own software is in one language that can happily and easily reference each other as a unified system.
- with a few caveats, you are cryptographically guaranteed to get the same result, every time, no matter what. if it worked once, it will never break again.
- it has mechanisms reminiscent of git or something: you can checkout a different computer or set of computers, and if you don’t like the result, revert to what you had before.
- it treats patching of arbitrary software as a completely typical and first-class activity. if anything doesn’t work how you want, you write a patch, check it in, and it works now and always will. upstream at your leisure or not at all.
- you get exactly what you want on your system, no more, no less. no gnome-keyring-daemon bullshit on your headless server Ubuntu 20.04 LTS.
- caching of artifacts both locally and via cache servers run by you or others or both is very granular. no giant slabs of docker composition towering ever higher.
I can then use that same environment to do CI without even creating a docker image, e.g. this for Gitlab CI:
image: nixos/nix:latest
before_script:
- nix-env -f shell.nix -i -A buildInputs
If the amount of stuff is big, or you need to build things rather than get them out of Nix cache, then you can build the docker image using Nix tooling instead.You can also use Nix to control what is on a machine. E.g. for our lab setup we had a gateway machine behind which was all the test equipment. NixOS was great for having the exact config of that machine checked into version control so we could recreate it. It's far more reliable than Ansible or something like that.
Nothing; even CSS is Turing-complete. It's all a question of how easy, how secure, how reproducible, etc.
> as far as I see, you can only install the tools Nix repo supports
Lol what? Nix literally just executes a given command, with given arguments and given environment variables. This comment is like saying "Makefiles can only build C projects".
Just like Make, if you can build something with some shell commands, then you can build it with Nix. It's often as simple as:
runCommand "my-program" { myEnvVar = myValue; } ''
put your shell commands here
mv my-build-product "$out"
''
('runCommand' tells Nix to run a Bash executable, with the given env vars (including the given commands), and a "default builder" script as argument (that "builder" will eval the given commands))> Again, is this a real problem anyone faces (and that isnt fixed by docker or ansible or any of the other hundreds of tools)?
Nix has been around for two decades. It's more appropriate to ask what was the point of creating Docker, Ansible, virtualenv, etc. when Nix already existed.
> And then there is NixOS, which again, I have no idea-- I can create my own Linux distribution that is what, reproducible?
Maybe you're getting hung up on terminology; if you would consider "Ubuntu, but with my SSH config file" as "my own Linux distribution", then sure, NixOS creates Linux distributions. If you would call that "configuring a Linux system", then NixOS is for configuring Linux systems.
Nix, after two decades, still has an incredibly sharp learning curve, especially to build your own packages. Docker has almost no learning curve, including creating your own images and sharing them with the world.
with import <nixpkgs> {};
runCommand "my-thing"
{
someSortOfSource = fetchurl {
url = "https://example.com/thing.tar.gz";
sha256 = "0000000000000000000000000000000000000000000000000000000000000000";
};
buildInputs = [ gcc python3 whatever-else-you-like ];
}
''
tar xzf "$someSortOfSource"
cd whateverWasInThatTarball
run whatever commands you like
mv whatever-the-result-should-be "$out"
''
The actual commands can usually be copy/pasted from the README or INSTALL file of whatever project you're "packaging".> Docker has almost no learning curve, including creating your own images and sharing them with the world.
It took me several attempts to learn Docker, and I'm still very much a newbie with it. To be fair, most of the difficulty I had was due to my misunderstandings; e.g. "surely nobody actually does that?" (e.g. "download entire OS just to run a command"; "ignore all the hashing and just fetch 'latest'"; "run 'apt-get -y update' without having any idea what it's going to do a week from now"; etc.)
Once Docker 'clicked' for me (i.e. I realised that indeed, people are doing that sort of stuff), it became much easier. It's also when I completely lost interest in Docker, and started using OCI containers instead (you can get remarkably far with just 'tar', 'sha256sum' and 'jq'!).
These days my only interaction with Docker is when other people's containers cause an outage at work, due to Docker blowing through all the disk space on our cloud servers. (Fun fact: you can resize AWS disk partitions on-the-fly, but not if they're 100% full, since the partition-editing commands try to allocate temp files)
I'd say that the relative popularity of the tools is an indication of how well suited they were for the things that people actually wanted to do.
Nobody (exaggerating here for dramatic effect, but it probably applies to a large part of the unseen 99%: https://www.hanselman.com/blog/dark-matter-developers-the-un...) wants to have fully reproducible builds and a unified language for configuring everything like Nix attempts to do, or even have an OS that attempts to centralize those concepts, like NixOS does because a lot of it is alien to them.
They just want to run their PHP CRUD app in a vaguely predictable way that is less painful than what they've historically done (ship scripts through FTP, experience pain due to php.ini being different, or a system package not being present, or the system package being of a different version). Docker and other solutions like it are the closest that they can get to shipping their machine to prod, given that shipping VMs has more challenges, than just telling their clients or even their ops to just run a Docker container with some configuration.
Nor do they want rootless containers, or distroless containers or Podman or any of the other fancy solutions - they just want their Ubuntu userland and their app to sort of work, most of the time.
We had containers in one way or another long before Docker, for example, FreeBSD jails were pretty good. And yet, they never caught on, nor did FreeBSD outside of large corporations, because for the most part the developer experience just wasn't there. Then came along Docker and changed everything (with plenty of bumps along the way), now building and running your app is pretty simple:
1. nano Dockerfile
2. docker build -t some_image_tag .
3. docker run some_image_tag
(or, you know, push the image somewhere)
Now, the layers system is a mess, permissions management is a mess (hence lots of containers run as root), volumes aren't easily browsable but bind mounts are also problematic, orchestration is all over the place (Compose is nice for a single server but doesn't handle clusters, Swarm is nice for multiple servers but mostly dead, Nomad is weird because of HCL, Kubernetes is nice if it's someone else's problem but there be dragons if you can't just pay a cloud vendor to handle it for you) and it got a large amount of things wrong (e.g. "latest" tags), but it was still good enough and aligned with actually getting things done.Additionally, most developers don't get paid for ensuring that their application will run in a stable and predictable manner 5 years from now. Most developers get paid for shipping that mediocre piece of software that their boss wants them to before the end of the week and having it work well enough so the company can earn some money, before they're told to move on and do something else the next week. I'm not saying that it's how things should be, but just the way they are, at least for a lot of people who don't tackle interesting problems yet still put food on the table.
That is the "tragedy of good enough" and why Nix, NixOS, jails, FreeBSD or anything else won't be as popular until vaguely low skilled developers can get easily started with them. Maybe things just need to cool down and become more stable, even Kubernetes has gotten less horrible thanks to Rancher/K3s in the last years, maybe in a decade package management and the way OSes are will be more approachable.
Right. The Dockerfile format is much less elegant than Nix, but it's easier to get started with, and can be used for most cases.
I don't necessarily see everyone _writing_ Nix. But I think one way Nix can gain in adoption with developers is Nix makes it easy to make dependencies available for working on a project.
I'd also point to git: many developers struggle to use git; and might use it for some time without an intuitive understanding. The network effects of GitHub have somehow been enough to make git a prominent tool, despite it being difficult to use.
I think as more Nix stuff becomes copy-pasteable, there are enough use cases which don't require deep understanding of Nix.
- I have machine configurations that if say a HDD dies means I can just replace it and be pretty much where I was an hour later from scratch.
- I can update a configuration (even doing the equivalent of a major OS update) without fear as it's possible to just use the old configuration if something is broken.
For Nix in general:
- Can define versioned development environments which aren't awkwardly sandboxed as they are in Docker.
- It's possible to make multi language/ecosystem builds.
- Builds only build what needs building.
- You can build on one machine and ship the build to another as if that machine had built it.
Right.
The benefits are clearer for DevOps than for developer workstations. (e.g. Nix makes it easy to declare the set of packages installed, with atomic rollbacks).
For developers, I think it's still worth keeping an eye on, since Nix provides a programmatic way of dealing with packages of software; and dealing with packages of software is pretty much what a developer will need to do when driving their system.
e.g. project READMEs typically list some commands for setting up a developer environment; Nix promises a consistent, single command for that (if projects provide Nix files).
For most things that you can do with Nix, there's a quicker + dirtier approach already. e.g. VSCode allows isolated/ephemeral dev environments with remote containers; Docker provides an easy way to be confident software will run a certain way in other system; ZFS/btrfs snapshots allow for rolling back changes; nvm/rvm/asdf allow for project-specific versions of packages; apt-get/brew provide a way of installing packages to a system...
Nix is an elegant and coherent solution to these kinds of problems.
> Nix can create isolated environments, but as far as I see, you can only install the tools Nix repo supports.
Not at all! -- It's comparable to e.g. Docker: With Docker, you can run containers using images served from DockerHub.. but you also have the option of building Docker images and using those.
With Nix, you describe the packages/libraries/tools you want with Nix. This varies from trivially easy, to "have to really understand what you're doing" difficult.
If you do very typical things that are within the sweet spot of the quick and dirty solutions, you'll likely see nix as redundant.
If for some reason, the quick and dirty solutions always seem to break for you you'll grow to love nix and likely NixOS.
NixOS and Guix present alternative systems that reuse functional developer skills. If you don't have or want those skills then they aren't going to make any more sense than choosing Smalltalk or a lisp machine while being resistant to leveraging their respective paradigms.
Nixos extends this reproducibility up to the level of the OS. Rather than a machine being a giant ball of mutable state, some of it pushed around by configuration management, Nix pulls the entire system state up to a single top value which is set by the bootloader (or similar high-level mutable cell). Like switching to functional programming, at first it just appears different, difficult, and not compelling. But after you start to understand the paradigm, a lot of nice capabilities just fall out, that would otherwise be effectively out of reach.
[0] Not deterministic builds per se, which is an ongoing effort.
But overall: it makes me more productive. It is my secret weapon to manage the complexity of software development. The benefit is not on day 1, but on day 100 and day 1000.
Well, for one, someone send me a random Python script with a dependency on a PostgreSQL driver (that probably needs to compile some C library). Just the script, no `requirements.txt` or `Pipfile.lock` or `pyproject.toml` files declaring the dependencies. I could have just created a virtualenv and tried to install it using pip, that would probably fail because I don't have a proper C compiler setup. Or maybe I have but it is missing headers. Maybe it will work because there is already a wheel for my system, but maybe it will not because some other random reason.
Instead, I just wrote two lines for shebang:
#! /usr/bin/env nix-shell
#! nix-shell -i python3 -p python3 python3Packages.psycopg2
And them `chmod +x ./script.py && ./script.py`, and everything is working.> What problem is Nix solving? What pain does it fix that is so important it would justify me spending 6 months on it?
Really the meme that you need to spend months just to use Nix properly needs to die. I literally skimped the docs and got a working NixOS install at my first try on the system [1]. The default configuration is really well documented with examples, and I think most people can get what they want quickly.
Eventually I wanted to use something that was not packaged on nixpkgs, or I started to want to upgrade some specific packages without using unstable. At that point it was when I started to think Nix was kinda of painful (not because it was difficult to do, however the documentation is not good and you end up searching a lot until you find some answers). At that point yes, it is kinda a journey, but it is very similar to learning a new language: you eventually can get very proficient at it, but you never stop learning.
> And then there is NixOS, which again, I have no idea-- I can create my own Linux distribution that is what, reproducible? Again, is this a real problem anyone faces (and that isnt fixed by docker or ansible or any of the other hundreds of tools)?
Try to have reproducible system with Ansible. Yeah, I tried. It simply doesn't work well. Ansible is always a pain because steps randomly fail in a new machine, and you can waste hours of debugging for simply issues. Not NixOS: if your configuration builds there is a great chance that everything will work.
NixOS is the only system that I am sure that I have the exactly same configuration as my other systems, as long I am running the same commit from my nix-configs repository. Can't say the same for Ansible: if I setup a machine using Ansible right now and 2 days from now, pretty sure they will have different package versions (since the repository will have changed them), for example.
Also, you don't have rollbacks with Ansible. Yeah, you can have ZFS/Btrfs taking periodic snapshots and use this for rollbacks. This is not the same though. The UX in NixOS is simply so much better (reboot your system and select which generation you want to boot).
> My point is: Why is Nix getting so much hype when I dont see them solving any real problems? Sure, they promise a lot, but I have yet to see any real solutions.
Well, my point is: Nix solves real problems. Maybe you are not bitten as much as I am with them, maybe you think that spend half a hour trying to get a random Python script to work is fine. And I completely concur with you. It doesn't mean that Nix is not worth your time though.
[1]: Now, I think the fact that I used Arch Linux before really helped, since both NixOS and Arch Linux have an installation process that is completely terminal based instead of a proper installer.
I find it disgusting you talk about an opensource effort of mostly volunteers like this. And I think you are wrong. There is no machine: it's people.
Yes it's hard. It might not be for you. But it is cool to some people, so they talk about it.
Other replies to your comment answer your questions well (showing people really care).
This is not bought marketing BS but some "agency machine". This is the labor of love of many. And you are simply dismissive.
> Reproducible builds and deployments
> Learn how to make reproducible, declarative and reliable systems.