Nix indentation

Hello. I’m making changes to my nix configuration, and I wonder if someone could point me to an editor plugin that helps with the syntax and indentation. Thank you!

1 Like

You can take a look at nixfmt

1 Like

What, and where, is that?

It’s a program that you can run on the terminal or as an editor on save hook to format your nix files.

We can’t really give you more than that, as you haven’t specified which editor you use.

I can tell you though, that there is an Emacs mode available, as well as at least one plugin for vscode.

I’m using Emacs, but it’s new to me.

For Emacs there is nix-mode on MELPA.

It does not come with format on save though, just syntax checking and a bit of font-locking.

There are 2 major programs to format nix files in nixpkgs. One is nixfmt, the other is nixpkgs-format or something similar.

Which of these produces an output that is more pleasant to your eyes, you need to check for yourself.

I’m not concerned with “pleasing to the eyes”, just a working configuration. Also, I know nothing about installing Emacs packages.

Not at all, or not with nix?

Not at all. Just a few years ago I was a Windows user. Also, I understand that to manage packages it’s best to choose the ‘with packages’ version in nix. At any rate, I do now.

If you want to install and manage your Emacs plugins through nix, you can totally do so.

I do it as well.

Though the way you do it, depends on the way you manage Emacs in general.

Do you want to manage it through configuration.nix or through Home-manager or do you want to do so by another means?

Do you have or are you willing to use the emacs-overlay?

I have no idea. That’s one of the things about Linux that baffles me: at least two ways of doing anything.

linux is just the kernel, everything on top of the kernel doesn’t have “a standard”

Getting back to the point: I set out to manage nix. Emacs is just a means of doing so.

Apparently changing init.el or .emacs will help, if someone will tell me where they are.

If your are using Vim (or Neovim) you can apply nixpkgs-fmt this way:

1 Like

Well, if nixpkgs-fmt is installed and visible to vim in PATH.

This is not an assumption that I would make light heartedly. Especially not when the user obviously does not know much about Linux in general and nix specifically.

I have enough experience to know I don’t want to code the Microsoft way, but it’s true that I don’t know much about Linux. So please don’t tell me about all your favorite programs.

Yeah, but you still haven’t said yet, what you want to actually use.

Do you use configuration.nix to manage your software beyond the base system? Do you use Home-Manager to manage the users software declaratively? Do you use nix-env and some declarative set up? Just nix-env? Something I haven’t considered?

Do you use already, or do you want to use the emacs-overlay?

Do you want to manage emacs configuration through nix as well or just its packages?

I do not know what home-manager or emacs-overlay are. I want to manage as little as possible; I want to write code.

even if you’re writing assembly, you’re likely to be writing on the shoulders of other programs. Once you get pass the initial environment hurdles, you should be free to do what you want.

In reply to @NobbZ- I don’t know what I want to use; I have no data.