NIX-STORE-DELETE(1)
β¨ NAME β¨
okay so welcome to the nix-store --delete(1) page, bestie β this is the one where we delete store paths. that's it, that's the whole vibe π
π SYNOPSIS π
nix-store --delete [--ignore-liveness] pathsβ¦
π¦ DESCRIPTION π¦
So the --delete operation deletes the store paths paths from the Nix store β but only if it's safe to do so. and "safe" here means: the path is not reachable from a root of the garbage collector. no cap.
Which basically means you can only delete paths that nix-store --gc would also have deleted anyway. so like... --delete is literally just --gc's more targeted, main-character little sister. same rules, but you get to pick the victims yourself β¨
Now with the --ignore-liveness option, the whole "reachability from the roots" thing gets ignored. BUT (and this is the important part, don't skip it π) the path still won't be deleted if there are other paths in the store that refer to it β i.e. that depend on it. so it's not a free-for-all, it's just a slightly less supervised one π«Ά
π OPTIONS π
The following options are allowed for all nix-store operations, but may not always have an effect. (yes, they show up everywhere. yes, sometimes they do nothing. it's giving "invited to every party, only sometimes dances" π)
--add-rootpath β makes the result of a realisation (--realiseand--force-realise) get registered as a root of the garbage collector. path gets created as a symlink pointing to the resulting store path. And on top of that, a uniquely named symlink pointing to path gets created in/nix/var/nix/gcroots/auto/. like, 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
So when /home/eelco/bla/result gets removed, the GC root over in the auto directory becomes a dangling symlink and the collector just ignores it. slay, cleanup handled π
β οΈ Warning: note that it is not possible to move or rename GC roots, because the symlink in the auto directory will still be pointing at the old location. so like... don't try it, it will not work, the symlink is committed to its ex π«
If there are multiple results, then multiple symlinks get created, by sequentially numbering the symlinks beyond the first one (e.g., foo, foo-2, foo-3, and so on). the way it just keeps counting π
okay that's the first chunk, bestie β there's more coming, don't go anywhere π§
π Common Options π
okay so bestie, here's the tea β most Nix commands accept this exact same lil squad of flags. Same options, everywhere. Learn 'em once, you're set for life. Slay. β¨
--helpβ prints out a summary of the command syntax and then exits. That's it, that's the whole job. π--versionβ prints the Nix version number on standard output and exits. Quick lil vibe check on what you're running.--verbose/-vβ turns the volume UP on diagnostic messages printed to standard error. Real talk: for every Nix operation, whatever gets printed on standard output is well-defined, and any diagnostic info goes to standard error β never standard output, no cap. You can pass this flag over and over again to keep cranking it. Currently these are the verbosity levels that exist:- 0 βErrors onlyβ β only prints messages explaining why the Nix invocation failed. Just the sad stuff. π
- 1 βInformationalβ β prints useful messages about what Nix is doing. This is the default, the main character setting. π
- 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 firehose. π€’
--quietβ turns the volume DOWN on diagnostic messages printed to standard error. It's the literal inverse option to-v/--verbose. You can pass this repeatedly too, and it walks down that same verbosity levels list from before. π«Ά--log-formatformat β use this to change the output of the log format, where format is one of:rawβ this is the raw format, as outputted bynix-build.internal-jsonβ outputs the logs in a structured manner.
β οΈ Warning β οΈ β the schema itself is relatively stable, but the format of the error-messages (namely of the msg-field) can change between releases. So don't you dare hard-code against it, bestie.
barβ only displays a progress bar during the builds.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 whole behaviour. β But heads up: the builder's standard output and error are always written to a log file inprefix/nix/var/log/nix, no matter what.--max-jobs/-jnumber β sets the maximum number of build jobs Nix will do in parallel to number. Passautoand it'll use the number of CPUs on your system. The default comes from themax-jobsconfiguration setting, which itself defaults to1. A higher value is useful on SMP systems or to exploit I/O latency. π₯ Setting it to0disallows building on the local machine β which is lowkey exactly what you want when you only want builds happening on remote builders. π--coresβ sets the value of theNIX_BUILD_CORESenvironment 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 attributeenableParallelBuildingis set totrue, the builder passes the-jNflag to GNU Make. It defaults to the value of thecoresconfiguration setting, if set, or1otherwise. The value0means the builder should use all available CPU cores in the system. Periodt. πͺ--max-silent-timeβ sets the maximum number of seconds that a builder can go without producing any data on standard output or standard error. Default comes from themax-silent-timeconfiguration setting.0means no time-out. Silent treatment: not tolerated. π--timeoutβ sets the maximum number of seconds that a builder can run. Default comes from thetimeoutconfiguration setting.0means no timeout. β°--keep-going/-kβ keeps going in case of failed builds, 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. 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's giving "the show must go on." π--keep-failed/-Kβ specifies 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. Perfect for when you wanna snoop on the crime scene. π--fallbackβ whenever Nix tries to build a derivation for which substitutes are known for each output path, but realising the 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 to do binary distribution from, say, a network repository. If the repository is down, the realisation of the derivation will fail. With this option, Nix will build the derivation instead. So installation from binaries falls back on installation from source. This isn't the default because 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). iykyk β those resources are not cheap bestie. π--readonly-modeβ when this is used, no attempt is made to open the Nix database. Most Nix operations do need database access, so those operations will fail. Look but don't touch energy. π--argname value β this option is 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 (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-leveldefault.nixin 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.) π€
--arg-from-filename path β passes the contents of file path as the argument name to Nix functions.--arg-from-stdinname β passes the contents of stdin as the argument name to Nix functions.--argstrname value β this one is like--arg, except the value is not a Nix expression, it's a string. So instead of--arg system \"i686-linux\"(the outer quotes are there to keep the shell happy) you can just say--argstr system i686-linux. So much cleaner, obsessed. β¨--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 expression e, the attribute pathxorg.xorgserverwould cause the expressione.xorg.xorgserverto be used. Seenix-env --installfor some concrete examples. On top of attribute names, you can also specify array indices. For instance, the attribute pathfoo.3.barselects thebarattribute of the fourth element of the array in thefooattribute of the top-level expression. (Yes, zero-indexed, bestie. The fourth element is index3. πΈ)--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.--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-buildandnix-shellonly.) Fornix-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 a shell that contains the built packages ready for use, give your expression to thenix-shell --packagesconvenience flag instead. Different vibe entirely. π¦-I/--includepath β adds an entry to the list of search paths used to resolve lookup paths. This option may be given multiple times. Paths added through-Itake precedence over thenix-pathconfiguration setting and theNIX_PATHenvironment variable. Boss energy, honestly. π--impureβ allows access to mutable paths and repositories. Living dangerously, 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. 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 undernix-store --repair-path. π’
π Note β see man nix.conf for overriding configuration settings with command line flags.
π Common Environment Variables π
Bestie. Okay. So most Nix commands read these lil env vars, and honestly they're the behind-the-scenes queens that decide where everything lives. Let's go one by one π«Ά
πΈ Configuration environment variables πΈ
These ones change how Nix loads its configuration. Full deets live in the configuration file documentation, but here's the quick tea:
NIX_CONF_DIRβ overrides the system configuration directory.NIX_USER_CONF_FILESβ overrides the user configuration file locations.NIX_CONFIGβ gives you configuration settings inline. Sneaky. Love it.
π₯ Store setting environment variables π₯
NIX_IGNORE_SYMLINK_STOREβ so normally the Nix store directory (typically/nix/store) is not allowed to contain any symlink components. That's on purpose, to prevent "impure" builds. See, builders sometimes "canonicalise" paths by resolving all symlink components, which means builds on different machines (where/nix/storeresolves to different places) could yield different results. Usually that's fine β except when builds get deployed to machines where/nix/storeresolves differently. If you're 100% sure you're not gonna do that, you can setNIX_IGNORE_SYMLINK_STOREto1.
Heads up: if you're symlinking the Nix store so you can put it on a different file system than the root file system, on Linux you're better off using bind mount points, like this:
$ mkdir /nix
$ mount -o bind /mnt/otherdisk/nix /nix
Consult the mount 8 manual page for the details, bestie π
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.
Check the Store Types chapter β each store has a store setting linking back to this as its default, iykyk.
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, again, no compile-time setting; 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. Main character energy β¨
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.
And yeah β 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 (peepNIX_STATE_DIRπ).
See the Local Daemon Store documentation for how the socket path is resolved.
TMPDIRβ use the directory you specify for temporary files. In particular this includes temporary build directories, and those can eat up a substantial amount of disk space. Default is/tmp.NIX_REMOTEβ overrides the store setting. That's it, that's the whole thing π
π¦ Nix language evaluator settings π¦
NIX_SHOW_STATSβ if set to1, Nix prints 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 sets the initial size of the heap in bytes. Defaults to384 MiB. Setting it low reduces memory consumption, but increases runtime because of the overhead of garbage collection. Pick your poison, babe.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, and the following env vars override where those live:
- user configuration directory:
NIX_CONFIG_HOME - user state directory:
NIX_STATE_HOME - user cache directory:
NIX_CACHE_HOME
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 (like nix-env and 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 π
When use-xdg-base-directories is enabled, the configuration directory is resolved like this:
$NIX_CONFIG_HOME, if it is defined- Otherwise, the platform default (e.g.
$XDG_CONFIG_HOME/nixon Unix)
Same logic for the state and cache directories. Periodt.
π 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 π
This info isn't Nix-specific, but it gets referenced above, so here it is anyway.
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) β 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%β per-user roaming application data%LOCALAPPDATA%β per-user local application data%PROGRAMDATA%β system-wide application data
β¨ Example β¨
Watch this, bestie β the classic "it's still alive" moment π
$ nix-store --delete /nix/store/gjak3al7lj61x4gj6rln4f5pc5v0f67n-mesa-6.4
0 bytes freed (0.00 MiB)
error: cannot delete path `/nix/store/gjak3al7lj61x4gj6rln4f5pc5v0f67n-mesa-6.4' since it is still alive
And that's a wrap on nix-store --delete(1) from the Nix manual, babe π go forth, delete responsibly, and remember that path is still alive fr fr. π¦π
πΈ
π¦ 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