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 ocasionally 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}}.  
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 ====
=== Automatic ===
To turn on automatic optimisation for newer derivations, add the following option to <code>/etc/nixos/configuration.nix</code>:
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>}}


{{Tip|This option only applies to new files: so we recommend manually optimising your nix store in addition to this option.}}
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;
The reason this option is not default to true automatically is discussed here: https://github.com/NixOS/nix/issues/6033
</nowiki>}}


Turning this option on (currently) means that it will try to optimize everytime you build, further slowing builds and causing a lot of thrash. If you want to avoid this, set up a simple cron job for weekly or just run every once in a while.  
{{Tip|This option only applies to new files, so we recommend manually optimising your nix store when first setting this option.}}


==== Manual ====
=== Manual ===
Run  
Run  
{{ic|# nix-store --optimise}}  
{{ic|# nix-store --optimise}}.
This is a potentially long operation.  
This is a potentially long operation.