.\" -*- 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 \f(CRnix\fR - a tool for reproducible and declarative configuration management .SH Synopsis .LP \f(CRnix\fR [\fIoption\fR\[u2026]] \fIsubcommand\fR .PP where \fIsubcommand\fR is one of the following: .PP \fBHelp commands:\fR .IP "\(bu" 3 \fB\f(CRnix help\fR\fR - show help about \f(CRnix\fR or a particular subcommand .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix help-stores\fR\fR - show help about store types and their settings .LP \fBMain commands:\fR .IP "\(bu" 3 \fB\f(CRnix build\fR\fR - build a derivation or fetch a store path .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix flake\fR\fR - manage Nix flakes .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix profile\fR\fR - manage Nix profiles .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix run\fR\fR - run a Nix application .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix search\fR\fR - search for packages .LP \fBMain commands:\fR .IP "\(bu" 3 \fB\f(CRnix repl\fR\fR - start an interactive environment for evaluating Nix expressions .LP \fBInfrequently used commands:\fR .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix copy\fR\fR - copy paths between Nix stores .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix eval\fR\fR - evaluate a Nix expression .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix fmt\fR\fR - reformat your code in the standard style .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix path-info\fR\fR - query information about store paths .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix registry\fR\fR - manage the flake registry .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix why-depends\fR\fR - show why a package has another package in its closure .LP \fBUtility/scripting commands:\fR .IP "\(bu" 3 \fB\f(CRnix config\fR\fR - manipulate the Nix configuration .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix 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\f(CRnix env\fR\fR - manipulate the process environment .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix hash\fR\fR - compute and convert cryptographic hashes .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix key\fR\fR - generate and convert Nix signing keys .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix nar\fR\fR - create or inspect NAR files .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix realisation\fR\fR - manipulate a Nix realisation .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fB\f(CRnix store\fR\fR - manipulate a Nix store .LP \fBCommands for upgrading or troubleshooting your Nix installation:\fR .IP "\(bu" 3 \fB\f(CRnix 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\f(CRnix-command\fR experimental feature\fR, and subject to change without notice. .RE .PP Many \f(CRnix\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) .RS .IP "\(bu" 3 This is the default .RE .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBStore path\fR .RS .IP "\(bu" 3 This is assumed if the argument is a Nix store path or a symlink to a Nix store path .RE .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBNix file\fR, optionally qualified by an attribute path .RS .IP "\(bu" 3 Specified with \f(CR--file\fR/\f(CR-f\fR .RE .if n \ .sp -1 .if t \ .sp -0.25v .IP "\(bu" 3 \fBNix expression\fR, optionally qualified by an attribute path .RS .IP "\(bu" 3 Specified with \f(CR--expr\fR/\f(CR-E\fR .RE .LP For most commands, if no installable is specified, \f(CR.\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\f(CRflakes\fR\fR and \fB\f(CRnix-command\fR\fR experimental features, and subject to change without notice. .RE .PP Example: \f(CRnixpkgs#hello\fR .PP These have the form \fIflakeref\fR[\f(CR#\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 \f(CRnix flake\fR manual page\fR. Flake references are most commonly a flake identifier in the flake registry (e.g. \f(CRnixpkgs\fR), or a raw path (e.g. \f(CR/path/to/my-flake\fR or \f(CR.\fR or \f(CR../foo\fR), or a full URL (e.g. \f(CRgithub:nixos/nixpkgs\fR or \f(CRpath:.\fR) .PP When the flake reference is a raw path (a path without any URL scheme), it is interpreted as a \f(CRpath:\fR or \f(CRgit+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 \f(CRgit+file://[GIT_REPO_ROOT]?dir=[RELATIVE_FLAKE_DIR_PATH]\fR where \f(CRGIT_REPO_ROOT\fR is the path to the root of the git repository, and \f(CRRELATIVE_FLAKE_DIR_PATH\fR is the path (relative to the directory root) of the closest parent of the given path that contains a \f(CRflake.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 \f(CR.gitignore\fR or have never been \f(CRgit add\fR-ed will not be available in the flake. If this is undesirable, specify \f(CRpath:\fR explicitly; .IP For example, if \f(CR/foo/bar\fR is a git repository with the following structure: .LP .EX \&. └── baz ├── blah │  └── file.txt └── flake.nix .EE .IP Then \f(CR/foo/bar/baz/blah\fR will resolve to \f(CRgit+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 \f(CRpath:FLAKE_DIR_PATH\fR where \f(CRFLAKE_DIR_PATH\fR is the closest parent of the supplied path that contains a \f(CRflake.nix\fR file (within the same file-system). If no such directory exists, then Nix will error-out. .IP For example, if \f(CR/foo/bar/flake.nix\fR exists, then \f(CR/foo/bar/baz/\fR will resolve to \f(CRpath:/foo/bar\fR .LP If \fIattrpath\fR is omitted, Nix tries some default values; for most subcommands, the default is \f(CRpackages.\fR\fIsystem\fR\f(CR.default\fR (e.g. \f(CRpackages.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 \f(CRpackages.\fR\fIsystem\fR, \f(CRlegacyPackages.*system*\fR and the empty prefix. Thus, on \f(CRx86_64-linux\fR \f(CRnix build nixpkgs#hello\fR will try to build the attributes \f(CRpackages.x86_64-linux.hello\fR, \f(CRlegacyPackages.x86_64-linux.hello\fR and \f(CRhello\fR. .PP If \fIattrpath\fR begins with \f(CR.\fR then no prefixes or defaults are attempted. This allows the form \fIflakeref\fR[\f(CR#.\fR\fIattrpath\fR], such as \f(CRgithub:NixOS/nixpkgs#.lib.fakeSha256\fR to avoid a search of \f(CRpackages.*system*.lib.fakeSha256\fR .SS Store path .LP Example: \f(CR/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: \f(CR/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 (\f(CR\(ha\fR). .PP Example: \f(CR/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv\(haout\fR .PP All outputs can be referred to at once with the special syntax \f(CR\(ha*\fR. .PP Example: \f(CR/nix/store/p7gp6lxdg32h4ka1q398wd9r2zkbbz2v-hello-2.10.drv\(ha*\fR .SS Nix file .LP Example: \f(CR--file /path/to/nixpkgs hello\fR .PP When the option \f(CR-f\fR / \f(CR--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: \f(CR--expr 'import {}' hello\fR .PP When the option \f(CR--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 \f(CR--impure\fR if the expression references impure inputs (such as \f(CR\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 \f(CRbin\fR output that contains programs, and a \f(CRdev\fR output that provides development artifacts like C/C++ header files. The outputs on which \f(CRnix\fR commands operate are determined as follows: .IP "\(bu" 3 You can explicitly specify the desired outputs using the syntax \fIinstallable\fR\f(CR\(ha\fR\fIoutput1\fR\f(CR,\fR\fI\[u2026]\fR\f(CR,\fR\fIoutputN\fR — that is, a caret followed immediately by a comma-separated list of derivation outputs to select. For installables specified as \fBFlake output attributes\fR or \fBStore paths\fR, the output is specified in the same argument: .IP For example, you can obtain the \f(CRdev\fR and \f(CRstatic\fR outputs of the \f(CRglibc\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 For \f(CR-e\fR/\f(CR--expr\fR and \f(CR-f\fR/\f(CR--file\fR, the derivation output is specified as part of the attribute path: .LP .EX $ nix build -f '' 'glibc\(hadev,static' $ nix build --impure -E 'import { }' 'glibc\(hadev,static' .EE .IP This syntax is the same even if the actual attribute path is empty: .LP .EX $ nix build -E 'let pkgs = import { }; in pkgs.glibc' '\(hadev,static' .EE .IP "\(bu" 3 You can also specify that \fIall\fR outputs should be used using the syntax \fIinstallable\fR\f(CR\(ha*\fR. For example, the following shows the size of all outputs of the \f(CRglibc\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 \f(CRmeta.outputsToInstall\fR, Nix will use those outputs. For example, since the package \f(CRnixpkgs#libxml2\fR has this attribute: .LP .EX # nix eval 'nixpkgs#libxml2.meta.outputsToInstall' [ \(dqbin\(dq \(dqman\(dq ] .EE .IP a command like \f(CRnix 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 \f(CRmeta\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 \f(CRnix\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\f(CRnix help-stores\fR\fR command. .SH Shebang interpreter .LP The \f(CRnix\fR command can be used as a \f(CR#!\fR interpreter. Arguments to Nix can be passed on subsequent lines in the script. .PP Verbatim strings may be passed in double backtick (\f(CR\(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 \f(CR\(ga\(ga\fR is ignored if present. .PP \f(CR--file\fR and \f(CR--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 \f(CR#! 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\f(CR--debug\fR\fR .IP Set the logging verbosity level to \(oqdebug\(cq. .IP "\(bu" 3 \fB\f(CR--log-format\fR\fR \fIformat\fR .IP Set the format of log output; one of \f(CRraw\fR, \f(CRinternal-json\fR, \f(CRbar\fR or \f(CRbar-with-logs\fR. .IP "\(bu" 3 \fB\f(CR--print-build-logs\fR\fR / \f(CR-L\fR .IP Print full build logs on standard error. .IP "\(bu" 3 \fB\f(CR--quiet\fR\fR .IP Decrease the logging verbosity level. .IP "\(bu" 3 \fB\f(CR--verbose\fR\fR / \f(CR-v\fR .IP Increase the logging verbosity level. .SS Miscellaneous global options .IP "\(bu" 3 \fB\f(CR--help\fR\fR .IP Show usage information. .IP "\(bu" 3 \fB\f(CR--offline\fR\fR .IP Disable substituters and consider all previously downloaded files up-to-date. .IP "\(bu" 3 \fB\f(CR--option\fR\fR \fIname\fR \fIvalue\fR .IP Set the Nix configuration setting \fIname\fR to \fIvalue\fR (overriding \f(CRnix.conf\fR). .IP "\(bu" 3 \fB\f(CR--refresh\fR\fR .IP Consider all previously downloaded files out-of-date. .IP "\(bu" 3 \fB\f(CR--version\fR\fR .IP Show version information. .RS .LP \fBNote\fR .PP See \fB\f(CRman nix.conf\fR\fR for overriding configuration settings with command line flags. .RE