Live data from Hacker News

My First Impressions of Nix

mtlynch.io

301–310 of 354 posts

Re: My First Impressions of Nix

#301

15 minutes to configure a local VM for development with Ansible? That feels very off. It used to take me about that long to set up a Kubernetes cluster on remote VMs from scratch (with etcd, load balancing, etc.). I haven't used it for a while though.

This a bit like saying a 15-minute commute sounds "very off" because it only takes you 10 minutes to drive to your office.

Ansible run times are going to vary wildly depending on what's in your playbooks and how fast your nodes are.

In my case, a lot of my VMs share a set of common roles I've been developing over 8 years of using Ansible. The roles span several different OSes and versions, and every play adds time to the run, even if Ansible just skips it or has no action to take. And then third-party roles from Ansible Galaxy typically take even longer to run because they're not optimized for speed either, and they're targeting an even larger set of possible OSes.

Re: My First Impressions of Nix

#302

Earlier quoted context omitted.

You don't have to manage your system with NixOS to reap the benefits of Nix. It solves very real problems that very much exist, it might not exist if you're a one-man show deploying WordPress to GoDaddy though. Barrier to entry: 1. Run the nix installer 2. Enable flakes 3. cd project 4. nix run This ensures you run the package with every dependency except the kernel pinned to a hashed version. If dependency hell is n…

You're omitting the entire thing about learning how to write nix. Which is nightmare fuel even for FP fans.

You don't have to know how to write Nix to write 95% of all Nix, it's just "JSON with functions" after all. There are definitely advanced things that the Nix and NixOS developers maintain for me.

Just like I don't know how to implement any crypto, or how to implement efficient 3D pathfinding I don't know how to implement NixOS. But I can write a derivation using the helper functions for the language I want to package, which aren't many these days since nixpkgs is huge already.

Re: My First Impressions of Nix

#303
post #280

Earlier quoted context omitted.

I just dipped my toe into the Nix pool a couple of weeks ago, and there are instructions to use root to create a /nix and grant ownership rw to your user account. No further admin required, but everything else seems to work as if using the Nix root user method.

The installer used to have an option for this, but nowadays it's discouraged. How come you wanted a single-user install so much? And j/w, are you on macOS?

Linux, but if there is ever an option to have one fewer services and/or root privileged things, I will take it.

Re: My First Impressions of Nix

#304

Earlier quoted context omitted.

I meant creating an entirely new package from scratch. Regarding non-goals - I think that exposes the fundamental difference. rpm-ostree isn't "better". It's trying to solve different problems. The use case you described is a very small part of what Nix makes possible. Nix isn't just trying to fix or improve on existing systems - it present a fundamentally new abstraction that can be used for many purposes. Yes, you…

Yes you're right, better wasn't a good choice of words. My comment was in the context of replacing Ansible with Nix for making a reproducible system, as per the linked article. I wanted to point out that alternative which will be much more familiar to most people, who perhaps aren't ready to jump to an entirely new paradigm, but still want a declarative config. But undoubtedly Nix is much more powerful. I myself have…

Makes sense, I'm sure that there are many on RPM-based systems that would enjoy a quick win like rpm-ostree.

Re: My First Impressions of Nix

#305

Seeing a tweet like the one from Mitchell makes me want to try Nix. Or at least I want to want to try Nix. Then I read the comments here and am reminded that no one can even succinctly explain what Nix is. I've read dozens of comments here and I still don't have a clear idea!

Your mind must be pure to understand Nix. Work on your purity. Just kidding. You might explain why you want to try nix? That would help customize an explanation for you, because there are levels. Umm... here is my attempt. Sorry.

Nix is a programming language plus utilities that are useful to define and work with software packages in a reproducible way (https://github.com/nixos/nix/).

Each package is called a "derivation", which is a function that takes inputs and makes output. The inputs are everything that is needed to make the output. It is "pure functional" package management - for the same input arguments, the same output will be produced. Nix is really fast because each derivation is hashed and cached and the language is lazy-evaluated.

Builds are "hermetic", meaning only the inputs specified in the derivation are available at build time. Contrast this to some packaging systems, where the build is done against some staging area where packages get installed as they are built and the output can depend on the non-deterministic order that packages are built.

Nixpkgs (https://github.com/nixos/nixpkgs/) is a large collection of recipes for existing software. It contains both rules to build software as well as "modules" to configure it or extend it. NixOS the linux distribution is also part of nixpkgs. There are lots of design patterns here and it can go pretty deep. There are also tons of hacks and patches and workarounds to make software conform to the way nix works. Nixpkgs also has a lot of useful library modules built in.

Nix is the latin word for snow. Nix "flakes" are a way to combine multiple inputs as well as pin the version of inputs. Kind of like pipenv/requirements.txt or "cargo lock" or "yarn lock" but for anything.

The output of derivations go in the "nix store" which is a path like /nix/store//, so all sorts of software can co-exist (think multiple incompatible versions of the same library) and can be referenced in a fixed way. Usually you will end up with an output that is mostly symlinks to other /nix/store/ paths.

Nix can make practically any combination of software you can cobble together trivially rebuildable/reproducible. You can write some nix code that will produce a a VM image with test scripts as well as a script to launch the VM with a patched version of qemu and run those tests. You can have all your dotfiles/configuration in code with nix installed just for your user on top of Ubuntu. You can generate a raspberry pi sd card image from a short nix source file and a single command, and then 6 months later change a single line and regenerate it without worrying it might be broken.

You can achieve a lot of that stuff with Yocto or Ansible or a Dockerfile and scripts, but it would be slower than nix and more fragile.

Re: My First Impressions of Nix

#306
post #87

Earlier quoted context omitted.

nixpkgs doesn't use requirements.txt for whatever reason. (That reason probably being the utter brokenness and braindead state of Python packaging; Node packages work much better.)

> Node packages work much better Are you sure about that? I haven't seen a node app built from source on nixpkgs yet. That includes Electron apps like Signal Desktop, which is a bit disappointing. There is this article about trying to package jQuery on Guix: http://dustycloud.org/blog/javascript-packaging-dystopia/

Grep nixpkgs for `buildNpmPackage`, it's ridiculously easy to package a node app nowadays.

Re: My First Impressions of Nix

#307
post #136

Earlier quoted context omitted.

Most of the above. - Nix is a tool for building and installing software. - Nix is a language for expressing how to build a package. Nix-the-tool reads expressions defined in Nix-the-language to know what to do. At the end of the day, this translates into normal commands that run in a sandboxed build environment. - Nixpkgs is a monolithic repository of 80000+ packages, defined literally as one giant expression in the…

So does this allow for different boot setups for NixOS? Say “webserver” or “office management” , “media streamer” profiles?

Yeah! There's specializations[1] to make this even simpler.

[1] https://nixos.wiki/wiki/Specialisation

Re: My First Impressions of Nix

#308

Earlier quoted context omitted.

Pure functions are just a concept that is used in FP world Yet, pure functions can "stand alone". You do not need FP to use pure functions. They are independent from FP. You can be OOP maniac and still use them. So unless you want to sound fancy and trendy then why call Nix functional instead of side-effects free?

> You do not need FP to use pure functions. They are independent from FP. You can be OOP maniac and still use them. This is not true. OOP is fundamentally built around impure operations. Objects are persistent references that you send messages to or that you call methods on (depending on your OOP language of choice). A persistent reference that is stable across different invocations (as opposed to a new reference bei…

> You do not need FP to use pure functions

I think this is a bit more subtle, and a bit less interesting to say, than you're thinking it is and responding to. You need to be impure in OOP world but not in every function you write. I write many pure functions in my OOP work; they make the whole thing easier to reason about.

Re: My First Impressions of Nix

#309
post #280

Earlier quoted context omitted.

The installer used to have an option for this, but nowadays it's discouraged. How come you wanted a single-user install so much? And j/w, are you on macOS?

Linux, but if there is ever an option to have one fewer services and/or root privileged things, I will take it.

Ok cool! The reason I asked is that the multi-user setup has more benefits on Linux than on macOS. That's because on Linux, the full build sandbox is actually available, and the store's immutability is enforced by default.

The tradeoffs are obviously yours to consider. But the normal Nix build sandboxing helps protect you from nasty things like crypto miners in setup.py or whatever, as well as improving reproducibility.

That's less relevant on macOS where the sandboxing story is not so great.

Personally, using Nix with a daemon seems like a better setup to me but adding another highly privileged process unnecessarily is obviously a real security concern. There is some ongoing work, btw, to reduce the level of privileges that the Nix daemon needs.

Re: My First Impressions of Nix

#310

Earlier quoted context omitted.

How about configuration management? Getting the packages is half the story.

The treefile allows you to define arbitrary config files to inject into the image.

Well, it sounds to be somewhat more limited than how Nix manages services. The beauty of Nix is the ability to stay DRY and declare things only once, then refer to them where you need it.

For example, most of my services that need to bind to some specific network interfaces but require an IP address, don't hardcode anything, they all in lines of `services.foo.listen = head config.networking.interfaces.vpn.ipv4.addresses`. Should I want to renumber my networking, it'll be relatively painless. Same with user IDs, passwords, paths, etc - they're all trying to be references rather than copies.

Of course, this can be done with an external template engine, but I like how Nix integrates all those aspects in a convenient package.

Post reply on HN