nix(1)
๐ nix โ the manual, bestie edition ๐
okay so you opened nix(1) from the General Commands Manual and you're about to get the whole entire tour. nix is THAT girl. let's go. ๐ธ
โ ๏ธ Warning โ ๏ธ this program is experimental and its interface is subject to change. like, yes she's iconic but she's also still growing. don't get too attached to any one flag, fr fr ๐ญ
โจ NAME โจ
nix โ a tool for reproducible and declarative configuration management. that's the whole serve. reproducible means same inputs, same outputs, every time. declarative means you say what you want and nix figures out the how. main character energy tbh ๐ซถ
๐ SYNOPSIS ๐
nix [optionโฆ] subcommand
where subcommand is one of the following, and bestie there are so many of them, so buckle up:
๐ Help commands ๐
nix helpโ shows you help aboutnixitself, or about one specific subcommand if you point at one ๐nix help-storesโ shows you help about store types and all their settings ๐
๐ฅ Main commands ๐ฅ
nix buildโ builds a derivation, or fetches a store path ๐๏ธnix developโ drops you into a bash shell with the build environment of a derivation, so you can poke around ๐nix flakeโ manages Nix flakes (the cute self-contained project format) ๐ฆnix profileโ manages Nix profiles ๐nix runโ runs a Nix application, no install required โจnix searchโ searches for packages ๐
๐ฅ Main commands ๐ฅ
(no you're not seeing double, the original page literally labels this one "Main commands" again. iconic of it.) ๐
nix replโ starts an interactive environment for evaluating Nix expressions, aka the playground ๐ฎ
๐ Infrequently used commands ๐
nix bundleโ bundles an application so it still works outside of the Nix store ๐ฆnix copyโ copies paths between Nix stores ๐nix editโ opens the Nix expression of a Nix package in$EDITORโ๏ธnix evalโ evaluates a Nix expression ๐งฎnix fmtโ reformats your code in the standard style ๐nix formatterโ builds or runs the formatter ๐nix logโ shows the build log of the specified packages or paths, if it's available ๐nix path-infoโ queries information about store paths ๐nix registryโ manages the flake registry ๐๏ธnix why-dependsโ shows why a package has another package in its closure ๐ค
๐ง Utility/scripting commands ๐ง
nix configโ manipulates the Nix configuration โ๏ธnix daemonโ a daemon that performs store operations on behalf of non-root clients ๐ปnix derivationโ works with derivations ๐nix envโ manipulates the process environment ๐nix hashโ computes and converts cryptographic hashes ๐nix keyโ generates and converts Nix signing keys ๐nix narโ creates or inspects NAR files ๐๏ธnix print-dev-envโ prints shell code that can be sourced by bash to reproduce the build environment of a derivation ๐จ๏ธnix storeโ manipulates a Nix store ๐ฌ
๐ ๏ธ Commands for upgrading or troubleshooting your Nix installation ๐ ๏ธ
nix upgrade-nixโ upgrades Nix to the latest stable version โฌ๏ธ
๐ EXAMPLES ๐
okay real talk, seeing it in action hits different. here we go:
- Create a new flake:
# nix flake new hello
# cd hello
- Build the flake in the current directory:
# nix build
# ./result/bin/hello
Hello, world!
- Run the flake in the current directory:
# nix run
Hello, world!
- Start a development shell for hacking on this flake:
# nix develop
# unpackPhase
# cd hello-*
# configurePhase
# buildPhase
# ./hello
Hello, world!
# installPhase
# ../outputs/out/bin/hello
Hello, world!
like?? she built it, she ran it, she dev-shell'd it, she said Hello, world! four separate times. ate and left no crumbs ๐ซถโจ
๐ DESCRIPTION ๐
Nix is a tool for building software, configurations and other artifacts in a reproducible and declarative way. for more information, see the Nix homepage or the Nix manual ๐
and that's only part one bestie, don't go anywhere โ part 2 is literally right there ๐๐ฆ
๐ INSTALLABLES ๐
โ ๏ธ WARNING: bestie. Installables are part of the unstable nix-command experimental feature. They are subject to change without notice. Do not build your whole personality on them. ๐
So most nix subcommands are like "okay give me a thing to do stuff to" and that thing is an installable โ a command line argument that represents something realisable in the Nix store. โจ
Here's the menu of installable types that most commands will accept:
- Flake output attribute (experimental)
- this is the default ๐
- Store path
- Nix assumes this if the argument is a Nix store path, or a symlink pointing at one ๐
- Nix file, optionally qualified by an attribute path
- you say so with
--file/-f
- you say so with
- Nix expression, optionally qualified by an attribute path
- you say so with
--expr
- you say so with
And here's the little shortcut that trips people up: for most commands, if you hand over no installable at all, . is assumed. That means Nix operates on the default flake output attribute of the flake sitting in your current directory. Yes, it's giving "I assumed you meant here." ๐ซถ
๐ธ Flake output attribute
โ ๏ธ WARNING: Flake output attribute installables depend on both theflakesandnix-commandexperimental features, and they're subject to change without notice. Experimental era, babe. ๐งช
Example: nixpkgs#hello
These look like flakeref[#attrpath], where flakeref is a flake reference and attrpath is an optional attribute path. Wanna know more about flakes? Go read the nix flake manual page. Flake references are usually:
- a flake identifier in the flake registry (e.g.
nixpkgs) ๐ - a raw path (e.g.
/path/to/my-flake, or., or../foo) ๐ - or a full URL (e.g.
github:nixos/nixpkgsorpath:.) ๐
When the flake reference is a raw path (a path with no URL scheme at all), Nix interprets it as a path: or git+file: url, like this:
- If the path is within a Git repository, the url gets the form
git+file://[GIT_REPO_ROOT]?dir=[RELATIVE_FLAKE_DIR_PATH]whereGIT_REPO_ROOTis the path to the root of the git repository, andRELATIVE_FLAKE_DIR_PATHis the path (relative to the directory root) of the closest parent of the given path that contains aflake.nixwithin the git repository. If there's no such directory, Nix will error-out. ๐ญ
Heads up: the search only includes files indexed by git. So files matched by .gitignore, or files that have never been git add-ed, will not be available in the flake. If that's not the vibe you want, specify path:<directory> explicitly.
So for example, if /foo/bar is a git repository with this structure:
.
โโโ baz
โโโ blah
โ โโโ file.txt
โโโ flake.nix
then /foo/bar/baz/blah will resolve to git+file:///foo/bar?dir=baz
- If the supplied path is not a git repository, the url gets the form
path:FLAKE_DIR_PATHwhereFLAKE_DIR_PATHis the closest parent of the supplied path that contains aflake.nixfile (within the same file-system). If no such directory exists, Nix will error-out. ๐
For example, if /foo/bar/flake.nix exists, then /foo/bar/baz/ will resolve to path:/foo/bar
Now, if attrpath is omitted, Nix tries some default values. For most subcommands the default is packages.system.default (e.g. packages.x86_64-linux.default), but some subcommands have other defaults. ๐
If attrpath is specified, it's interpreted as relative to one or more prefixes; for most subcommands those are packages.system, legacyPackages.*system* and the empty prefix. So on x86_64-linux, nix build nixpkgs#hello will try to build all three of these attributes:
packages.x86_64-linux.hellolegacyPackages.x86_64-linux.hellohello
And if attrpath begins with . then no prefixes or defaults are attempted at all. That's what lets you write the form flakeref[#.attrpath], like github:NixOS/nixpkgs#.lib.fakeSha256, to avoid a search of packages.*system*.lib.fakeSha256. Slay, no more guessing. ๐
๐ Store path
Example: /nix/store/10l19qifk7hjjq47px8m2prqk1gv4isy-hello-2.10
These are paths inside the Nix store, or symlinks that resolve to a path in the Nix store. ๐
A store derivation is also addressed by store path.
Example: /nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv
If you wanna refer to an output path of that store derivation, add the output name preceded by a caret (^). โจ
Example: /nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv^out
And you can grab all outputs at once with the special syntax ^*. ๐
Example: /nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv^*
๐ Nix file
Example: --file /path/to/nixpkgs hello
When the option -f / --file path [attrpathโฆ] is given, installables are interpreted as the value of the expression in the Nix file at path. If attribute paths are provided, commands will operate on the corresponding values accessible at those paths. And here's the rule, no cap: the Nix expression in that file โ or any selected attribute โ must evaluate to a derivation. ๐
๐ Nix expression
Example: --expr 'import <nixpkgs> {}' hello
When the option --expr expression [*attrpath*โฆ] is given, installables are interpreted as the value of the of the Nix expression. (Yes, the original says "the value of the of the" โ we're keeping the facts, not fixing the prose, bestie. ๐ญ) If attribute paths are provided, commands will operate on the corresponding values accessible at those paths. And again: the Nix expression, or any selected attribute, must evaluate to a derivation.
You may need to specify --impure if the expression references impure inputs (such as <nixpkgs>). ๐ซง
๐ฆ Derivation output selection
Derivations can have multiple outputs, and each one corresponds to a different store path. For instance, a package can have a bin output with the programs in it, and a dev output that provides development artifacts like C/C++ header files. So which outputs do nix commands actually operate on? Great question, here's the tea: โ
- You can explicitly specify the desired outputs using the syntax
installable^output1,โฆ,outputNโ that is, a caret followed immediately by a comma-separated list of derivation outputs to select. For installables specified as Flake output attributes or Store paths, the output is specified in the same argument:
For example, you can obtain the dev and static outputs of the glibc package:
# nix build 'nixpkgs#glibc^dev,static'
# ls ./result-dev/include/ ./result-static/lib/
โฆ
and likewise, using a store path to a "drv" file to specify the derivation:
# nix build '/nix/store/fpq78s2h8ffh66v2iy0q1838mhff06y8-glibc-2.33-78.drv^dev,static'
โฆ
For --expr and -f/--file, the derivation output is specified as part of the attribute path:
$ nix build -f '<nixpkgs>' 'glibc^dev,static'
$ nix build --impure --expr 'import <nixpkgs> { }' 'glibc^dev,static'
This syntax is the same even if the actual attribute path is empty:
$ nix build --impure --expr 'let pkgs = import <nixpkgs> { }; in pkgs.glibc' '^dev,static'
- You can also specify that all outputs should be used, with the syntax
installable^*. For example, the following shows the size of all outputs of theglibcpackage in the binary cache:
# nix path-info --closure-size --eval-store auto --store https://cache.nixos.org 'nixpkgs#glibc^*'
/nix/store/i2fn2mjgihz960bwa7ldab5ra5fhxznh-glibc-2.33-123 33208200
/nix/store/n2wnn3i47w6dbylh64hdjzgd5rrprdn8-glibc-2.33-123-bin 36142896
/nix/store/v7dyz518sbkzl8x2a1sgk1lwsfd3d6gm-glibc-2.33-123-debug 155787312
/nix/store/z4hv6ybyinqw9a3dwyl5k66a91aggylj-glibc-2.33-123-static 42488328
/nix/store/lrjirf0j1rjnvif6amyp9pfcqr2km385-glibc-2.33-123-dev 44200560
and likewise, using a store path to a "drv" file to specify the derivation:
# nix path-info --closure-size '/nix/store/fpq78s2h8ffh66v2iy0q1838mhff06y8-glibc-2.33-78.drv^*'
โฆ
- If you didn't specify the desired outputs, but the derivation has an attribute
meta.outputsToInstall, Nix will use those outputs. For example, since the packagenixpkgs#libxml2has this attribute:
# nix eval 'nixpkgs#libxml2.meta.outputsToInstall'
[ "bin" "man" ]
a command like nix shell nixpkgs#libxml2 will provide only those two outputs by default. ๐
Note that a store derivation doesn't have any attributes like meta, and thus this case doesn't apply to it. ๐ซ
- Otherwise, Nix will use all outputs of the derivation. ๐
๐ช Nix stores
Most nix subcommands operate on a Nix store. The various store types are documented in the Store Types section of the manual. ๐
The same information is also available from the nix help-stores command. Handy! โจ
๐ง Shebang interpreter
The nix command can be used as a #! interpreter. Arguments to Nix can be passed on subsequent lines in the script. ๐ช
Verbatim strings may be passed in double backtick () quotes. Sequences of *n* backticks of 3 or longer are parsed as *n*-1 literal backticks. A single space before the closing is ignored if present.
--file and --expr resolve relative paths based on the script location. ๐
Examples:
#!/usr/bin/env nix
#! nix shell --file ``<nixpkgs>`` hello cowsay --command bash
hello | cowsay
or with flakes:
#!/usr/bin/env nix
#! nix shell nixpkgs#bash nixpkgs#hello nixpkgs#cowsay --command bash
hello | cowsay
or with an expression:
#! /usr/bin/env nix
#! nix shell --impure --expr ``
#! nix with (import (builtins.getFlake "nixpkgs") {});
#! nix terraform.withPlugins (plugins: [ plugins.openstack ])
#! nix ``
#! nix --command bash
terraform "$@"
or with cascading interpreters. Note that the #! nix lines don't need to follow after the first line, to accommodate other interpreters. ๐
#!/usr/bin/env nix
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
/*
#!nix shell nixpkgs#rustc nixpkgs#rust-script nixpkgs#cargo --command rust-script
*/
fn main() {
for argument in std::env::args().skip(1) {
println!("{}", argument);
};
println!("{}", std::env::var("HOME").expect(""));
println!("{}", time::now().rfc822z());
}
// vim: ft=rust
๐ OPTIONS ๐
okay bestie, here's the part where we get into the knobs and switches โจ every single one of these is a global flag, so they work basically everywhere, and you can just sprinkle them on like glitter ๐
๐ Logging-related options ๐
these are all about how much tea nix spills while it's working. more verbosity = more texts, more scrolling, more of you going "wait what happened" at 2am. pick your fighter ๐
--debugโ cranks the logging verbosity level alllll the way up todebug. yes that's literally the name of the level. it's giving "I want to see everything" โจ--log-formatformat โ sets what the log output actually looks like. you pick exactly one of these four, no mixing and matching:raw,internal-json,bar, orbar-with-logs. choose wisely bestie ๐ธ--print-build-logs,-Lโ prints the full build logs straight to standard error. no hiding, no truncating, the whole thing ๐๐--quietโ decreases the logging verbosity level. the "please stop telling me things, I'm overwhelmed" flag ๐คซ--verbose,-vโ increases the logging verbosity level. stack it, spam it, watch the wall of text appear ๐ฃ๏ธ๐ฅ
ngl--quietand--verboseare literally opposites and the way that they just nudge the level up or down is so simple it's iconic ๐
๐ Miscellaneous global options ๐
the leftovers that don't fit anywhere else but are still lowkey essential. grab a snack ๐
--helpโ shows you the usage information. the classic "hello, what are you" move ๐ซถ--offlineโ disables substituters, and treats every previously downloaded file as up-to-date. it's giving airplane mode but for your store โ๏ธ ngl this one is very useful when the wifi is acting up--optionname value โ sets the Nix configuration setting name to value, overridingnix.conf. two args, both required, no skipping ๐--refreshโ the chaotic sibling of--offline: it considers all previously downloaded files out-of-date instead. brb re-fetching everything ๐๐--versionโ shows the version information. short, sweet, slay โญ
note-ish moment: see man nix.conf for overriding configuration settings with command line flags. iykyk, that's where the real config lore lives ๐โจ
and that's the whole page, bestie, we made it to the end ๐ญ๐ this nix(1) page comes straight from the Nix manual, and it's signed off all official with its own source, version and date down at the bottom โ think of it like the little copyright signature in a group photo, periodt ๐ no cap, go build something cute ๐ฆ
๐ฆ where this page comes from
- fedora 44: nix-core 2.35.3-2.fc44 ยท LGPL-2.1-or-later
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms