Nix 101 Course / Section 1: Getting started: install Nix and score your first wins
Premium

1.7 Nix editor setup: VS Code with nixd and nixfmt

Lesson 7 of 68 · 5:47

placeholder thumbnail

Sign in, then buy this course to watch

Free account · no credit card needed

Video chapters

  1. 0:00 Setting Up a Nix-Friendly Editor
  2. 0:52 Installing Nix IDE and Configuring Nixd
  3. 2:23 Adding Nixd and Nixfmt to the Environment
  4. 3:34 Autocomplete, Hover Docs, and Formatting in VS Code
Transcript

Setting Up a Nix-Friendly Editor

0:00 Okay, so before we go into more detail with Nix and NixOS and everything, we're going to learn the Nix language. And the Nix language has a different syntax, have different semantics, if you're not used to functional programming, and so on and so on. It might feel ugly in the beginning, but to ease that out a bit, let's set up an editor in the right way, so that we get syntax highlighting, code completion, and automatic formatting.

0:31 In this example, we're simply going to use Visual Studio Code. Let's go into some example repository, I already have Visual Studio Code installed, and typically you would either install that with Snap, or your package manager, or with Nix, whatever,

Installing Nix IDE and Configuring Nixd

0:53 I don't mind, however. So without any integration or anything, we just have this ugly thing here, that in my project here I have no syntax highlighting, nothing, it simply looks like no support. We can fix that. We could say, okay, let's go into the extension search and enter Nix IDE.

The full transcript comes with the lesson.

About this lesson

The Nix language can feel strange at first, and reading it in a plain editor without any support makes that worse. Before the language lessons start, this video sets up Visual Studio Code for Nix: syntax highlighting, code completion, inline documentation and automatic formatting, using the Nix IDE extension, the nixd language server and nixfmt.

In this video

  • Installing the Nix IDE extension, and why syntax coloring alone is not the whole story
  • Wiring up nixd and nixfmt through settings.json, starting from a minimal config that just works
  • Installing both tools with nix profile, including a bash shorthand for adding two packages at once
  • Completion in action: typing packages. and picking real packages from nixpkgs
  • Documentation on mouseover, and where those docs actually come from, plus fixing horribly formatted code with one command

After this lesson

You write Nix with completion, inline documentation and a formatter, which makes everything from here on noticeably more comfortable.

Builds on: Installing tools to keep with nix profile (1.5.2)