Storage optimization: Difference between revisions
imported>Xav-ie m Add reasoning for why auto-optimise-store is not on automatically and what you can do instead |
imported>LucasWagler Rework automatic optimisation to differentiate the two methods. |
||
Line 1: | Line 1: | ||
A recurring problem with NixOS is lack of space on <code>/</code>. Even if you only | A recurring problem with NixOS is lack of space on <code>/</code>. Even if you only occasionally use Nix, it is easy for <code>/nix/store</code> to grow beyond reasonable sizes. What follows are generic notes on how to reduce the growth of the [[Nix store]]. | ||
== Optimising the store == | == Optimising the store == | ||
Here we demonstrate how to configure <code>nix</code> to save space via hardlinking store files. | Here we demonstrate how to configure <code>nix</code> to save space via hardlinking store files. | ||
=== Automatic === | |||
To turn on automatic optimisation | To turn on automatic optimisation of the nix store, set the following option in <code>/etc/nixos/configuration.nix</code>: | ||
{{file|configuration.nix|nix|<nowiki> | {{file|configuration.nix|nix|<nowiki> | ||
nix.optimise.automatic = true; | nix.optimise.automatic = true; | ||
nix.optimise.dates = [ "03:45" ]; # Optional; allows customizing optimisation schedule | |||
</nowiki>}} | </nowiki>}} | ||
Alternatively, the store can be optimised on ''every'' build. This may slow down builds, as discussed [https://github.com/NixOS/nix/issues/6033 here]. To enable this behavior, set the following option: | |||
{{file|configuration.nix|nix|<nowiki> | |||
nix.settings.auto-optimise-store = true; | |||
</nowiki>}} | |||
{{Tip|This option only applies to new files, so we recommend manually optimising your nix store when first setting this option.}} | |||
=== Manual === | |||
Run | Run | ||
{{ic|# nix-store --optimise}} | {{ic|# nix-store --optimise}}. | ||
This is a potentially long operation. | This is a potentially long operation. | ||