In terms of learning specifically the language itself, so you understand complex nix files a bit better, I think the process is something like
- Use the basic constructs as copy-pasted from various places
- Gain a basic understanding of what attrsets are and how you can operate on them
- Become confident in browsing the reference docs for the “standard” library functions, both in nixpkgs and the nix manual
- Start understanding more exotic constructs like
inherit
, let in
, @ attrs
, with
, …
- Figure out function declarations, function calls,
import
s
- Understand the difference between NixOS modules and normal nix code, including inline module definitions
- Read the nix pills and figure out
callPackage
Not necessarily in order… But I think those are the core competencies you’ll build up to tackle arbitrarily complex nix files. Understanding of concepts like the nix store will slowly trickle in as you experiment, too.
Part of the complexity is definitely figuring out functional programming languages if you don’t have any background in them. While I generally think it’s a good fit for the types of work we do with nix, I’ve also definitely often heard long-term programmers complain about having to think “backwards”. It can take a while to adjust to how these languages work, even with relatively simple ones like nix.
Don’t get too intimidated, start with simple projects. Packaging simple things like fonts or templated configuration files is much simpler than fully compiled projects, let alone rust/python/java/go/whatever, and you should probably try writing modules before going on to more complex packages. Once you’ve figured out basic packaging and modules, you can then go on to writing functions that build the same thing in subtly different ways, your own specialized composite builders (for tests for example), modules that change based on some input data, etc.
Also never underestimate the value of reading existing code. If you need to figure out how to do something, go see if someone has done it in nixpkgs before, and read their code.
I’d also caution you from trying to understand third party projects like dream2nix, poetry2nix, niv, the various flake “helpers” & co until you understand roughly how they work - projects like those obscure what’s going on under the hood, so you won’t really understand what’s happening if you don’t get the basics yet. You can still use them, of course, but don’t feel bad if you’re just copy-pasting code. They’re not simple.
Despite everybody’s complaints, the nix, nixos and nixpkgs manuals are quite good, by the way. Once you start understanding the nix manuals’ explanation of the language and how it maps to things you’ve written you should consider yourself pretty much there.