r/NixOS • u/AdventurousFly4909 • 7h ago
The nix language is incomprehensible
I know three languages(Lua, Python and rust), which I know isn't a lot but at this point in my journey it's very easy to learn a new one. But nix just escapes my grasp, there are so many weird things and the documentation is so horrible. The complex packages like VSCode fhs and the fhs that wraps other packaged are insanely confusing and then there's complex flakes which have tests and have them run a vm. And then it just stops working and it spews forth a unreadable error message that makes you want to clamp your balls in a vise. Not to mention dentritic pattern with all It's helper flakes that have god awful documentation so you just end up reading the source which is incomprehensible.
Maybe it's just because I am not used to functional programming.
Nevertheless I am still going to keep using NixOS and with each year that passes I will understand more.
74
u/Old-Ad-9064 7h ago
You know three languages that are very similar and then struggle to learn one that’s completely different it makes sense that it’s harder.
9
u/grovemau5 7h ago
In many ways nix is more similar to Python/Lua than rust
8
u/godofpumpkins 6h ago edited 4h ago
Eh. It’s ~purely functional and lazy but also dynamically typed. I’d say the purely functional part takes the most getting used to for someone with OP’s experience. The dynamic types make it more similar to python and lua but that’s pretty much where the similarity ends. If anything probably closer to scheme or lisp in that regard
2
1
u/SpotCool4422 20m ago
A few years ago I spent some time learning Haskell (quite a language by the way!). With that knowledge, Nix language itself was a walk in the park. It's incorrect to compare purely functional languages to the likes of Python, although Rust was at least partially inspired by Haskell and in theory might have some concepts borrowed from it. Still, it's a skill issue on the OP's side.
9
u/M8Ir88outOf8 7h ago
To me, the syntax is quite ugly and not self-describing. But I think easy of use is a function of familiarity, I am sure that with more experience, it becomes more obvious
-3
u/AdventurousFly4909 7h ago
I mean yeah the functions are defined i need a weird way with also weird syntax for the body. Predicates are also weirdly defined. All very weird syntax.
21
u/EarlMarshal 7h ago
Nix isn't that bad. It's just functions and objects and some set handling. Reading languages is a dependent on experience. You have none. Why do you expect to be fluent with it? Take a look at prolog and Haskell. You wouldn't understand them either.
Enjoy learning something new.
7
u/AdventurousFly4909 7h ago
If I actually could make some programs with it I would learn it faster but everything is undocumented and the things I want to work on are also highly complex. So that's a fun combination.
I mean have you looked at the fhs packages and the fhs wrapper itself?
8
u/ItsThreeRealEstate 6h ago
The core of the language is very small and there is plenty of documentation + third party tutorials for learning it. It's roughly the same complexity as Lua I feel.
nixpkgs, however, has tons of extremely dense/powerful abstractions which can be hard to wrap your head around.
3
u/plethepus 7h ago
Try nix repl. Get some iterative feedback with simple expressions to help build some momentum.
1
u/thussy-obliterator 5h ago
yeah i rly don't get the hate, it's mostly fine and doesn't have a lot of suprises as far as pure functional / lazy / dynamic languages go. it's a pretty cute language.
7
u/Interesting_Dream_83 3h ago
nix is probably the worst functional language there is. good thing is tho 99.9% of the time you will use it as a configuration language and as a configuration language it's ok
6
u/Leading_Yogurt7025 7h ago
luckly nix is very well supported by AI so you don't have to read it /s
2
u/AdventurousFly4909 7h ago
Even if it did I wouldn't want to use it since I want to understand nix so that I actually own my OS.
4
3
u/sf1tzp 3h ago edited 3h ago
You could use a working, AI generated, nix module as a starting point though. Tear it apart and "deep dive" into every line of it until you can confidently talk about how it works and why. If the AI generated module doesn't work exactly how you want, you can then make your own edits to it, etc.
Edit: This is a worthwhile skill to practice even outside of nix. Replace 'AI Generated' with 'Code my coworkers wrote' and it's still worth doing the deep dives on any of the code you share responsibility for.
0
u/ItsThreeRealEstate 6h ago
Tbh I don't think this should be sarcastic. AI is breaking down barriers and, somewhat ironically, allowing a lot more people to enjoy the benefits of determinism and reproducibility.
1
u/KasztanowyBoi 42m ago
Well yeah, AI as a tool for your own usage is good. I wouldn't trust it with critical stuff, but as a "tutor" and personal code maid (lol) it is a revolutionary tool to have. I was able to learn how nix functions and how it looks, what everything does thanks to it. Now I just learn myself with some nix courses and if I dont get something I ask AI to explain but I write the actuall code myself. And if u want something setup in your config, but don't want to bother it is also soon nice to just do anything you want in seconds with it (and then copy and paste error codes cuz the stupid clanker hallucinates, saying "this is an absolute nix classic") xD
5
1
u/landonr99 5h ago
I've worked professionally for 4 years in C, C++, C#, and Python, and it took about a year for Nix to click for me. It is a totally different and weird way of thinking and it's not at all like the traditional academic and professional object oriented programming world where learning one language translates easier to another. Just keep digging into as many different sources as you can, the more angles of understanding you approach from the better. And ultimately, just like any programming language, I didn't truly understand nix until I tried to write my own derivations. You will fail your first times, just like you would in any other language, but keep at it and I promise it gets easier and starts to make sense and you may eventually see the beauty in its simplicity that yields complexity. It's like a fractal, rabbit hole and I personally think that although it can be frustrating, it really is beautiful and incredibly interesting at the same time. Don't give up, the agitation you feel when learning is actually an essential part of the learning process.
1
u/DerekB52 5h ago
I've tried to use Nix twice and given up both times because the language is a little involved. I'm sure I'd gain understanding with time, but as someone who just needs one or two computers, I didn't see enough of a benefit. I'll try again at some point.
1
u/NTolerance 4h ago edited 4h ago
For the use case of just having a declarative system, it could not be more complex. I just want to deploy some software and configs to some systems. I don't want to see any of the upside down and backwards functional programming when I do this, or the obtuse error messages.
At any rate, I just try to keep all the wacky stuff in my flake.nix with the help of a LLM, and then every other file is just a config, no logic ever. Every platform (nixos/darwin/home-manager) gets its own flake.nix so it doesn't get too crazy.
Oh, and I template and deploy all the nix files to hosts using Ansible, fight me.
1
u/Luna24_ig 4h ago
You’d probably be interested in the package manger I’m building for my own distro, SilkOS. It’s nix like and declarative, but uses Lua so it’s easier for people to pick up and use. I hated using nix lang when I used nix and it’s why I stopped using it. Still a great distro and nice for nix, just not my preference
1
u/jerrygreenest1 2h ago
I kinda agree but once you stop thinking about it as a programming language and think of it as what it is – a configuration language, then a lot of this hate for language disappears. At least for me.
You just shouldn’t do programming with it, or anything complex. Once you do something complex with it, you gonna have a bad time. But as long as you use it for its initial purpose, it is okay.
Of course it’s more of a way to cope rather than justify anything. I still think Nix the language could have been designed better. Yes. But these are just words and to actually do it – is always harder than just talk.
1
1
u/pr06lefs 1h ago
I think a lot of the difficulty is in the mechanics of packaging, not the nix language per se. A lot of the action is behind the scenes, or implicit in the build process. The source dir for the package, the build directory for the package, the output directory for the package, the 'derivation' and whether its evaluated yet or not, etc. All the build phases of the packages and how to override. There's just a lot to keep track of.
1
0
1
u/ppen9u1n 5h ago
I don’t really understand why people whine so loudly about nix. It’s just a DSL that has been rightfully characterised as “JSON with functions”, and it’s perfectly adequate for what it’s supposed to do.
Could the failure messages be much better? Absolutely! This is an evaluation/interpreter issue. Could the documentation be better? Probably, but the reference is not bad.
This has nothing to do with the language as such, however.
1
u/ItsThreeRealEstate 5h ago
I think it's the laziness and abundant recursion that makes people uncomfortable.
1
1
u/ItsThreeRealEstate 6h ago
I'm not sure what all this dentritic stuff is about. I've been using nix personally and professionally for 7 years and the only people I see talking about it are noobs who just started using Nix. I'd say stick to the basics, and wait til you experience pain before you adopt any sort of framework. If you can't articulate in your own words what problems dentritic solves for you, get some more experience with the basics.
1
u/IDontBelongInThsWrld 5h ago edited 5h ago
The only modern language that’s more disgusting in its presentation is Lean. And I really mean presentation - Java was designed by bureaucrats, so it’s infinitely worse in all other aspects. And I love the concept of Lean, the formalisation of mathematics and the structures behind it, but it clearly was designed by mathematicians with zero comprehension of good programming practises, everything super-terse and unreadable. I say this as a professional mathematician and hobbyist programmer.
There’s something similar to the Nix language: it’s too terse, not self-explanatory. And the documentation isn’t great. Worlds apart from Rust - a great language with generally good documentation culture.
-1
0
0
u/jejunerific 3h ago
I would suggest building out your own configuration organically. Don't steal the dendritic libs because then you'll never get to understand what is going on. The only nix lib I use is uv2nix and it is painful but at least it mostly works.
Totally agree about the error messages and layers of stuff mixed. Just gotta slog through the nixpkgs patterns and use the repl a lot.
-1
u/silver_blue_phoenix 6h ago
Are you frustrated with nix the language? Or nix the ecosystem? Cause nix language is very ugly yeah; but it's pretty easy to understand i'd say. What you are complaining about is the nix ecosystem.
Yes, documentation is non-existent pretty much. LLMs are helpful in doing evals and trace where errors etc come from actually; i would give it a try. I'm trying to set up a local model to do this automatically at the moment.
Nix ecosystem is about functional paradigm to everything. For people who are used to more popular programming languages/paradigm (i'm in the boat too) it's very hard to get into. On the other side; the good practices are baked into the ecosystem. When I used to use arch; i could not build half of all AUR pkgbuilds; because they would not build in clean chroots; and usually the pkgbuilds out there is a script kiddo's first try in software. (Most AUR packages are so badly packaged that I just ended up writing my own pkgbuilds all the time) You can still write a sloppy derivation (there are still a bunch in nixpkgs that I run into every now and then) but there is a limit on how bad you can be due to the architecture. Unfortunately; that also leads to having to do weird esotheric stuff to make stuff like vscode work with nix.
-1
u/toastal 4h ago edited 2h ago
Nix is the ugly sibling in the ML family tree—but even with dynamic types, no module system, & inherit keyword, it’s ultimately just another functional language. I find it most similar to OCaml & Nickel in the space personally, so you could try out one of those to see the similarities & how Nix just isn’t that different …just different relative to the languages you know.
Also flakes are complex, unstable/experimental, & now forked in incompatible ways (Nix, Lix, Dix)… you probably don’t need them since 95% of the features can be accomplished without & instead you can adopt concepts piecemeal as you wish to learn about the topics. You’ll often find simple imports, callPackage, & overlays are not only simpler to understand once you get the concepts, but make your project more modular, & easier for consumers to pick out the bits they want. You shouldn’t touch flakes until you grasp all 3 of these concepts IMO… then your flake.nix, if you choose to use one at all, is just a thin re-exporting layer on stable Nix code. This is why none of the official docs/tutorials recommend learning flakes; Reddit is a hivemind that recommends despite it going against upstream’s recommendations (blind leading blind).
Flakes are an experimental extension format with outstanding issues. Its functionality can generally be achieved without them as well.
-1
u/Ambitious_Ad4397 5h ago
I agree that debugging can be.. cumbersome in nix, but official nix/NixOS manual, explains everything quite good
81
u/Guardian-Spirit 7h ago
I'm a functional programmer professionally, and, to be honest, I use NixOS as my daily driver and constantly write nix flakes for my projects, but I just deeply, utterly hate Nix-the-lang. I don't understand the point of this dynamically typed fixpoint mess.
I mean, I understand why was it done like this, but I just can't believe they couldn't come up with something that maybe isn't as eloquent, but at least is somewhat robust & predictable.