.nix

What is a .nix file?

Nix Expression File · Code and data · Eelco Dolstra / NixOS project · 2003

A .nix file is a Nix expression: code in a small functional language that describes packages, development environments or entire systems for the Nix package manager and NixOS, reproducibly.

Category
Code and data
MIME type
Type
Plain text
Is a .nix file safe to open? Caution. Evaluating and building a .nix file can run arbitrary build steps and download sources. Read unfamiliar expressions, especially flakes, before running nix build or nix develop.

What is a .nix file used for?

Nix treats builds as pure functions: the same .nix input yields bit-for-bit the same environment, which is why developers use shell.nix or flake.nix to pin a project's exact toolchain, and why NixOS defines a whole OS in configuration.nix.

The language is lazy and functional, closer to a mini Haskell than to YAML, which gives it a learning curve. Flakes (flake.nix) are the modern entry point that also pins all inputs.

What opens a .nix file?

The .nix format opens in the following apps, grouped by operating system. If one app does not work, try another from the same list.

Windows

  • VS Code (Nix IDE), via WSL
  • any text editor

macOS

  • VS Code (Nix IDE)
  • any text editor

Linux

  • VS Code (Nix IDE)
  • any text editor

Open a .nix file step by step

  1. Confirm the file really is a .nix. Drop it into the WhatFileType identifier, which reads its signature in your browser without uploading anything.
  2. On Windows, open it with VS Code (Nix IDE), via WSL or any text editor.
  3. On Mac, use VS Code (Nix IDE) or any text editor.
  4. On Linux, try VS Code (Nix IDE) or any text editor.
  5. Still stuck? Search for a dedicated Nix viewer rather than a generic one.

Why can't I open my .nix file?

Almost always because no installed app understands Nix. Install one of the apps above, or convert the file to a format your existing software already reads. If double-clicking opens the wrong program instead of nothing at all, the file association is set to the wrong app rather than the file being broken.

The other possibility is that the file is not really a .nix at all. Drop it into the file identifier to check it by its bytes instead of its name. Nothing is uploaded.

Nix has no fixed magic number, so there is no signature table on this page. Its bytes alone do not prove the format: identification relies on the extension, the structure of the content and the program that created it. The magic-numbers reference lists the formats that do carry one.

Frequently asked questions

What is a .nix file?

A .nix file is a Nix expression: code in a small functional language that describes packages, development environments or entire systems for the Nix package manager and NixOS, reproducibly.

What is a flake.nix file?

The modern standard entry point of a Nix project: it declares inputs (pinned dependencies) and outputs (packages, dev shells, systems), making builds fully reproducible.

What is the difference between Nix and NixOS?

Nix is the package manager and language; NixOS is a Linux distribution built on it where the entire system is declared in .nix files.

How do I open a .nix file?

Any text editor; it is plain text. Using it requires the Nix package manager, which runs on Linux and macOS (and Windows via WSL).

Related formats

Sources

Details on this page were checked against authoritative references. How sources are ranked and what is deliberately left out is set out in the methodology.