News for hackers. Stuff that matters.
Re:Nix: An idea whose time has come by n42 on Friday February 18, 2022 @07:32PM (#30393175)
I don’t want to be dismissive. “nix but with yaml” is kind of like saying “rust but without borrow checking”. if you think you can approximate what Nix is capable of with YAML and be less complicated, I think you’ve missed the point. what makes Nix powerful is that it is built on the back of an actual programming language. it’s fundamental to the whole thing.

the language itself is surprisingly simple. the difficulty people have with it is that it’s functional, not that it’s nix. I don’t think most sys admins are fluent in functional programming, so it’s a huge turn off and learning curve.

if you approach it as three problems: learn the basics of functional programming, learn the syntax of the Nix language, and only then learn what a derivation is and how it works, it will be a lot easier to approach. at that point the nixpkgs library starts to make a LOT more sense.

I understand that’s a lot to ask when you just want to install some packages, though. It’s a tricky problem.

Re:Nix: An idea whose time has come by dwohnitmok on Friday February 18, 2022 @07:50PM (#30393321)
> what makes Nix powerful is that it is built on the back of an actual programming language. it’s fundamental to the whole thing.

I think I agree with this.

> the difficulty people have with it is that it’s functional, not that it’s nix.

No I don't think that's the problem people have with it. Speaking for myself the thing that's hard about Nix is first and foremost the bad error messages and secondly the complexity of idioms used in nixpkgs. If you stray just a little bit from the happy path, you're liable to get a ton of very arcane problems, and the error message often has nothing to do with the actual problem because a lot of the idioms used in nixpkgs end up doing clever things with Nix that work well when everything lines up just right, but blow up when just a little bit is wrong.

The functional parts of Nix can be obstacles for someone new to functional programming, but when something goes wrong the developer has a clear sense of what is wrong ("ugh why is this immutable?!") even if it's not clear how to fix it. The sheer complexity of nixpkgs though can cause breakages in ways that don't make it clear at all what went wrong.

There are a variety of ways that this could be fixed either in concert with changes to the language itself, or whole-scale changes to the interpreter/compiler.

Re:Nix: An idea whose time has come by Izkata on Friday February 18, 2022 @10:19PM (#30394118)
For me it's a total lack of any description of the nix language. I just have no idea what I'm looking at, and nowhere (last time I looked, which I admit was some time ago) explained what tokens make up the language. Some showed that parts of the syntax were optional, but not what they meant.

Occasionally I'd find a guide that describes in English what a given example file is doing, and it kind-of made sense, but wasn't clear how it mapped to the file shown. There was a lot of magic going on with no explanation how it was getting there, so I could only assume there were semantics tied to some of the syntax that the writer assumed you'd eventually figure out... But they were just abstract enough that it didn't make sense in a way I could duplicate.

Re:Nix: An idea whose time has come by kaba0 on Saturday February 19, 2022 @05:10AM (#30395890)
The problem is not the language but the “standard library” used by it, which is quite ad hoc and organically built.

The language may not be the most intuitive at parts, but I feel that it is not the actual problem people have - I think what trips up people (me included) is that one pretty much grep for a similar package to be able to start doing the work. Why does a python derivation require this function instead of the generic one, what are the package names, etc. Some stricter structure would be welcome, in my opinion.

Re:Nix: An idea whose time has come by tazjin on Saturday February 19, 2022 @03:28AM (#30395386)
I wrote a Nix language tutorial a while ago and people keep telling me it works for them: https://github.com/tazjin/nix-1p
Re:Nix: An idea whose time has come by ris on Saturday February 19, 2022 @07:55AM (#30396796)
> For me it's a total lack of any description of the nix language. I just have no idea what I'm looking at, and nowhere (last time I looked, which I admit was some time ago) explained what tokens make up the language. Some showed that parts of the syntax were optional, but not what they meant.

Huh?

https://nixos.org/manual/nix/stable/expressions/expression-l...

Thing is, the language itself is really very simple.

If there's something missing, it's a guide to the contents of `lib` and how they should be used. Though there is a terse reference: https://nixos.org/manual/nixpkgs/stable/#sec-functions-libra...

Re:Nix: An idea whose time has come by viraptor on Saturday February 19, 2022 @12:36AM (#30394682)
Fortunately this is now in a much better state - have a look at https://nixos.org/guides/nix-pills/basics-of-language.html

It's not perfect and I raised some issues about fragments being written from the perspective of someone who knows the system - but it's definitely good enough for learning the language.

Re:Nix: An idea whose time has come by infogulch on Friday February 18, 2022 @08:56PM (#30393710)
I haven't tried it but apparently you can compile to Nix from Dhall:

> You can use this compiler to program Nix using the Dhall language. This package targets people who wish Nix had a type system.

https://github.com/dhall-lang/dhall-haskell/tree/master/dhal...

Re:Nix: An idea whose time has come by soraminazuki on Saturday February 19, 2022 @12:37AM (#30394687)
I don't think the Nix language requires understanding of functional programming. Overall, it's not so different from JSON. What is different is that it provides a few programming language constructs on top like variables, functions, and conditionals. This enables developers using the Nix language to properly abstract complex configurations in a comprehensible way, thus avoiding the pitfalls of writing JSON and YAML by hand.
Re:Nix: An idea whose time has come by n42 on Friday February 18, 2022 @08:01PM (#30393385)
you’re right. I guess I should qualify that with: what makes the language more difficult to approach as a newcomer.

once you’re in there, there’s a ton of warts, of course. I just hear complaints about the syntax so much that it really seems like people are more caught up learning functional programming than Nix. which makes sense, since most people who would need Nix spend their time writing Bash and Python

Re:Nix: An idea whose time has come by dwohnitmok on Friday February 18, 2022 @08:26PM (#30393528)
I think the problem is that the bad error messages make it unclear whether something is a syntax issue or a nixpkgs issue (this is somewhat worse with the dynamic nature of Nix, although I personally don't actually think Nix really needs static typing all that much, but that would be one viable way of fixing this).
Re:Nix: An idea whose time has come by freeopinion on Friday February 18, 2022 @08:31PM (#30393561)
In that case, what if you swapped out the language for, say, Scheme?

Does that help?

Re:Nix: An idea whose time has come by Ericson2314 on Friday February 18, 2022 @08:38PM (#30393603)
There is Guile for that.

The Nix language out-schemes scheme (even smaller), so I don't really see the point.

Re:Nix: An idea whose time has come by mbrock on Friday February 18, 2022 @11:53PM (#30394518)
One reason is that Scheme has Emacs modes that connect to a live system for precise jump-to-definition, etc. This works with Guix and is extremely convenient. Scheme's metaprogramming also enables Guix's beautiful system of code staging, G-expressions.

https://guix.gnu.org/manual/en/html_node/G_002dExpressions.h...

Re:Nix: An idea whose time has come by Ericson2314 on Saturday February 19, 2022 @11:52AM (#30398465)
> One reason is that Scheme has Emacs modes that connect to a live system for precise jump-to-definition, etc. This works with Guix and is extremely convenient.

Those are all valuable things, but I don't think that would actually be hard to implement for the Nix language either. Just no one bothered

> Scheme's metaprogramming also enables Guix's beautiful system of code staging, G-expressions.

Yes not pasting together strings for bash would be nice, but with all due respect to scheme's metaprogramming, which I do indeed highly respect, I view this as fairly orthogonal.

From a quick glance, g-exps don't have much binding structure? That means hygiene and other things are not as useful, and just doing

  ["see" "I" "can" "sexp" "too"]
in the Nix expression language isn't actually so bad.
Re:Nix: An idea whose time has come by rekado on Sunday February 27, 2022 @12:08PM (#30490239)
With G-expressions you can splice in computed store values, e.g. the computed output location of a package. I recommend the paper[1] explaining why they exist and what alternatives they replace.

[1]: https://hal.inria.fr/hal-01580582

Re:Nix: An idea whose time has come by dwohnitmok on Friday February 18, 2022 @08:43PM (#30393639)
It's not purely a language thing per se, i.e. there are ways the language could change minimally but error messages could have a huge leap in improvement. However, certain idioms in the standard library might need to change, and certainly changing the language at the same time can improve the error messages even more.

I have only a little experience with Guix (replacing Nix with Scheme), so I'm not very confident in this, but the shallow impression I have is that Guix's error messages are not much better.

Re:Nix: An idea whose time has come by khimaros on Friday February 18, 2022 @08:45PM (#30393648)
it sounds like you might be looking for Guix https://guix.gnu.org/
Re:Nix: An idea whose time has come by d3nj4l on Friday February 18, 2022 @09:14PM (#30393806)
I imagine GP was setting up to redirect there, given the very deliberate choice of language.
Re:Nix: An idea whose time has come by toastal on Friday February 18, 2022 @10:25PM (#30394159)
There’s also the PureNix project that lets you go from PureScript→Nix. Caveats in the docs.

https://github.com/purenix-org/purenix

Re:Nix: An idea whose time has come by tikhonj on Friday February 18, 2022 @08:01PM (#30393382)
> the difficulty people have with it is that it’s functional, not that it’s nix.

My experience is that the difficulty people have is with Nixpkgs as a library/codebase rather than the language itself. Poor error message, unclear abstractions, lots of things managed through implicit conventions rather than in the language itself... it's a massive legacy codebase with a lot of internal inconsistency and some questionable practices. I'm convinced that if you had a magic codebase-cleaning wand and kept literally everything else about Nix (the language, the model, derivations) the same, you'd fix like 90% of the problems people have with the system.

Re:Nix: An idea whose time has come by viraptor on Saturday February 19, 2022 @12:33AM (#30394675)
> the difficulty people have with it is that it’s functional, not that it’s nix

Not really - functional languages are ok. The problems I have are nix-specific:

- for documentation you need to read the source

- there's no debugger

- there are no sanity-checks in the system which means that some internal function deep down the stack says "attribute never_heard_about_it missing" and you have no context how it got there

- there's no type checking which results in the previous error on attribute foobar while you set attribute fobar and have no idea why things aren't working (or set {system}.{package} instead of {package}.{system})

Re:Nix: An idea whose time has come by hamandcheese on Friday February 18, 2022 @08:06PM (#30393421)
> the difficulty people have with it is that it’s functional, not that it’s nix.

I write plenty of functional scala. I still find nix to be rather impenetrable, largely due to its dynamic nature and unfamiliar syntax.

Re:Nix: An idea whose time has come by n42 on Friday February 18, 2022 @08:09PM (#30393439)
maybe that’s it; maybe it kind of sits in the middle where it tries to please everyone and ends up pleasing no one. not a great functional language, but functional enough to confuse you if you’ve never done functional and are expecting JSON.
Re:Nix: An idea whose time has come by carlmr on Saturday February 19, 2022 @02:54AM (#30395214)
I've written this before. The issue is not because it's functional at all. That's a proximate explanation that's just plain false.

Everyone I know that has tried Nix was a functional programmer first. Nobody had a good experience with Nix though.

If I could describe my issues with Nix it's that:

1. The syntax is odd. It's usually better not to stray too far from common programming languages if you want your language to be accepted.

2. You often find two examples which work individually, but they use a different way to do things, so it's hard to get them to work together in the same configuration.

3. A lot of examples depend on some specific functions, which are hardly explained at all. There seem to be a lot of these special functions that make it very hard to make a mental model you can work from.

4. The error messages are worse than C++ templating errors.

5. At least last I checked the documentation was really lengthy, but never gave a good overview of the language, only gave some inconsistent examples instead. In the end you don't feel like you learned something.

Re:Nix: An idea whose time has come by octoberfranklin on Friday February 18, 2022 @08:59PM (#30393739)
A bigger problem is that the command-line utilities (what git calls "porcelain") are full of jillions of inconsistencies. Some tools (nix-env) read ~/.nix-defexpr, others (nix-store) ignore it. Sometimes arguments are interpreted as filenames, sometimes as attrnames, and other times as a search query that nix will use to grind through some big list of package names.

The new "nix" command with subcommands ("nix env" instead of "nix-env") is much better, but has been stuck in "experimental status, breaking changes may occur at any time". Stabilizing the nix command syntax and deprecating nix-env/nix-store/nix-instantiate would go a long way.

Re:Nix: An idea whose time has come by rgoulter on Friday February 18, 2022 @08:39PM (#30393613)
> the language itself is surprisingly simple. the difficulty people have with it is that it’s functional, not that it’s nix.

I wrote down "what I wish I knew when learning Nix", and realised what had initially confused me:

Some people are confused by immutability when learning functional programming. e.g. Programs involve changing things, but then immutable stuff doesn't change.

With Nix, packages get built and installed to the store. In other solutions, this is done by running a command like "install package", or by having some file describing the package and running "install this"... but with Nix, packages are so integral to the language that they're built as part of just evaluating the language expressions, and (before flakes) the language didn't really have a "main file format" the same way that programming languages do, or that Terraform does.

With functional programming, pure functions have no side effects. With Nix, an implicit side effect of evaluating code is that packages are built.

Re:Nix: An idea whose time has come by tadfisher on Friday February 18, 2022 @09:46PM (#30393961)
Sort of. There are no real side effects, just lazy evaluation. Every entry point into `nix build` evaluates one expression to produce one output, but in the process, ends up evaluating the outputs of all the dependent expressions as well. The Nix store essentially caches the results of these evaluations, which looks very much like a traditional package manager "installing" packages to the file system.
Re:Nix: An idea whose time has come by aij on Friday February 18, 2022 @10:40PM (#30394233)
It's kind of like how an implicit side effect in "normal" FP languages is that memory is being allocated.

The nix garbage collector will even free up disk space by deleting unreferenced packages just like a garbage collector freeing memory by deleting unreferenced values.

Re:Nix: An idea whose time has come by remexre on Friday February 18, 2022 @08:00PM (#30393381)
idk, as a part-time Haskeller, I think Nix-the-language kinda sucks (tho not enough for me to not use nix). IMO the big huge thing is really inconsistent nixpkgs docs; compare linkFarm and symlinkJoin's docs, for example. I wish there were some way of getting nice autogenerated docs, but I don't think we're gonna get there without either adding some kind of type system or having a pretty strong review requirement that's actually enforced, and doing that for a year or more...
Re:Nix: An idea whose time has come by octoberfranklin on Friday February 18, 2022 @09:02PM (#30393751)
Plus the nixpkgs and nixos docs are generated from some weird hybrid docbook-markdown that mere mortals (well me at least) can't get to build. So we are stuck using the makes-my-eyes-bleed font on nixos.org, and the gigantic mile-long single-page manual format (which is nice sometimes, like for searching, but other times you want a TOC sidebar).

The documentation for the nix language is all done in mdbook, and is beautiful and easy to read. I wish the nixpkgs/nixos manuals were like that.

Re:Nix: An idea whose time has come by 1_player on Saturday February 19, 2022 @06:49AM (#30396400)
> makes-my-eyes-bleed font on nixos.org

AKA the curse of macOS designers that have that setting that makes all fonts a little bolder, so they think 300 weight is perfectly acceptable for a documentation site, while everybody else have to strain their eyes to read too thin a black font on eye watering white for hours.

Just go on nixos.org, remove the font-weight: 300 and see how much readable it is.

Re:Nix: An idea whose time has come by jfb on Friday February 18, 2022 @09:27PM (#30393880)
The problem is that the documentation is garbage.
Re:Nix: An idea whose time has come by qbasic_forever on Friday February 18, 2022 @08:13PM (#30393460)
It's a higher level issue, declarative vs. programmatic environment control. It isn't that sysadmins don't understand programming, functional programming, etc.--everyone is devops these days. It's that in the world of system administration we've gone through many waves and trends with significant backlash against complete programmatic definition of environments.

In the old days you'd exec a pile of shell scripts to go out and put your servers into the state you wanted. It was brittle, painful to understand, etc. Then things evolved into declarative definition of environments with tools like ansible. Now you just define the state of the world you want and ansible or other tools do the work to get the world into that state. This has evolved even further into declarative definition of entire distributed systems with kubernetes--you write out a pile of YAML that defines the state you want and kubetl and k8s controllers take care of making it happen.

So there are definitely people that understand the value of functional programming, but don't want it to define their environments. I don't want to have to grok someone's 'clever' solutions to figure out that ultimately they just want package x, y, z and software foo installed. I just want to list what I want and let the tooling make it happen.

Re:Nix: An idea whose time has come by dnr on Friday February 18, 2022 @08:34PM (#30393579)
> I just want to list what I want and let the tooling make it happen.

That's just what Nix does?

It's very much more declarative than any system I've seen. Yes, k8s turns your declarative manifest into running processes, but how was the image built? There's a huge gap there: you refer to container images by name, not by a description of the software you want them to contain, and then hope that some other process has built the image correctly. Nix can close that gap and take declarative all the way from the service manifest down to the git commit of the compiler used to build your binary.

Re:Nix: An idea whose time has come by rgoulter on Friday February 18, 2022 @09:07PM (#30393768)
The comment you're replying to describes concerns about maintenance burden from the programmatic nature of Nix.

I think "declared in YAML, pointing to a Docker image", and "declared in Nix, pointing to some more Nix elsewhere in the codebase" is relatively moot to this point. (If you wrote the image, you'll know what it's expected to do; if you don't know the Nix you're pointing to, it's as opaque as a Docker image).

Configuring with a program vs using a plain structured file have different trade-offs.

Re:Nix: An idea whose time has come by dnr on Friday February 18, 2022 @09:44PM (#30393953)
Does anyone write k8s manifests in raw yaml? They're so complicated that they're generated using some templating language (helm or kustomize or whatever is popular these days, I'm a little out of the loop). So you still have something programmatic. Think of Nix as just a better and more principled templating language. (I mean, look at NixOS configs: they're much closer to "plain structured files" than "programs".)

The promise that I see (I haven't seen this fully realized but it should be possible) is that instead of yaml plus some ad-hoc templating language plus dockerfile plus makefile, everything is in a single language top to bottom.

Re:Nix: An idea whose time has come by rgoulter on Friday February 18, 2022 @09:50PM (#30393979)
I think it's better to put in terms of trade-offs, rather than "this is better than that". https://mikehadlow.blogspot.com/2012/05/configuration-comple...

(I use NixOS btw).

Re:Nix: An idea whose time has come by rezonant on Saturday February 19, 2022 @02:19AM (#30395066)
Helm charts are basically just collections of k8s yamls, it doesn't serve to simplify them, only to make them parameterized
Re:Nix: An idea whose time has come by PoignardAzur on Saturday February 19, 2022 @07:25AM (#30396611)
> I don’t want to be dismissive. “nix but with yaml” is kind of like saying “rust but without borrow checking”.

I mean... your metaphor cuts both ways? A lot of work went into making Rust's borrow-checking non-intrusive, or at least softening its edges.

The big improvements were lifetime elision and non-lexical lifetimes, but there's also a ton of compiler errors for common cases that explain what went wrong, and often suggest an easy fix when there is one.

Last time I checked, Nix didn't really have this. If you get the syntax wrong, it doesn't tell you "oh, you tried to get 'ripgrep', you probably meant 'nixpkgs.ripgrep'".

Re:Nix: An idea whose time has come by xyzzy_plugh on Saturday February 19, 2022 @09:11AM (#30397240)
> Last time I checked, Nix didn't really have this. If you get the syntax wrong, it doesn't tell you "oh, you tried to get 'ripgrep', you probably meant 'nixpkgs.ripgrep'".

I get where you're coming from but as it stands there is no universal description of what "nixpkgs" means in this context. It's a channel, defined only in the context of your environment. Your nixpkgs isn't my nixpkgs. It's just a channel label.

Imagine you typed

  curl "PoignardAzur" 
compared with entering the same value into your browser's address bar. Would you expect to end up on your HN profile page in either case?
Re:Nix: An idea whose time has come by PoignardAzur on Sunday February 20, 2022 @09:37AM (#30406020)
... Okay? You're basically telling me "there's fundamental reasons Nix has these properties that make it annoying to use".

And, okay, I believe you, but the end result is I don't want to bother.

Re:Nix: An idea whose time has come by xyzzy_plugh on Sunday February 20, 2022 @02:10PM (#30408370)
I think what you're missing is that instead of providing the convenience behavior you're looking for, a more powerful primitive is available. Any other package manager has a bloated song and dance where if you want to install something not in the official repo, you either:

- download and install it manually - add a new third-party repository and install it from there.

Then, whenever you perform a distro upgrade, you have to repeat the entire process because the repo has changed, subtly.

Instead, nix eschews this concept by allowing you to install whatever you want. Imagine running Ubuntu 18.04 and wanting to install a package from Ubuntu 20.10. Have fun with that! Nix not only makes it possible, it makes it as easy as installing anything else.

I now consider "foo install ripgrep" a mistake and an anti-pattern. I now find those tools annoying to use. Could nix be better? Certainly, but you're really giving me a "it's different so I hate it" vibe. Give it a chance.

Re:Nix: An idea whose time has come by PoignardAzur on Monday February 21, 2022 @06:14AM (#30414429)
> I think what you're missing is that instead of providing the convenience behavior you're looking for, a more powerful primitive is available.

That's great, but I still want the convenience behavior.

> Give it a chance.

I tried. I kept getting papercuts, and things that were easy on PopOS were annoying on NixOS. That wouldn't deter me if I needed to use Nix, but as it is PopOS works perfectly for me and I have no reason to switch. I might still try out of curiosity, but I'm honestly not feeling that enthusiastic.

(I actually documented my experience here, if you're curious: https://poignardazur.github.io/2021/09/08/nixos-post-mortem/)

But that kind of response that boils down to "you just think that way because you haven't tried it" or "the reason the UX is so incredibly obtuse is because of the underlying model" seriously annoy me.

You can have plumbing and a porcelain. Nix currently is lacking on the porcelain side. The idea that you have to study the entire programming model of an OS (not just vaguely understand it, which I do, but study it) to use it, and if you think it's not worth the effort, it's because you haven't tried it yet, is inane.

Re:Nix: An idea whose time has come by xyzzy_plugh on Monday February 21, 2022 @10:08AM (#30416640)
I'll be honest: I don't understand why you wanted to try NixOS out in the first place. It sounds like Pop!_OS works for you? Great! Enjoy. It doesn't work for me.

Not that you're asking, but I found your review pretty uncharitable. You pretty clearly don't want any of the benefits the Nix ecosystem provided. NixOS is not competing with Pop!_OS, and I wouldn't recommend to non-technical users. It really sounds like you want to use snap or flatpak, so I'd recommend those -- they also work well on NixOS.

As for your review, in particular:

- you changed the desktop environment from the default, which is fine, but a lot of your problems are the result of that choice. The default is KDE, and I find it works perfectly well. How does Pop!_OS fare if I install XFCE?

- lengthy rant about /bin/bash vs /usr/bin/env bash, I found boring since the latter has already won as far as I can tell, and righteously so. The whole point of NixOS is to deprecate a traditional FHS, and then you complain about the lack of FHS. Okay.

- You give up on Steam immediately. I run Steam rather successfully and I've managed to play more games on Linux than ever before, I can count on one hand the number of games I've been unable to start, and it's usually because of shitty DRM.

- you don't understand the difference between nix-env and configuration.nix, so I don't think you read the manual.

- you just want to use existing dotfiles/configuration instead of learning how home-manager workapo

- you describe difficulties getting the VLC developer environment set up, but the instructions were not written for NixOS. What are you hoping to accomplish? The Nix way would be to open a shell for the VLC derivation, which works fine without installing Docker. You didn't even try this.

- you somehow don't mention the most obvious pain point everyone runs into, which is that you can't usually trivially download and run binaries as there is no FHS, so binaries don't know where to find runtime dependencies.

> The idea that you have to study the entire programming model of an OS (not just vaguely understand it, which I do, but study it) to use it, and if you think it's not worth the effort, it's because you haven't tried it yet, is inane.

Have you used MacOS before? How did you get started with Linux? Why is Pop!_OS intuitive to you?

You don't need to study, but you need to develop and foster an understanding of how the systems operate. This has always been true. This system is different, but you want it not to be. You're installing your own operating system but then expect to be pandered to. You're seriously exaggerating the effort involved.

Ultimately this isn't a productive conversation. You're not interested in change without a seamless transition, which NixOS does not purport to offer. It's been around for a while, sure, but it's been a pet project for most of its life. Debian is nearly twice as old, and Ubuntu built upon Debian, and Pop!_OS built upon Ubuntu. They're all pretty much the same. NixOS is quite different. In time, we'll see the same polish along with spin-off distros.

Re:Nix: An idea whose time has come by arianvanp on Saturday February 19, 2022 @07:29AM (#30396632)
Funnily enough the author of nix kind of seems sad that they made nix a programming language and has been Experimenting with a TOML frontend.

And also been Experimenting with a new more specified language called Nickel