Storage optimization: Difference between revisions
imported>Ianthehenry m try to make some of the language a little more clear |
imported>Ianthehenry larger tweaks to the section on pinning |
||
| Line 94: | Line 94: | ||
=== Pinning === | === Pinning === | ||
Running the following command: | |||
<syntaxhighlight lang="console"> | <syntaxhighlight lang="console"> | ||
$ nix-instantiate shell.nix --indirect --add-root | $ nix-instantiate shell.nix --indirect --add-root ./.nix-gc-roots/shell.drv ... | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Will create a persistent snapshot of your <code>shell.nix</code> dependencies, which then won't be garbage collected, as long as you have configured <code>keep-outputs = true</code> (and haven't changed the default of <code>keep-derivations = true</code>). This is useful if your project has a dependency with no substitutes available, or you don't want to spend time waiting to re-download your dependencies every time you enter the shell. | |||
You need to re-run that <code>nix-instantiate</code> command any time your <code>shell.nix</code> changes. | |||
And there is a subtle gotcha if your <code>shell.nix</code> happens to evaluate to more than one derivation: <code>nix-instantiate</code> will number each derivation sequentially, so if you change your <code>shell.nix</code> to contain ''fewer'' derivations, such that (for example) the name of the last GC root starts with <code>shell.drv-7</code>, then <code>shell.drv-{8,9,10,11,12...}</code> will be dangling and unused. | |||
The easiest way to get around this is to delete the <code>./.nix-gc-roots</code> directory periodically (i.e., any time you re-run the <code>nix-instantiate</code> command). | |||
Don't forget to periodically check your GC roots, and remove any that you no longer need. | |||
=== Automation === | === Automation === | ||