Skip to content

Instantly share code, notes, and snippets.

@makoConstruct
Last active January 6, 2024 20:52
Show Gist options
  • Save makoConstruct/e44b183e3f856ba5e766de7d34cab1e6 to your computer and use it in GitHub Desktop.
Save makoConstruct/e44b183e3f856ba5e766de7d34cab1e6 to your computer and use it in GitHub Desktop.
proposal of the Nix syntax, Nis

I propose "Nis", a new syntax for Nix.

Nix's syntax has a couple of issues. Its function invocation syntax breaks in arrays, which is fairly serious. It also involves a lot of semicolons. Neither of these things are necessary.

Nix version:

{
  outputs = inputs: let
    username = "mako";
    defaultHostname = "yoga";
    forHost = hostname: numberOfPears: moreConfig:
      inputs.nixpkgs.lib.nixosSystem {
        modules = [
          moreConfig
          (import ./harware-configuration.nix)
          {
            fruitBowl = { pears = numberOfPears; };
            inherit username;
            inherit hostname;
          }
        ];
      };
    in {
      nixosConfigurations = {
        yoga = forHost defaultHostname (4 + 2)*3 {};
    };
}

Nis version:

{
  outputs = (inputs): let
    username = "mako"
    defaultHostname = "yoga"
    forHost = (hostname numberOfPears moreConfig):
      inputs.nixpkgs.lib.nixosSystem({
        modules = [
          moreConfig
          import(./harware-configuration.nix)
          {
            fruitBowl = { pears = numberOfPears }
            inherit username
            inherit hostname
          }
        ]
      })
    in {
      nixosConfigurations = forHost(defaultHostname (4 + 2)*3 {})
    }
}

Those are the benefits. The only drawback is a potential to leave programmers a more confused when they first encounter a function that returns a function being used as if it were a function of two parameters, as a result of not having forceably introduced to the curried function signature syntax in the process of learning the syntax, but I was already pretty confused when I encountered an immediate call into a returned function, so I'm not sure how much difference this will make.

The parser's a little bit more complex, but you only have to write it once, and I might be the one who does it, and I don't mind doing it.

Whether a nix code file uses the nis or nix syntax can generally be determined from the file extension of the import. import will be easy to adapt.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment