NIX-STORE-READ-LOG(1)

✨ nix-store --read-log(1) ✨

General Commands Manual πŸ’– nix-store --read-log(1)

okay bestie, sit down, hydrate, and let me tell you about the most lowkey iconic move in the nix-store playbook 🫢


🌸 NAME 🌸

nix-store --read-log β€” print build log πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

nix-store {--read-log | -l} paths…

⭐ DESCRIPTION ⭐

So the operation --read-log prints the build log of the store paths you name, straight onto standard output. The build log is literally whatever the builder of a derivation wrote to standard output and standard error. That's it, that's the tea. πŸ“

And if a store path isn't a derivation? No stress β€” the deriver of that store path gets used instead. iykyk.

Build logs live in /nix/var/log/nix/drvs. But β€” and this is the part where we vibe check reality β€” there is no guarantee that a build log is available for any particular store path. For instance, if the path was downloaded as a pre-built binary through a substitute, then the log is just... not there. gone. unavailable. 😭


πŸŽ€ OPTIONS πŸŽ€

The following options are allowed for all nix-store operations, but may not always have an effect. (Yes, all of them. She's versatile like that. πŸ‘‘)

  • --add-root path β€” causes the result of a realisation (--realise and --force-realise) to be registered as a root of the garbage collector. That path gets created as a symlink to the resulting store path. On top of that, a uniquely named symlink to path gets created in /nix/var/nix/gcroots/auto/. For instance:
$ nix-store --add-root /home/eelco/bla/result --realise ...

$ ls -l /nix/var/nix/gcroots/auto
lrwxrwxrwx    1 ... 2005-03-13 21:10 dn54lcypm8f8... -> /home/eelco/bla/result

$ ls -l /home/eelco/bla/result
lrwxrwxrwx    1 ... 2005-03-13 21:10 /home/eelco/bla/result -> /nix/store/1r11343n6qd4...-f-spot-0.0.10

Thus, when /home/eelco/bla/result is removed, the GC root in the auto directory becomes a dangling symlink and will be ignored by the collector. ✨ (iconic behavior honestly, she cleans up after herself)

⚠️ Warning ⚠️ Note that it is not possible to move or rename GC roots, since the symlink in the auto directory will still point to the old location. so like. don't do that. fr fr. πŸ’€

If there are multiple results, then multiple symlinks will be created by sequentially numbering symlinks beyond the first one (e.g., foo, foo-2, foo-3, and so on). numbering goes brrr 🧚


✨ Common Options ✨

okay so listen, bestie β€” most Nix commands lowkey share the same lil squad of command-line options, and once you know them you know them everywhere. here's the whole roster πŸ’…

  • --help β€” prints out a summary of the command syntax and then dips. that's it, that's the whole job.
  • --version β€” prints the Nix version number onto standard output and exits. short, sweet, iconic.
  • --verbose / -v β€” turns up the volume on the diagnostic messages that get printed on standard error. and here's the tea: for every Nix operation, whatever lands on standard output is well-defined, but any diagnostic info goes to standard error, never standard output. periodt.

you can stack this option multiple times btw. currently these are the verbosity levels that exist:

  • 0 β€œErrors only” β€” only prints messages explaining why the Nix invocation failed. no thoughts, just errors.
  • 1 β€œInformational” β€” prints useful messages about what Nix is doing. this is the default, bestie.
  • 2 β€œTalkative” β€” prints more informational messages.
  • 3 β€œChatty” β€” prints even more informational messages.
  • 4 β€œDebug” β€” prints debug information.
  • 5 β€œVomit” β€” prints vast amounts of debug information. it's giving chaos, honestly.
  • --quiet β€” turns the volume down on the diagnostic messages printed on standard error. it's the inverse option to -v / --verbose.

this one can also be specified repeatedly. go check the verbosity levels list above ↑

  • --log-format format β€” changes the output of the log format, where format is one of:
    • raw β€” the raw format, as outputted by nix-build.
    • internal-json β€” outputs the logs in a structured manner.
⚠️ Warning β€” while the schema itself is relatively stable, the format of the error-messages (namely of the msg-field) can change between releases. so don't get too attached, bestie 😭
  • bar β€” only display a progress bar during the builds.
  • bar-with-logs β€” display the raw logs, with the progress bar at the bottom.
  • --no-build-output / -Q β€” by default, output written by builders to standard output and standard error gets echoed to the Nix command's standard error. this option suppresses that behaviour. but heads up: the builder's standard output and error are always written to a log file in prefix/nix/var/log/nix, no cap.
  • --max-jobs / -j number β€” sets the maximum number of build jobs Nix will do in parallel to the number you give it. you can also say auto to use the number of CPUs on the system. the default is specified by the max-jobs configuration setting, which itself defaults to 1. a higher value is useful on SMP systems or when you wanna exploit I/O latency.

setting it to 0 disallows building on the local machine β€” super useful when you want builds to happen only on remote builders. remote work era 🫢

  • --cores β€” sets the value of the NIX_BUILD_CORES environment variable in the invocation of builders. builders can use this variable at their discretion to control the maximum amount of parallelism. for instance, in Nixpkgs, if the derivation attribute enableParallelBuilding is set to true, the builder passes the -jN flag to GNU Make. it defaults to the value of the cores configuration setting, if set, or 1 otherwise. and the value 0 means the builder should use all available CPU cores in the system. main character energy fr.
  • --max-silent-time β€” sets the maximum number of seconds that a builder can go without producing any data on standard output or standard error. the default is specified by the max-silent-time configuration setting. 0 means no time-out.
  • --timeout β€” sets the maximum number of seconds that a builder can run. the default is specified by the timeout configuration setting. 0 means no timeout.
  • --keep-going / -k β€” keep going in case of failed builds, to the greatest extent possible. that means if building an input of some derivation fails, Nix will still build the other inputs, but not the derivation itself. without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress (in case of parallel or distributed builds). it does not simply give up, and we love that for it.
  • --keep-failed / -K β€” says that in case of a build failure, the temporary directory (usually in /tmp) where the build takes place should not be deleted. the path of the build directory gets printed as an informational message so you can go snoop πŸ”
  • --fallback β€” whenever Nix attempts to build a derivation for which substitutes are known for each output path, but realising those output paths through the substitutes fails, fall back on building the derivation.

the most common scenario where this is useful is when we've registered substitutes in order to perform binary distribution from, say, a network repository. if the repository is down, the realisation of the derivation will fail. when this option is specified, Nix will build the derivation instead. so installation from binaries falls back on installation from source. this option is not the default, since it's generally not desirable for a transient failure in obtaining the substitutes to lead to a full build from source (with the related consumption of resources). your CPU did not sign up for that πŸ’€

  • --readonly-mode β€” when this option is used, no attempt is made to open the Nix database. most Nix operations do need database access, so those operations will fail. look don't touch mode, basically.
  • --arg name value β€” this option is accepted by nix-env, nix-instantiate, nix-shell and nix-build. when evaluating Nix expressions, the expression evaluator will automatically try to call functions that it encounters. it can automatically call functions for which every argument has a default value (e.g., { argName ? defaultValue }: ...).

with --arg, you can also call functions that have arguments without a default value (or override a default value). that is, if the evaluator encounters a function with an argument named name, it will call it with value value.

for instance, the top-level default.nix in Nixpkgs is actually a function:

{ # The system (e.g., `i686-linux') for which to build the packages.
system ? builtins.currentSystem
...
}: ...

so if you call this Nix expression (e.g., when you do nix-env --install --attr pkgname), the function will be called automatically using the value builtins.currentSystem for the system argument. you can override this using --arg, e.g., nix-env --install --attr pkgname --arg system "i686-freebsd". (note that since the argument is a Nix string literal, you have to escape the quotes.) sneaky but make it fashion.

  • --arg-from-file name path β€” pass the contents of file path as the argument name to Nix functions.
  • --arg-from-stdin name β€” pass the contents of stdin as the argument name to Nix functions.
  • --argstr name value β€” this option is like --arg, only the value is not a Nix expression but a string. so instead of --arg system "i686-linux" (the outer quotes are to keep the shell happy) you can say --argstr system i686-linux. so much cleaner, we stan 🌸
  • --attr / -A attrPath β€” select an attribute from the top-level Nix expression being evaluated. (nix-env, nix-instantiate, nix-build and nix-shell only.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expression e, the attribute path xorg.xorgserver would cause the expression e.xorg.xorgserver to be used. see nix-env --install for some concrete examples.

in addition to attribute names, you can also specify array indices. for instance, the attribute path foo.3.bar selects the bar attribute of the fourth element of the array in the foo attribute of the top-level expression. yes bestie, zero-indexed, count from 0 like a true nerd πŸ’œ

  • --eval-store store-url β€” the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drv files) and inputs referenced by them.
  • --expr / -E β€” interpret the command line arguments as a list of Nix expressions to be parsed and evaluated, rather than as a list of file names of Nix expressions. (nix-instantiate, nix-build and nix-shell only.)

for nix-shell, this option is commonly used to give you a shell in which you can build the packages returned by the expression. if you want to get a shell which contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. choose your fighter.

  • -I / --include path β€” add an entry to the list of search paths used to resolve lookup paths. this option may be given multiple times.

paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. so they're the VIPs at the front of the line πŸ‘‘

  • --impure β€” allow access to mutable paths and repositories.
  • --option name value β€” set the Nix configuration option name to value. this overrides settings in the Nix configuration file (see nix.conf5).
  • --repair β€” fix corrupted or missing store paths by redownloading or rebuilding them. note that this is slow, because it requires computing a cryptographic hash of the contents of every path in the closure of the build. also note the warning under nix-store --repair-path. sorry bestie, no shortcuts 😭
πŸ“ Note β€” see man nix.conf for overriding configuration settings with command line flags.

πŸ’– Common Environment Variables πŸ’–

okay so bestie, most Nix commands read the following environment variables. it's giving "the config lives in your shell, actually" 🫢

🧷 Configuration environment variables

these ones change how Nix loads its config. full deets live in the configuration file documentation, iykyk.

  • NIX_CONF_DIR β€” overrides the system configuration directory.
  • NIX_USER_CONF_FILES β€” overrides the user configuration file locations.
  • NIX_CONFIG β€” lets you hand over configuration settings inline, right there in the variable. iconic.

🏬 Store setting environment variables

  • NIX_IGNORE_SYMLINK_STORE

okay so normally the Nix store directory (typically /nix/store) is not allowed to contain any symlink components. why? to prevent "impure" builds. here's the tea: builders sometimes "canonicalise" paths by resolving all symlink components. so builds on different machines β€” where /nix/store resolves to different locations β€” could yield different results. this is generally not a problem, except when builds are deployed to machines where /nix/store resolves differently. if you're sure you're not gonna do that, you can set NIX_IGNORE_SYMLINK_STORE to 1. πŸ’…

note that if you're symlinking the Nix store so you can put it on another file system than the root file system, on Linux you're better off using bind mount points, e.g.

$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix

consult the mount 8 manual page for details. πŸ“–

  • NIX_STORE_DIR β€” overrides the location of the Nix store. on Unix, the default is /nix/store, set at compile time by the libstore:store-dir build option. on Windows there's no compile-time setting; the default is %PROGRAMDATA%\nix\store, determined at runtime using the %PROGRAMDATA% Known Folder.

see the Store Types chapter; each store has a store setting linking back to this as its default.

  • NIX_LOG_DIR β€” overrides the location of the Nix log directory. on Unix, the default is /nix/var/log/nix, set at compile time by the log-dir build option. on Windows, no compile-time setting; the default is %PROGRAMDATA%\nix\log, determined at runtime using the %PROGRAMDATA% Known Folder.

the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this.

  • NIX_STATE_DIR β€” overrides the location of the Nix state directory. on Unix, the default is ${localstatedir}/nix, where localstatedir is a compile-time build option defaulting to /nix/var. on Windows, no compile-time setting; the default is %PROGRAMDATA%\nix\state, determined at runtime using the %PROGRAMDATA% Known Folder.

the Local Store, Local Daemon Store, and Experimental SSH Store with filesystem mounted have per-store settings that override this too.

  • NIX_DAEMON_SOCKET_PATH β€” overrides the path to the Unix domain socket used to talk to the Nix daemon. defaults to daemon-socket/socket within the state directory (see NIX_STATE_DIR).

see the Local Daemon Store documentation for details on how the socket path is resolved.

  • TMPDIR β€” use the specified directory to store temporary files. in particular this includes temporary build directories, and bestie those can eat substantial amounts of disk space 😭. the default is /tmp.
  • NIX_REMOTE β€” overrides the store setting.

🧠 Nix language evaluator settings

  • NIX_SHOW_STATS β€” if set to 1, Nix will print some evaluation statistics, like the number of values allocated. ✨
  • NIX_COUNT_CALLS β€” if set to 1, Nix will print how often functions were called during Nix expression evaluation. super useful for profiling your Nix expressions.
  • GC_INITIAL_HEAP_SIZE β€” if Nix has been configured to use the Boehm garbage collector, this variable sets the initial size of the heap in bytes. it defaults to 384 MiB. setting it low reduces memory consumption, but will increase runtime due to the overhead of garbage collection. tradeoffs, amirite πŸ’€
  • NIX_PATH β€” a colon-separated list of search path entries used to resolve lookup paths.

this environment variable overrides the value of the nix-path configuration setting.

it can be extended using the -I option.

Example
$ export NIX_PATH=/home/eelco/Dev:nixos-config=/etc/nixos

if NIX_PATH is set to an empty string, resolving search paths will always fail. πŸ™ˆ

Example
$ NIX_PATH= nix-instantiate --eval '<nixpkgs>'
error: file 'nixpkgs' was not found in the Nix search path (add it using $NIX_PATH or -I)

🏠 User Directories

Nix supports per-user configuration, state, and cache directories. these environment variables override the locations for these directories:

  • user configuration directory: NIX_CONFIG_HOME
  • user state directory: NIX_STATE_HOME
  • user cache directory: NIX_CACHE_HOME

when these are not set, the defaults depend on the platform:

  • on Unix, the XDG base directories: $XDG_CONFIG_HOME/nix, $XDG_STATE_HOME/nix, $XDG_CACHE_HOME/nix
  • on Windows, the Windows Known Folders: %APPDATA%\nix\config, %LOCALAPPDATA%\nix\state, %LOCALAPPDATA%\nix\cache

for backwards compatibility, legacy Nix commands (e.g. nix-env, nix-channel) use dotfiles in $HOME instead of these directories unless use-xdg-base-directories is enabled. new Nix commands (experimental) use the proper directories by default. periodt. πŸ‘‘

when use-xdg-base-directories is enabled, the configuration directory is resolved as:

  1. $NIX_CONFIG_HOME, if it is defined
  2. otherwise, the platform default (e.g. $XDG_CONFIG_HOME/nix on Unix)

likewise for the state and cache directories.

πŸŽ€ Miscellaneous environment variables

  • IN_NIX_SHELL β€” indicator that tells if the current environment was set up by nix-shell. it can have the values pure or impure. πŸ¦‹

🌈 Appendix: OS-specific conventions 🌈

this information is not Nix-specific, but is referenced above. so here it is, for the lore. πŸ“š

🐧 Unix: XDG Base Directories

the XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.

the following environment variables are used:

  • XDG_CONFIG_HOME (default ~/.config)
  • XDG_STATE_HOME (default ~/.local/state)
  • XDG_CACHE_HOME (default ~/.cache)
  • XDG_CONFIG_DIRS (default /etc/xdg) β€” colon-separated list of additional configuration base directories, searched after XDG_CONFIG_HOME

πŸͺŸ Windows: Known Folders

on Windows, Known Folders provide standard locations for application data on Windows.

the relevant folders are:

  • %APPDATA% β€” per-user roaming application data
  • %LOCALAPPDATA% β€” per-user local application data
  • %PROGRAMDATA% β€” system-wide application data

⭐ Example ⭐

$ nix-store --read-log $(which ktorrent)
building /nix/store/dhc73pvzpnzxhdgpimsd9sw39di66ph1-ktorrent-2.2.1
unpacking sources
unpacking source archive /nix/store/p8n1jpqs27mgkjw07pb5269717nzf5f8-ktorrent-2.2.1.tar.gz
ktorrent-2.2.1/
ktorrent-2.2.1/NEWS
...

and that's the whole page, bestie πŸ«ΆπŸ’– this was the nix-store --read-log(1) manual β€” go read your logs, you ate. πŸŽ€βœ¨πŸ‘‘

πŸ“¦ where this page comes from