Hacker News new | ask | show | jobs
by pasc1878 685 days ago
I understand Nix the language if it is all in one file.

But try to call one file from another - it is confusing - the parameters are not explicit like a function call - they suddenly appear - adding more arguments is odd. Modules are not simple imports they add options and config to "help" you.

I do wish they had used a well documented language with some form of modules rather than invent their own idiosyncratic one.

1 comments

Nix-the-language imports are dead simple: https://nixos.org/guides/nix-pills/05-functions-and-imports#... - `builtins.import ./foo.nix` makes it like we had `./foo.nix` copied and pasted in place of it. If we want to pass something, we make contents of `./foo.nix` a function (thus the frequently seen `import ./foo.nix {}` or `import ./foo.nix { inherit bar; }`).

It’s the nixpkgs’ module convention system that is a little bit less straightforward as it relies on some conventions: https://nixos.wiki/wiki/NixOS_modules#Module_Imports_vs_buil...

Oh, and Flakes have inputs (which are closer to built-in module system, as IIRC Flake support is baked into Nix itself rather than being a part of Nixpkgs like the module system), which is another different convention, but it all boils down to using `builtins.import` somewhere deep down the chain, all extra semantics in the libraries.

Again, I would've preferred a language with module system built-in but it's not a bad design either - it's just minimalistic. IMHO, Ruby and Perl can be more confusing than this - and they're still sane (if we don't intentionally start having fun with their metaprogramming capabilities). But then Flakes probably wouldn't be a thing, so minimal core has its advantages too. Or disadvantages, as it all depends on the viewer.

Either way, it’s all well documented. I still forget how it works now and then, but that’s my memory/attention span problem rather than a Nix/Nixpkgs issue.