.\" -*- mode: troff; coding: utf-8 -*- .TH "nix" "1" "" .RS .PP \fBWarning\fR .br This program is \fB\fBexperimental\fR\fR and its interface is subject to change. .RE .SH Name .LP \fCnix\fR - a tool for reproducible and declarative configuration management .SH Synopsis .LP \fCnix\fR [\fIoption\fR\[u2026]] \fIsubcommand\fR .PP where \fIsubcommand\fR is one of the following: .PP \fBHelp commands:\fR .IP "\(bu" 3 \fB\fCnix help\fR\fR - show help about \fCnix\fR or a particular subcommand .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix help-stores\fR\fR - show help about store types and their settings .LP \fBMain commands:\fR .IP "\(bu" 3 \fB\fCnix build\fR\fR - build a derivation or fetch a store path .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix develop\fR\fR - run a bash shell that provides the build environment of a derivation .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix flake\fR\fR - manage Nix flakes .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix profile\fR\fR - manage Nix profiles .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix run\fR\fR - run a Nix application .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix search\fR\fR - search for packages .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix shell\fR\fR - run a shell in which the specified packages are available .LP \fBMain commands:\fR .IP "\(bu" 3 \fB\fCnix repl\fR\fR - start an interactive environment for evaluating Nix expressions .LP \fBInfrequently used commands:\fR .IP "\(bu" 3 \fB\fCnix bundle\fR\fR - bundle an application so that it works outside of the Nix store .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix copy\fR\fR - copy paths between Nix stores .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix edit\fR\fR - open the Nix expression of a Nix package in $EDITOR .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix eval\fR\fR - evaluate a Nix expression .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix fmt\fR\fR - reformat your code in the standard style .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix log\fR\fR - show the build log of the specified packages or paths, if available .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix path-info\fR\fR - query information about store paths .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix registry\fR\fR - manage the flake registry .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix why-depends\fR\fR - show why a package has another package in its closure .LP \fBUtility/scripting commands:\fR .IP "\(bu" 3 \fB\fCnix config\fR\fR - manipulate the Nix configuration .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix daemon\fR\fR - daemon to perform store operations on behalf of non-root clients .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix derivation\fR\fR - Work with derivations, Nix\(cqs notion of a build plan. .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix hash\fR\fR - compute and convert cryptographic hashes .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix key\fR\fR - generate and convert Nix signing keys .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix nar\fR\fR - create or inspect NAR files .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix print-dev-env\fR\fR - print shell code that can be sourced by bash to reproduce the build environment of a derivation .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix realisation\fR\fR - manipulate a Nix realisation .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\fCnix store\fR\fR - manipulate a Nix store .LP \fBCommands for upgrading or troubleshooting your Nix installation:\fR .IP "\(bu" 3 \fB\fCnix upgrade-nix\fR\fR - upgrade Nix to the latest stable version .SH Examples .IP "\(bu" 3 Create a new flake: .LP .EX # nix flake new hello # cd hello .EE .IP "\(bu" 3 Build the flake in the current directory: .LP .EX # nix build # ./result/bin/hello Hello, world! .EE .IP "\(bu" 3 Run the flake in the current directory: .LP .EX # nix run Hello, world! .EE .IP "\(bu" 3 Start a development shell for hacking on this flake: .LP .EX # nix develop # unpackPhase # cd hello-* # configurePhase # buildPhase # ./hello Hello, world! # installPhase # ../outputs/out/bin/hello Hello, world! .EE .SH Description .LP Nix is a tool for building software, configurations and other artifacts in a reproducible and declarative way. For more information, see the \fBNix homepage\fR or the \fBNix manual\fR. .SH Installables .RS .LP \fBWarning\fR .br Installables are part of the unstable \fB\fCnix-command\fR experimental feature\fR, and subject to change without notice. .RE .PP Many \fCnix\fR subcommands operate on one or more \fIinstallables\fR. These are command line arguments that represent something that can be realised in the Nix store. .PP The following types of installable are supported by most commands: .IP "\(bu" 3 \fBFlake output attribute\fR (experimental) .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBStore path\fR .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBNix file\fR, optionally qualified by an attribute path .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBNix expression\fR, optionally qualified by an attribute path .LP For most commands, if no installable is specified, \fC.\fR is assumed. That is, Nix will operate on the default flake output attribute of the flake in the current directory. .SS Flake output attribute .RS .LP \fBWarning\fR .br Flake output attribute installables depend on both the \fB\fCflakes\fR\fR and \fB\fCnix-command\fR\fR experimental features, and subject to change without notice. .RE .PP Example: \fCnixpkgs#hello\fR .PP These have the form \fIflakeref\fR[\fC#\fR\fIattrpath\fR], where \fIflakeref\fR is a \fBflake reference\fR and \fIattrpath\fR is an optional attribute path. For more information on flakes, see \fBthe \fCnix flake\fR manual page\fR. Flake references are most commonly a flake identifier in the flake registry (e.g. \fCnixpkgs\fR), or a raw path (e.g. \fC/path/to/my-flake\fR or \fC.\fR or \fC../foo\fR), or a full URL (e.g. \fCgithub:nixos/nixpkgs\fR or \fCpath:.\fR) .PP When the flake reference is a raw path (a path without any URL scheme), it is interpreted as a \fCpath:\fR or \fCgit+file:\fR url in the following way: .IP "\(bu" 3 If the path is within a Git repository, then the url will be of the form \fCgit+file://[GIT_REPO_ROOT]?dir=[RELATIVE_FLAKE_DIR_PATH]\fR where \fCGIT_REPO_ROOT\fR is the path to the root of the git repository, and \fCRELATIVE_FLAKE_DIR_PATH\fR is the path (relative to the directory root) of the closest parent of the given path that contains a \fCflake.nix\fR within the git repository. If no such directory exists, then Nix will error-out. .IP Note that the search will only include files indexed by git. In particular, files which are matched by \fC.gitignore\fR or have never been \fCgit add\fR-ed will not be available in the flake. If this is undesirable, specify \fCpath:\fR explicitly; .IP For example, if \fC/foo/bar\fR is a git repository with the following structure: .LP .EX \&. └── baz ├── blah │  └── file.txt └── flake.nix .EE .IP Then \fC/foo/bar/baz/blah\fR will resolve to \fCgit+file:///foo/bar?dir=baz\fR .IP "\(bu" 3 If the supplied path is not a git repository, then the url will have the form \fCpath:FLAKE_DIR_PATH\fR where \fCFLAKE_DIR_PATH\fR is the closest parent of the supplied path that contains a \fCflake.nix\fR file (within the same file-system). If no such directory exists, then Nix will error-out. .IP For example, if \fC/foo/bar/flake.nix\fR exists, then \fC/foo/bar/baz/\fR will resolve to \fCpath:/foo/bar\fR .LP If \fIattrpath\fR is omitted, Nix tries some default values; for most subcommands, the default is \fCpackages.\fR\fIsystem\fR\fC.default\fR (e.g. \fCpackages.x86_64-linux.default\fR), but some subcommands have other defaults. If \fIattrpath\fR \fIis\fR specified, \fIattrpath\fR is interpreted as relative to one or more prefixes; for most subcommands, these are \fCpackages.\fR\fIsystem\fR, \fClegacyPackages.*system*\fR and the empty prefix. Thus, on \fCx86_64-linux\fR \fCnix build nixpkgs#hello\fR will try to build the attributes \fCpackages.x86_64-linux.hello\fR, \fClegacyPackages.x86_64-linux.hello\fR and \fChello\fR. .PP If \fIattrpath\fR begins with \fC.\fR then no prefixes or defaults are attempted. This allows the form \fIflakeref\fR[\fC#.\fR\fIattrpath\fR], such as \fCgithub:NixOS/nixpkgs#.lib.fakeSha256\fR to avoid a search of \fCpackages.*system*.lib.fakeSha256\fR .SS Store path .LP Example: \fC/nix/store/v5sv61sszx301i0x6xysaqzla09nksnd-hello-2.10\fR .PP These are paths inside the Nix store, or symlinks that resolve to a path in the Nix store. .PP A \fBstore derivation\fR is also addressed by store path. .PP Example: \fC/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv\fR .PP If you want to refer to an output path of that store derivation, add the output name preceded by a caret (\fC\(ha\fR). .PP Example: \fC/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv\(haout\fR .PP All outputs can be referred to at once with the special syntax \fC\(ha*\fR. .PP Example: \fC/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv\(ha*\fR .SS Nix file .LP Example: \fC--file /path/to/nixpkgs hello\fR .PP When the option \fC-f\fR / \fC--file\fR \fIpath\fR [\fIattrpath\fR\[u2026]] is given, installables are interpreted as the value of the expression in the Nix file at \fIpath\fR. If attribute paths are provided, commands will operate on the corresponding values accessible at these paths. The Nix expression in that file, or any selected attribute, must evaluate to a derivation. .SS Nix expression .LP Example: \fC--expr 'import {}' hello\fR .PP When the option \fC--expr\fR \fIexpression\fR [\fIattrpath\fR\[u2026]] is given, installables are interpreted as the value of the of the Nix expression. If attribute paths are provided, commands will operate on the corresponding values accessible at these paths. The Nix expression, or any selected attribute, must evaluate to a derivation. .PP You may need to specify \fC--impure\fR if the expression references impure inputs (such as \fC\fR). .SS Derivation output selection .LP Derivations can have multiple outputs, each corresponding to a different store path. For instance, a package can have a \fCbin\fR output that contains programs, and a \fCdev\fR output that provides development artifacts like C/C++ header files. The outputs on which \fCnix\fR commands operate are determined as follows: .IP "\(bu" 3 You can explicitly specify the desired outputs using the syntax \fIinstallable\fR\fC\(ha\fR\fIoutput1\fR\fC,\fR\fI\[u2026]\fR\fC,\fR\fIoutputN\fR. For example, you can obtain the \fCdev\fR and \fCstatic\fR outputs of the \fCglibc\fR package: .LP .EX # nix build 'nixpkgs#glibc\(hadev,static' # ls ./result-dev/include/ ./result-static/lib/ … .EE .IP and likewise, using a store path to a \(lqdrv\(rq file to specify the derivation: .LP .EX # nix build '/nix/store/gzaflydcr6sb3567hap9q6srzx8ggdgg-glibc-2.33-78.drv\(hadev,static' … .EE .IP "\(bu" 3 You can also specify that \fIall\fR outputs should be used using the syntax \fIinstallable\fR\fC\(ha*\fR. For example, the following shows the size of all outputs of the \fCglibc\fR package in the binary cache: .LP .EX # nix path-info --closure-size --eval-store auto --store https://cache.nixos.org 'nixpkgs#glibc\(ha*' /nix/store/g02b1lpbddhymmcjb923kf0l7s9nww58-glibc-2.33-123 33208200 /nix/store/851dp95qqiisjifi639r0zzg5l465ny4-glibc-2.33-123-bin 36142896 /nix/store/kdgs3q6r7xdff1p7a9hnjr43xw2404z7-glibc-2.33-123-debug 155787312 /nix/store/n4xa8h6pbmqmwnq0mmsz08l38abb06zc-glibc-2.33-123-static 42488328 /nix/store/q6580lr01jpcsqs4r5arlh4ki2c1m9rv-glibc-2.33-123-dev 44200560 .EE .IP and likewise, using a store path to a \(lqdrv\(rq file to specify the derivation: .LP .EX # nix path-info --closure-size '/nix/store/gzaflydcr6sb3567hap9q6srzx8ggdgg-glibc-2.33-78.drv\(ha*' … .EE .IP "\(bu" 3 If you didn\(cqt specify the desired outputs, but the derivation has an attribute \fCmeta.outputsToInstall\fR, Nix will use those outputs. For example, since the package \fCnixpkgs#libxml2\fR has this attribute: .LP .EX # nix eval 'nixpkgs#libxml2.meta.outputsToInstall' [ \(dqbin\(dq \(dqman\(dq ] .EE .IP a command like \fCnix shell nixpkgs#libxml2\fR will provide only those two outputs by default. .IP Note that a \fBstore derivation\fR doesn\(cqt have any attributes like \fCmeta\fR, and thus this case doesn\(cqt apply to it. .IP "\(bu" 3 Otherwise, Nix will use all outputs of the derivation. .SH Nix stores .LP Most \fCnix\fR subcommands operate on a \fINix store\fR. The various store types are documented in the \fBStore Types\fR section of the manual. .PP The same information is also available from the \fB\fCnix help-stores\fR\fR command. .SH Shebang interpreter .LP The \fCnix\fR command can be used as a \fC#!\fR interpreter. Arguments to Nix can be passed on subsequent lines in the script. .PP Verbatim strings may be passed in double backtick (\fC\(ga\(ga\fR) quotes. Sequences of \fIn\fR backticks of 3 or longer are parsed as \fIn-1\fR literal backticks. A single space before the closing \fC\(ga\(ga\fR is ignored if present. .PP \fC--file\fR and \fC--expr\fR resolve relative paths based on the script location. .PP Examples: .LP .EX #!/usr/bin/env nix #! nix shell --file \(ga\(ga\(ga\(ga hello cowsay --command bash hello | cowsay .EE .PP or with \fBflakes\fR: .LP .EX #!/usr/bin/env nix #! nix shell nixpkgs#bash nixpkgs#hello nixpkgs#cowsay --command bash hello | cowsay .EE .PP or with an \fBexpression\fR: .LP .EX #! /usr/bin/env nix #! nix shell --impure --expr \(ga\(ga #! nix with (import (builtins.getFlake \(dqnixpkgs\(dq) {}); #! nix terraform.withPlugins (plugins: [ plugins.openstack ]) #! nix \(ga\(ga #! nix --command bash terraform \(dq$@\(dq .EE .PP or with cascading interpreters. Note that the \fC#! nix\fR lines don\(cqt need to follow after the first line, to accomodate other interpreters. .LP .EX #!/usr/bin/env nix //! \(ga\(ga\(gacargo //! [dependencies] //! time = \(dq0.1.25\(dq //! \(ga\(ga\(ga /* #!nix shell nixpkgs#rustc nixpkgs#rust-script nixpkgs#cargo --command rust-script */ fn main() { for argument in std::env::args().skip(1) { println!(\(dq{}\(dq, argument); }; println!(\(dq{}\(dq, std::env::var(\(dqHOME\(dq).expect(\(dq\(dq)); println!(\(dq{}\(dq, time::now().rfc822z()); } // vim: ft=rust .EE .SH Options .SS Logging-related options .IP "\(bu" 3 \fB\fC--debug\fR\fR .IP Set the logging verbosity level to \(oqdebug\(cq. .IP "\(bu" 3 \fB\fC--log-format\fR\fR \fIformat\fR .IP Set the format of log output; one of \fCraw\fR, \fCinternal-json\fR, \fCbar\fR or \fCbar-with-logs\fR. .IP "\(bu" 3 \fB\fC--print-build-logs\fR\fR / \fC-L\fR .IP Print full build logs on standard error. .IP "\(bu" 3 \fB\fC--quiet\fR\fR .IP Decrease the logging verbosity level. .IP "\(bu" 3 \fB\fC--verbose\fR\fR / \fC-v\fR .IP Increase the logging verbosity level. .SS Miscellaneous global options .IP "\(bu" 3 \fB\fC--help\fR\fR .IP Show usage information. .IP "\(bu" 3 \fB\fC--offline\fR\fR .IP Disable substituters and consider all previously downloaded files up-to-date. .IP "\(bu" 3 \fB\fC--option\fR\fR \fIname\fR \fIvalue\fR .IP Set the Nix configuration setting \fIname\fR to \fIvalue\fR (overriding \fCnix.conf\fR). .IP "\(bu" 3 \fB\fC--refresh\fR\fR .IP Consider all previously downloaded files out-of-date. .IP "\(bu" 3 \fB\fC--version\fR\fR .IP Show version information. .RS .LP \fBNote\fR .PP See \fB\fCman nix.conf\fR\fR for overriding configuration settings with command line flags. .RE