NIX-STORE-ADD-FIXED(1)
nix-store --add-fixed β from the General Commands Manual π
okay bestie, pull up a chair πͺ because we're about to talk about nix-store --add-fixed and honestly? it's giving crafty. it's lowkey one of the most useful little corners of nix-store and i need you to be seated for it.
β¨ NAME β¨
nix-store --add-fixed β add paths to store using given hashing algorithm πΈ
π SYNOPSIS π
nix-store --add-fixed [--recursive] algorithm pathsβ¦
π DESCRIPTION π
so the operation --add-fixed adds the specified paths to the Nix store. periodt. that's the whole vibe.
but here's the twist that makes it iconic: unlike --add, paths are registered using the specified hashing algorithm, which means you get the same output path as a fixed-output derivation. the way that just *works*β¦ i'm obsessed. π«Ά
and why do we care? because this can be used for sources that are not available from a public url or broke since the download expression was written. like, the link died, the mirror's gone, it's over β but you have the file locally and you need nix to still love you. --add-fixed said "say less." π
this operation has the following options:
--recursiveβ use recursive instead of flat hashing mode, used when adding directories to the store. π
and one lil caveat ngl: paths that refer to symlinks are not dereferenced, but added to the store as symlinks with the same target. so the symlink stays a symlink, living its best truth. π¦
π OPTIONS π
the following options are allowed for all nix-store operations, but may not always have an effect. (iykyk β they're the universal ones that only show up to the party when they feel like it. π)
--add-rootpath
causes the result of a realisation (--realise and --force-realise) to be registered as a root of the garbage collector. GC can't touch it, bestie, it's protected. β¨
path will be created as a symlink to the resulting store path. and in addition, a uniquely named symlink to path will be 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. it's fine, it's fine, the collector just looks past it like it's not there π
β οΈ 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 try it. it will not slay, it will simply break. π«
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). cute little numbered babies, one after another. π
β¨ Common Options β¨
okay bestie so like, most Nix commands out here accept these same lil command-line options. group chat rules, everybody plays nice π
--helpβ prints out a summary of the command syntax and then dips, exit stage left. that's it, that's the option.--versionβ prints the Nix version number to standard output and bounces.--verbose,-vβ turns up the volume on the diagnostic messages that go to standard error. here's the tea: for every Nix operation, what lands on standard output is well-defined; any and all diagnostic chatter goes to standard error, never to standard output. periodt.
you can stack this option over and over. rn these are the verbosity levels that exist:
0βErrors onlyβ β only prints messages explaining why the Nix invocation failed. tragic but necessary π1βInformationalβ β prints useful messages about what Nix is doing. this is the default, the main character π2βTalkativeβ β more informational messages, it's yapping π£οΈ3βChattyβ β even more informational messages4βDebugβ β prints debug information5βVomitβ β prints vast amounts of debug information. yes it's literally called that π
--quietβ turns the volume down on diagnostic messages going to standard error. it's the inverse option to-v/--verbose, they're giving enemies to lovers π«Ά
you can stack this one repeatedly too. go check that verbosity levels list above, same energy.
--log-formatformat β changes how the log output looks. format is one of:rawβ the raw format, exactly as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner, very organized, very demure β¨
β οΈ Warning β while the schema itself is relatively stable, the format of the error-messages (namely of the msg-field) can legitimately change between releases. don't get too comfy.
barβ only displays a progress bar during the builds. minimalism, we love her πbar-with-logsβ displays the raw logs, with the progress bar chilling 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, like "we don't need to see that". heads up tho: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix. always always. no cap.--max-jobs,-jnumber β sets the max number of build jobs Nix will run in parallel to that number. putautothere and it uses the number of CPUs in your system, so unserious of you to guess it yourself. the default comes from themax-jobsconfiguration setting, which itself defaults to1. a higher value is handy on SMP systems or to exploit I/O latency.
setting it to 0 disallows building on the local machine β which is exactly what you want when you only want builds happening on remote builders. bye local, it's not you it's me π
--coresβ sets the value of theNIX_BUILD_CORESenvironment variable in the invocation of builders. builders can use that variable at their discretion to control the maximum amount of parallelism. for instance, in Nixpkgs, if the derivation attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. it defaults to the value of thecoresconfiguration setting if that's set, or1otherwise. the value0means the builder should use all available CPU cores in the system. go big πββοΈ--max-silent-timeβ sets the max number of seconds a builder can go without producing any data on standard output or standard error. silence is NOT golden here bestie. default comes from themax-silent-timeconfiguration setting.0means no time-out.--timeoutβ sets the max number of seconds that a builder can run. default comes from thetimeoutconfiguration setting.0means no timeout. run free.--keep-going,-kβ keeps going when builds fail, to the greatest extent possible. like, if building an input of some derivation fails, Nix will still build the other inputs, but not the derivation itself (that one's cooked). without this option, Nix stops if any build fails (except for builds of substitutes), possibly killing builds in progress β yeah, in the case of parallel or distributed builds it will absolutely take other builds down with it π--keep-failed,-Kβ says that when a build fails, the temporary directory (usually in/tmp) where the build was happening should NOT be deleted. the path of the build directory gets printed as an informational message, so you can go investigate like the detective you are π΅οΈββοΈ--fallbackβ whenever Nix tries to build a derivation for which substitutes are known for each output path, but realising the output paths through those substitutes fails, it falls back on building the derivation instead.
the most common scenario where this saves you: you've got registered substitutes to do binary distribution from, say, a network repository. if that repository is down, realising the derivation fails. with this option, Nix just builds the derivation instead. so installation from binaries falls back on installation from source. it's NOT the default because it's generally not desirable for a transient failure in getting the substitutes to lead to a full build from source (plus all the resources that eats up). so it's a "ask for me by name" situation.
--readonly-modeβ when this is on, no attempt is made to open the Nix database. most Nix operations do need database access, so those operations will fail. so like, only use this when you know what you're doing π--argname value β accepted bynix-env,nix-instantiate,nix-shellandnix-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, like{ argName ? defaultValue }: ....
with --arg, you can also call functions that have arguments without a default value (or override a default value). basically, if the evaluator encounters a function with an argument named name, it'll call it with the value you gave.
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 (like when you do nix-env --install --attr pkgname), the function gets called automatically using the value builtins.currentSystem for the system argument. you can override that with --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 β yes, them's the rules.)
--arg-from-filename path β passes the contents of the file path as the argument name to Nix functions. file-based queen πΈ--arg-from-stdinname β passes the contents of stdin as the argument name to Nix functions.--argstrname value β like--arg, only the value is not a Nix expression, it's a string. so instead of--arg system \"i686-linux\"(the outer quotes are just to keep your shell happy), you can just say--argstr system i686-linux. so much simpler, we stan convenience π--attr,-AattrPath β selects an attribute from the top-level Nix expression being evaluated. (nix-env,nix-instantiate,nix-buildandnix-shellonly.) the attribute path attrPath is a sequence of attribute names separated by dots. for instance, given a top-level Nix expressione, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. go checknix-env --installfor some concrete examples.
and plot twist: 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, fourth, because counting starts at zero, we been knew.)
--eval-storestore-url β the URL to the Nix store to use for evaluation, i.e. where to store derivations (.drvfiles) and inputs referenced by them. it's giving "this is where the lore lives" π--expr,-Eβ interprets the command line arguments as a list of Nix expressions to be parsed and evaluated, instead of as a list of file names of Nix expressions. (nix-instantiate,nix-buildandnix-shellonly.)
for nix-shell, this option is commonly used to give you a shell where you can build the packages returned by the expression. if you want a shell that contains the built packages ready for use, give your expression to the nix-shell --packages convenience flag instead. different vibe, different tool.
-I,--includepath β adds an entry to the list of search paths used to resolve lookup paths. you can give this option multiple times, stack it up π
paths added through -I take precedence over the nix-path configuration setting and the NIX_PATH environment variable. they're the priority, they're the moment.
--impureβ allows access to mutable paths and repositories. living dangerously, we love that for you π¦--optionname value β sets the Nix configuration option name to value. this overrides settings in the Nix configuration file (seenix.conf5).--repairβ fixes corrupted or missing store paths by redownloading or rebuilding them. heads up though: this is slow, because it requires computing a cryptographic hash of the contents of every path in the closure of the build. that's a LOT of hashing. also go read the warning undernix-store --repair-path. seriously, go read it π
π Note β see man nix.conf for overriding configuration settings with command line flags.
π Common Environment Variables π
Okay bestie, most Nix commands read these environment variables, so let's get into it. π«Ά
Configuration environment variables
These cuties control how Nix loads its configuration. Peep the configuration file documentation for the full tea.
NIX_CONF_DIRβ overrides the system configuration directory. πNIX_USER_CONF_FILESβ overrides the user configuration file locations.NIX_CONFIGβ hands you config settings inline, right there, no file needed. Slay.
Store setting environment variables
NIX_IGNORE_SYMLINK_STOREβ normally, the Nix store directory (usually/nix/store) is not allowed to contain any symlink components. Why? To prevent "impure" builds. Builders sometimes "canonicalise" paths by resolving every symlink component, which means builds on different machines (with/nix/storeresolving to different places) could give you different results. This is usually fine... except when builds get deployed to machines where/nix/storeresolves differently. If you're sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
Ngl, if you're symlinking the Nix store so you can stash it on another file system than the root file system, on Linux you're better off using bind mount points, like:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
(Go read the mount 8 manual page for the deets.)
NIX_STORE_DIRβ overrides the location of the Nix store. On Unix, the default is/nix/store, set at compile time by thelibstore:store-dirbuild 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; every store has a store setting that links 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 thelog-dirbuild 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 all 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, wherelocalstatediris 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 todaemon-socket/socketwithin the state directory (seeNIX_STATE_DIR).
See the Local Daemon Store documentation for how the socket path gets resolved.
TMPDIRβ use the specified directory to store temporary files. In particular, this includes temporary build directories, which can eat up substantial amounts of disk space. Default is/tmp.NIX_REMOTEβ overrides the store setting. That's it, that's the whole vibe.
Nix language evaluator settings
NIX_SHOW_STATSβ if set to1, Nix will print some evaluation statistics, like the number of values allocated. πNIX_COUNT_CALLSβ if set to1, Nix prints 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 to384 MiB. Setting it low reduces memory consumption, but it'll increase runtime due to the overhead of garbage collection. Tradeoffs, bestie.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. The following environment variables override the locations for these directories:
[user configuration directory]{#user-conf-dir}:[NIX_CONFIG_HOME]{#env-NIXCONFIGHOME}- user state directory:
[NIX_STATE_HOME]{#env-NIXSTATEHOME} - user cache directory:
[NIX_CACHE_HOME]{#env-NIXCACHEHOME}
When these aren't 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:
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon Unix)
Likewise for the state and cache directories. Same energy all around. β¨
Miscellaneous environment variables
IN_NIX_SHELLβ an indicator that tells you whether the current environment was set up bynix-shell. It can have the valuespureorimpure. πΈ
π Appendix: OS-specific conventions
Just so you know, this info isn't Nix-specific, it's just referenced above. π
Unix: XDG Base Directories
The XDG Base Directory Specification defines standard locations for user-specific configuration, state, and cache files on Unix systems.
The environment variables it uses:
[XDG_CONFIG_HOME]{#env-XDGCONFIGHOME}(default~/.config)[XDG_STATE_HOME]{#env-XDGSTATEHOME}(default~/.local/state)[XDG_CACHE_HOME]{#env-XDGCACHEHOME}(default~/.cache)[XDG_CONFIG_DIRS]{#env-XDGCONFIGDIRS}(default/etc/xdg) β a colon-separated list of additional configuration base directories, searched afterXDG_CONFIG_HOME
Windows: Known Folders
On Windows, Known Folders provide standard locations for application data.
The relevant folders are:
[%APPDATA%]{#env-APPDATA}β per-user roaming application data[%LOCALAPPDATA%]{#env-LOCALAPPDATA}β per-user local application data[%PROGRAMDATA%]{#env-PROGRAMDATA}β system-wide application data
β¨ Example β¨
$ nix-store --add-fixed sha256 ./hello-2.10.tar.gz
/nix/store/8alrpdaasjd1x6g1fczchmzbpqm936a3-hello-2.10.tar.gz
And that's the whole page, bestie β nix-store --add-fixed(1), delivered with all the love. π Go add some fixed-output paths and be iconic. ππ
π¦ where this page comes from
- fedora 44: nix-legacy 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