Jump to content

Nix (command)

From NixOS Wiki
Revision as of 02:13, 18 May 2021 by imported>Samuela

This article is about all nix subcommands. Its written for nix 2.4 or newer. Older nix versions might have different commands.

Enabling the nix command

In nix 2.4 the nix command must be enabled explicitly set. You can do this in a few different ways.

For an individual invocation, eg.

nix --experimental-features nix-command log ...

Or by setting a user-specific configuration,

# ~/.config/nix/nix.conf
experimental-features = nix-command

in ~/.config/nix/nix.conf.

Or system-wide with

# /etc/nix/nix.conf
{ pkgs, ... }: {
   nix.extraOptions = ''
      experimental-features = nix-command
   '';
   # this is required until nix 2.4 is released
   nix.package = pkgs.nixUnstable;
}

in /etc/nix/nix.conf on NixOS.

In the following we describe all sub commands of nix:

Common flags

  • --debug enable debug output
  • --help show usage information
  • --help-config show configuration options
  • --log-format FORMAT format of log output; "raw", "internal-json", "bar" or "bar-with-logs"
  • --no-net disable substituters and consider all previously downloaded files up-to-date
  • --option NAME VALUE set a Nix configuration option (overriding nix.conf)
  • -L, --print-build-logs print full build logs on stderr
  • --quiet decrease verbosity level
  • --refresh consider all previously downloaded files out-of-date
  • -v, --verbose increase verbosity level
  • --version show version information

In addition, most configuration settings can be overriden using --name value. Boolean settings can be overriden using --name or --no-name. See nix --help-config for a list of configuration settings.

Main commands

Build a derivation or fetch a store path.

Run a bash shell that provides the build environment of a derivation.

Manage Nix flakes.

Manage Nix profiles.

Start an interactive environment for evaluating Nix expressions.

Run a Nix application.

Query available packages.

Run a shell in which the specified packages are available.

Infrequently used commands

Copy paths between Nix stores.

Open the Nix expression of a Nix package in $EDITOR.

Evaluate a Nix expression.

Show the build log of the specified packages or paths, if available.

Query information about store paths.

Manage the flake registry.

Verify the integrity of store paths.

Show why a package has another package in its closure.

Utility/scripting commands

Add a path to the Nix store.

Print the contents of a file inside a NAR file on stdout.

Print the contents of a file in the Nix store on stdout.

Copy path signatures from substituters (like binary caches).

Dump a store path to stdout (in NAR format).

Print cryptographic hash of the NAR serialisation of a path.

Print cryptographic hash of the NAR serialisation of a path.

Show information about a path inside a NAR file.

Show information about a path in the Nix store.

Rewrite a path or closure to content-addressable form.

Replace identical files in the store by hard links.

Test whether a store can be opened.

Print shell code that can be sourced by bash to reproduce the build environment of a derivation.

Show the Nix configuration.

Show the contents of a store derivation.

Sign the specified paths.

Convert a hash to base-16 representation.

Convert a hash to base-32 representation.

Convert a hash to base-64 representation.

Convert a hash to SRI representation.