Hacker News new | ask | show | jobs
by marvel_boy 664 days ago
Nice explanation. But Nix is known for a steep learning curve, there is any reason for this?
4 comments

The learning curve depends strongly on what you are trying to do. Many things are very undocumented in Nix, and the interpreter being lazy creates very hard to read errors. No static typing makes everything worse.

If you are trying to configure your system using NixOS, the available options are very well documented so I personally rarely get into trouble.

Packaging an application however can be very difficult.

It's not a curve, it's a wall.

I've tried and failed twice. I think I irreparably messed up my macOS installation with tons of crap by trying.

macOS’s core is in a read-only volume for a few years now, so I doubt you can mess it up unless you disable system integrity.
Yeah, nix on macOS can be a pain…

You might be too deeply scarred to come close to it, but we just wrote a blog post about deploying NixOS servers without installing nix locally or provisioning work here that feels relevant: https://garnix.io/blog/hosting-nixos

if anyone is afraid of this happening to them, I'd recommend the deterministic nix installer. it has an atomic installation process where each step is reversible with the uninstaller. This is uniquely a macos issue since the setup is a bit different to other OS's in terms of creating a read only filesystem for the nix store, but the determinate installer was built to fix any worries of that happening.

https://github.com/DeterminateSystems/nix-installer

can vouch for the detsys installer, and anecdotally, the resulting nix install seems more resilient across os updates. on a similar note, nix-darwin is a must-have. the typical nix-env stuff you see in introductions to nix on non-nixos systems really sells it short, as it feels like just another package manager to keep track of. by contrast, nix-darwin brings the centralised configuration.nix approach, which makes it way harder to hose your environment.

https://github.com/LnL7/nix-darwin

Yes, it’s the result of a doctoral degree.[1] It was never meant to be simple in the first place.

[1]: https://edolstra.github.io/pubs/phd-thesis.pdf

i.i.r.c. the answer to this question is the complexity of Nix is necessary to achieve the level of assurance it provides.

" You may quickly encounter Nix language expressions that look very complicated. As with any programming language, the required amount of Nix language code closely matches the complexity of the problem it is supposed to solve, and reflects how well the problem – and its solution – is understood. Building software is a complex undertaking, and Nix both exposes and allows managing this complexity with the Nix language. " https://nix.dev/tutorials/nix-language.html

My read of this is any other build system has random elements that are usually fine but sometimes cause issues. There are no random elements in a Nix expression.

i.e. Yarn has a lockfile, but does not guarantee the system underlying the Yarn process is "locked." Nix does this down to the fundamental Linux/Mac libraries.

The upside is this complex configuration is a one-time cost for your project. Using a project configured with Nix can be simple. For instance, a Nix Flake can be set up for your project which defines your project workflow commands in the shell. These commands are completely portable.

Nix is not a virtual machine. But it does guarantee the command will run the same way on equivalent systems (unless it does something that goes outside the Nix boundary).