top | item 43640250

(no title)

gadtfly | 10 months ago

Completely unrelated to anything I'm just taking this as an opportunity to yell this into the void while nix is on topic:

I have a theory that a problem for Nix understanding and adoption out of all apparent proportion is its use of ; in a way that is just subtly, right in the uncanny valley, different from what ; means in any other language.

In the default autogenerated file everyone is given to start with, it immediately hits you with:

    environment.systemPackages = with pkgs; [ foo ];
How is that supposed to read as a single expression in a pure functional language?

discuss

order

angra_mainyu|10 months ago

To be fair, that is not problematic at all and most definitely not what I think is the issue with Nix adoption/learning curve.

Personally, it's the fact that there are 57698 ways of doing something and when you're new to Nix you're swarmed with all the options and no clear way of choosing where to go. For example, the docs still use a shell.nix for a dev shell but most have moved to a flake-based method...

I always recommend starting with devenv.sh from the excellent Domen Kozar and then slowly migrating to bare Nix flakes once you're more accustomed.

eru|10 months ago

> How is that supposed to read as a single expression in a pure functional language?

Well, in Haskell the following is technically single expression:

    do with pkgs; [ foo ];
(Eg using 'let {with = pure; pkgs = 1; foo = 2}' makes the above type check and compile.)

But extreme nerdery and nit-picking aside, I agree that the choice of syntax in nix unfortunate here.

mplanchard|10 months ago

Personally I think a bigger problem is the lack of discoverability of things in nixpkgs, which hits you as soon as you start writing anything remotely non-trivial. "Things" here means functions in 'lib', 'builtins', etc., as well as common idioms for solving various problems. I think this combines with the language's lack of types to make it hard to know what you can write, much less what you should write.

A language server with autocomplete and jump-to-definition would go a long way to making nix more accessible. As it stands, I generally have to clone nixpkgs locally and grep through it for definitions or examples of things related to what I'm doing, in order to figure out how they're used and to try to understand the idioms, even with 4 years of running NixOS under my belt and 3 years of using it for dev environments and packaging at work.

418tpot|10 months ago

I agree the syntax isn't perfect, but in case you're actually confused there's really only 3 places where semicolons go, and I would argue that two of the places make a lot of sense— as a terminator for attribute sets, and a terminator for `let` declarations.

Unfortunately it is also used with the somewhat confusing `with` operator which I personally avoid using. For those of you who aren't familiar, it works similar to the now deprecated javascript `with` statement where `with foo; bar` will resolve to `bar` if it is in scope, otherwise it will resolve to `foo.bar`.

chriswarbo|10 months ago

I actually prefer `with`, since it fits better with the language:

- It uses `;` in the same way as `assert`, whereas `let` uses a whole other keyword `in`.

- It uses attrsets as reified/first-class environments, unlike `let`, which lets us do `with foo; ...`.

- Since it uses attrsets, we can use their existing functionality, like `rec` and `inherit`; rather than duplicating it.

I've been using Nix for over a decade (it's even on my phone), and I've never once written a `let`.

(I agree that the shadowing behaviour is annoying, and we're stuck with it for back-compat; but that's only an issue for function arguments and let, and I don't use the latter)

pkulak|10 months ago

Your p,k,g,s keys must be worn to nubs.