1. 23
  1.  

    1. 8

      This seems like a great talk for beginners. My feedback is not aimed at beginners, but at Nix evangelists.

      Because there were no other options at the time, Nix uses its own programming language also named Nix to define packages.

      This doesn’t quite sound right to me. While Eelco’s thesis doesn’t directly refute this claim (say, on p69), it does explain that the Nix expression language is the simplest possible language which has all of the necessary features, and it also explains why each individual feature (laziness, recursive definitions, attrsets, functions, etc.) are necessary for defining packages. The thesis also explains why languages like Make are unsuited to the task.

      A NixOS module is a function that takes the current state of the world and returns things to change in it.

      This is perhaps too imperative to be true. NixOS configuration is generally monoidal, and often commutative (or configuring underlying systems which commute, e.g. networking.firewall.allowedTCPPorts which is sorted by the iptables subsystem.) It’s important to not give folks the false impression that adding a NixOS module is like adding a SysV init script.

      1. 8

        The with keyword certainly could’ve been removed from the language without removing expressiveness. I’d even say the language would be better for it.

        1. 7

          yeah a lot of good language design is saying no to features or syntactic decisions because of concerns that seem very abstract, because past experience has shown they have far-reaching negative impact

          with is in that category and should be removed, imo. I find it super convenient but that does not outweigh the loss of referential transparency. there have been a few proposed replacements, some of which are kind of okay although nothing perfect, but at the end of the day it’s a damaging feature and even just removing it entirely ought to be on the table

          it’s hard to do that when there’s existing code, but it’s possible, and it does pay dividends down the line

      2. 4

        Right, I mean, I’m a known nix partisan as it were, but in my view I’d say that there is no better expression language for the thing nix is doing today, and there also wasn’t at the time it was new. :)

        1. 4

          TBH if I was remaking Nix today, I’d probably use JavaScript as the expression language to make people’s lives easier

          1. 2

            It’s basically JSON for all practical purposes. Also, you want to keep computations to a minimal, it is more of a data description language.

            1. 1

              Functions are a super important part. Recursion is used heavily to do things like overrides. It’s not really JSON.

              1. 1

                Sure, but these are written once somewhere deep inside lib, and then used declaratively. You won’t really be writing functions as you would in a regular PL, and I would argue that most package descriptions can actually be read by humans if you parse them more or less as you would a JSON, which is the important mental model.

          2. 1

            Try it and see what happens. There’s several projects like Nickel and Zilch already exploring the space, too.

          3. 1

            I understand the impulse but I still feel it would be the wrong call. it’s not like it’s something really exotic, it uses infix and curly braces, heh.

      3. 3

        it does explain that the Nix expression language is the simplest possible language which has all of the necessary features

        Thanks for pointing this out!

    2. 5

      I love writing NixOS modules! I especially like how you can easily define one on the flake that defines the package itself that you want to ship, neatly putting the build process of a service and the service consumer’s interface in one place.

    3. 3

      Nix seems like a worthwhile investment to learn. Though (as mentioned with the comic sans slide) the ecosystem is somewhat confusing.

      Among the things that add a barrier to entry is needing to learn yet another custom configuration language (funny that the post starts off by complaining that NGINX has one). I’m wondering if a wrapper in a lang I might already know, like Ruby or Rust, might ease that one small burden so I could focus on the outcome and not the syntax.

      1. 9

        If you already know a programming language with some functional elements (Rust definitely fits that bill), I’d say Nix the language can be learned in an hour by taking the time to read Nix pills 4 and 5. The language is definitely quirky, but it is also extremely small. Warts are an annoyance but not a complete blocker.

        Then however you have to find out what all the functions in the lib thingy do (I think it’s provided by nixpgs and not Nix the language but I am still not sure), and this is IMO the big barrier to entry.

        1. 7

          Also about this bit:

          funny that the post starts off by complaining that NGINX has one

          NixOS is surprisingly old: Wikipedia tells me that the initial release of NixOS was in 2003, while nginx was in 2004. Maybe nginx should have used nix the language for configuration from the beginning :P

        2. 5

          That’s correct, lib is part of nixpkgs, not part of the language. Strictly speaking there’s one lib that’s used when writing packages and another that’s used when writing modules, but you’ll rarely need to worry about that distinction.

          1. 1

            Thanks for clarifying!

            1. 1

              sure thing!

      2. 2

        Guix isn’t quite as widely adopted as Nix, but uses scheme which is a big win for it. Anecdotally, it’s also much easier to use.

        1. 8

          I really want guix to succeed, but fear it’s lack of network effect will continue to hamper it. nixpkgs just has so many more packages and people involved. Sadly, guix will continue to be even more niche than the niche nix as long as it’s tied to GNU. In the real world, purity doesn’t really work for operating systems any more than programming languages.

          1. 6

            In the real world, purity doesn’t really work for operating systems any more than programming languages.

            Nix and NixOS are pure, so that’s a very weird to say!

            1. 2

              Eh, “pure” is a very overloaded term that has no meaning to the general computing public. I think it’s safer to say that they are more strictly focused on being repeatable (same inputs -> same outputs).

              1. 3

                Same inputs, same outputs is purity.

                1. 1

                  Yes, but if you call it purity you start making people’s eyes glaze over because it starts to sound like Haskell ivory tower bullshit lol

                  1. 8

                    That seems like “oh this isn’t pure, because that’s ivory tower, this is just strictly focused on being repeatable

                    I prefer to say “oh purity is super practical, look”

                    1. 2

                      Yep. Only that one simple thing with nix, that I can just replicate this exact environment perfectly in another machine every single time is, for me, so valuable I kind of don’t mind some of the quirks in nix/nixpkgs.

            2. 2

              I think you two interpret “pure” differently: Guix is pure in the FSF/GNU sense: free of proprietary software in its repositories, to the point where it is using linux-libre (a kernel stripped of binary blobs). This has the major disadvantage of not working very well on a lot of hardware that does require those binary blobs.

              nixpkgs has plenty of unfree software in it, and even though you can’t install them without going through additional hoops, they’re there, thus, it’s not pure in the FSF/GNU sense. Like, GNU considers the linux kernel impure to begin with, and you can install that from nixos without any additional hoops.

              1. 4

                I can’t remember the FSF using the term “pure” in this sense (complete absence of non-free software). It’s possible other FLOSS projects do, however.

              2. 2

                What’s the relevance to programming languages?

          2. 3

            Well, Nix is simply a decade older than Guix, so it’s understandable. For my personal use, I’ve found https://toys.whereis.みんな/ to be a nice package search across many channels, and you can add any channels you want as and when you find something that’s not packaged in the main repository. As for the last sentence, Nix is a pure programming language ;)

        2. 2

          Scheme is just not doing it for me. I just had a look at how to create something nix-shell like in GUIX, and found this reference. Unfortunately the examples (see the --expression=expr section) is exactly the sort of Perl-style line noise I can’t abide. Like, I don’t want to have to remember which complex LISP thing @ or % stand for. What’s wrong with words?

          1. 1

            Hmm, I have to say I vehemently disagree! I’m sorry if what follows feels like flamebait, tone is hard to convey over text and I just want to address some issues with what you said. You are of course entitled to any opinions you hold. The funny thing about what you said, that % is arcane, is that % has no special meaning, that’s just part of the variable name! @ is just splat, like in javascript or python, and neither of those are words either (whereas in scheme you can express it as a word, but using @ is shorter and spending a tiny amount of time is enough to understand that it’s shorthand). The examples are extremely clear and there is a 1-1 mapping between nix-shell and guix shell until you get to the one about --expression, which you would only use if you actually want to evaluate code to do something, which you can’t do with nix-shell.

            1. 2

              Of course someone used to Scheme would disagree ;) I tried learning Scheme many years ago, and just got the worst cognitive dissonance ever from every single token being abbreviated to death, and from using obtuse technical jargon like car and cdr instead of short, simple, everyday synonyms like first and second, or even initial and subsequent. LISP clones have a massive usability issue in that it’s not just a new programming language, but an entirely new set of words which other programming languages have moved away from.

              I would love to learn a LISP clone which chose usability over trying to look like 1960s code.

              1. 1

                maybe you’d find clojure more amenable, it is very much a modern language and (I think) uses head and tail instead of car and cdr.

                1. 5

                  Wouldn’t a Nix vs. Guix syntax debate just go back to the split between ML & LISP? That’s been one of the main syntax dividing lines in FP for decades. Having used many MLs (PureScript, Elm, OCaml, Haskell) Nix feels cozy (albeit quirky) & my limited time with Clojure(Script) or Chicken Scheme for Tree-sitter feels alien & unergonomic.

      3. 1

        I think of a wrapper language for Nix occasionally too, but I’ve been scared away by how difficult it would be to debug the errors.

    4. 2

      If somebody didn’t know this: man configuration.nix for nixos configuration and if using home-manager man home-configuration.nix for that. All config options explained and it runs fast. You can search and find what you need quickly. I quite enjoy their man pages.