6 ms·
I love Nix. NixOS is my primary development operating system. However, the Nix language itself is syntactically ugly, and this proposal makes it even uglier. Pa
by atemerev 9y ago
I love Nix. NixOS is my primary development operating system. However, the Nix language itself is syntactically ugly, and this proposal makes it even uglier. Parentheses, sigils and special characters (esp. semicolons) are line noise — the less of it the better.
Why they wouldn't take the most (syntactically) beautiful functional programming language out there — Standard ML? It would work perfectly for such a task. Or the second contender — Haskell. If C-like syntax is desired, the best contendant is probably Swift.
I cringe every time I have to edit a .nix file (and I have to do it a lot).
- jajern 9y agoIt's one of those languages that a developer can look at and think "Oh, so this is how non-developers see code".
- joombaga 9y agoIt looks like someone threw a pinch of erlang in a Chef recipe. Like bash, but every English word operator has been replaced by space ships, angry squids, ternary operators, && all the other things that make code hard to read. But... I still love Nix, and you get used to it.
- atemerev 9y agoBash is still worse. Probably. I know it is ubiquitous, but if I can avoid writing Bash scripts, I do.
- kmicklas 9y agoI have no idea why you would think that. It's pretty standard usage of punctuation like (){}[] etc. If it's hard to read that's because the libraries and infrastructure for writing derivations is not simple or well-documented. But that's not a language issue.
- agumonkey 9y agoYou tried guix ? I still have a fondness for sexps, but ML would be nice too.
- atemerev 9y agoI need CUDA drivers for what I am working with, and I have found no way to install it in Guix. Otherwise, it looks interesting enough. (Sexps are usually not my first choice, I think it is a "lazy option" for people who do not want to write parsers / design their own syntax. Even then, they are better than current Nix expressions).
- agumonkey 9y agoSome academics say that sexp allow to focus on what's important: semantics. I kinda agree with that, so many time, effort is wasted on syntax that moves, and only make ideas further apart. Anyway, thanks for the answer
- atemerev 9y agoWell, right, but we are not talking about an academic paper here, we talk about practically convenient language. If syntax is unimportant, we could leave Nix files as is -- semantically, it is a good programming language. But judging from the comments, I am not the only one who thinks that syntax and overall esthetics are important.
- zeveb 9y ago> Sexps are usually not my first choice, I think it is a "lazy option" for people who do not want to write parsers / design their own syntax. There are some real advantages to having one universal syntax: witness the explosion in XML and, later, JSON (both of which are generally inferior to S-expressions[1]). It'd be pretty great for one person to write one parser, and then everyone forever after to be able to use it. We'd be able to focus on semantics and not on syntax. [1] Although it is nice that JSON supports first-class associative arrays.
- corysama 9y ago
- KitDuncan 9y agoHonestly that's the only thing that keeps me from jumping to NixOS. I don't want to learn a weird language, I'll never use for anything else, just to maintain my OS.
- rnhmjoj 9y agoThe language is so simple you can learn all of it in a day. Read through chapter 15 in the nix[1] manual and that's it. To me it doesn't feel weird at all: I can't think of any feature that was new or surprising when I started using it and I am not the biggest expert of functional programming. You have to learn more about the standard environment and tools if you want to start contributing to nixpkgs and write your own packages but if you only care about configuring your system nix is as difficult to learn as say, JSON. [1]: https://nixos.org/nix/manual/#ch-expression-language https://nixos.org/nix/manual/#ch-expression-language
- atemerev 9y agoIt is definitely not difficult to learn, just somewhat hard to read and visually unappealing :)
- adrianmonk 9y agoPersonally, I'm not against the idea in principle. There are some real DSL-haters out there, and I'm not one of them. For a different problem domain, a different language can be more efficient. It's true that some DSLs are not only different, they're also badly-designed languages or gratuitously different. I guess this is an occupational hazard of DSLs, but it's not unavoidable. It's possible to make the leap to a DSL only when actually beneficial and then to design a DSL that doesn't suck.
- regnat 9y agoHi, author here. While I agree that the language could be improved, I wonder why you say that this makes it uglier, and how you'd imagine a better solution (this is still in development, and any idea is welcome).
- atemerev 9y agoIs there any option to break source-level compatibility? (Automatic translation to old syntax will still be possible and seamless, of course). If yes, I can draft a proposal.
- regnat 9y agoUnfortunately no, except maybe for some very minor tweaks that have a chance to be included in vanilla nix, but otherwise this would most probably either mean the death of this project or a split in the (already small) community, which I both don't want to see
- atemerev 9y agoCommunity could be larger if all these petty things were resolved :) But I understand, forking is definitely not an option. So, if only gradual changes are allowed, I would have started with: - making semicolons optional - commas for implicit array literals (e.g. "a", "b", "c" in lieu of ["a" "b" "c"] - something to do with 'with' / 'in' syntax. In fact, I can live with anything, except non-optional semicolons. Is there a possibility to infer them?
- tonyarkles 9y ago> In fact, I can live with anything, except non-optional semicolons. Is there a possibility to infer them? I'm genuinely curious... what makes that a dealbreaker?
- atemerev 9y agoJust look: https://gist.github.com/atemerev/889806081ed8fcb77495666fac9930e5 https://gist.github.com/atemerev/889806081ed8fcb77495666fac9...
- dtwhitney 9y agoI could not agree with you more! I use nix daily, and every time I go to edit it a nix file a voice in the back of my head says, "you should really start that Haskell to Nix compiler you've been thinking about." [edit] ha! just notice the next comment talking about hnix. Great minds... :)
- regnat 9y agoYou might be interested in dhall[0] and dhal-to-nix[1] which provides a really neat haskell-like language that compiles to nix. [0]: https://github.com/Gabriel439/Haskell-Dhall-Library https://github.com/Gabriel439/Haskell-Dhall-Library [1]: https://github.com/Gabriel439/Haskell-Dhall-Library https://github.com/Gabriel439/Haskell-Dhall-Library
- atemerev 9y agoIf only Haskellers knew that "a blog post" and "type definitions in Hackage" are not documentation... Also, the comma-first syntax like { foo = "bar" , baz = "qux" } drives me nuts. In the name of all good things in the world, why?
- radarsat1 9y ago> comma-first syntax oooh but this is one of those trivial things that I really liked in my brief days of using Haskell, and that has sometimes carried over to my C++, e.g. in initializer lists. I find it super useful because everything lines up nicely, and from the point of view of version control you don't have to edit the previous line to change '}' to ',' when adding a new line.
- coldtea 9y agoHow about allowing for bloody danging commas?
- wereHamster 9y ago
- zimbatm 9y agoIf I only look at the language properties then Nix makes sense to me. The fact that Nix is lazily evaluated allows for easy composability. This is used a lot in nixpkgs to allow overrides and build up packaging layers. And because the language is interpreted, only the files that are being used need to be evaluated. It wouldn't be very practical to hold all of nixpkgs in memory. It also allow to do things like dynamically import code from another git repo. And finally, the language only allows side-effects through derivations. None of the above language have all these properties combined.
- atemerev 9y agoI am only talking about the syntax. Semantically, Nix absolutely rocks.
- mbrock 9y agoI love the Nix language and I generally distrust aesthetic feelings about programming languages. Neither SML nor Haskell are optimized for expressing deeply nested records with many string literals, for example. The multiline interpolated strings in Nix are extremely much better than in SML or Haskell. The way records and arrays are written is great: SML and Haskell both suffer from the tedious problem of using separators between items instead of after each one; in Nix each item can always be moved without messing with separators. I think Nix is an engineering marvel up to and including the language design. If you can make a better surface syntax and demonstrate it by translating some significant part of Nixpkgs, I'd be very interested, but I think in general the language is the way it is because that's what made most sense for the system's designers.
- codemac 9y ago> If you can make a better surface syntax ... http://gnu.org/s/guix http://gnu.org/s/guix Lisp is pretty good at lists. The only important language is the derivation language sent to the daemon. Nix spends so much time building up inputs... for shell scripts. I always felt like they would have been so much more successful if they chose some other, more popular language to generate derivation.
- pmahoney 9y agoI may be in the minority, but I like the Nix language. I don't have extensive ML or Haskell experience, coming from Ruby/Java background. I think the Nix language works great as a configuration language, and I greatly prefer it to JSON, YAML, or Ruby, which are often used for similar purposes. The way arguments are passed in, merging of attribute sets, the library from Nixpkgs with various list and set operators and other utilities, and great multiline string support make it far superior to those other config languages in my opinion. My biggest gripe is that the Emacs mode isn't very strong, so I'm often applying indentation manually. I recently learned about Jsonnet[1] which has some similarity with Nix. [1] http://jsonnet.org/ http://jsonnet.org/
- thinkpad20 9y agoReally? I write almost nix every day at work and I have no problem with the syntax. I think it's pretty elegant and well-suited to its use case. There are a few minor tweaks I would make but nothing big at the syntactic level. EDIT: probably the only gripe I would make is to have comma-separated lists instead of having to use parentheses to separate non-atomic expressions.
- kmicklas 9y ago> probably the only gripe I would make is to have comma-separated lists instead of having to use parentheses to separate non-atomic expressions. Wait no separators are evil. This is the best thing about the syntax.
- adultSwim 9y agoAside: I would love it if ML caught on. Such a good balance between expressiveness and usability. Imagine if Caml had caught on in the 90s instead of Java...
- mintplant 9y agoThis is why I'm very much interested in Guix and GuixSD, which use Guile Scheme. Unfortunately I don't think they have an officially-supported story for running on the server, yet, or an equivalent to NixOps.
- runeks 9y ago> I cringe every time I have to edit a .nix file (and I have to do it a lot). No need to cringe over syntax. Syntax is just syntax. If you are familiar with a better syntax to express Nix in then create a parser from that format to Nix' syntax. Then insert this parser as a pre-processor in the build process, and problem solved.