Skip to content

Commit 8218d13

Browse files
committed
update with Brian's comments about storage handling and runtime optimmization
1 parent 31c931b commit 8218d13

File tree

1 file changed

+31
-2
lines changed

1 file changed

+31
-2
lines changed

README-nix.md

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ alternatively `nix develop o1js#mina-shell` (which works better from MacOS).
8989
nix develop o1js#default
9090
```
9191
92-
You will observe that the current devshell becomes a Nix shell with the right
92+
The first time you run this command, you can expect it to take hours (or even a full day) to complete. Then, you will observe that the current devshell becomes a Nix shell with the right
9393
configuration for `o1js` and `mina`.
9494
9595
In order to make sure that the bindings will be regenerated in the case that you
@@ -123,6 +123,35 @@ cd ./src/mina
123123
nix develop mina
124124
```
125125

126+
## Desirable configurations
127+
128+
### Storage handling
129+
130+
Using Nix can take up a lot of disk space if not optimized. Every time you run `nix develop {SOMETHING}`, Nix will create new generations taking gigabytes of data instead of replacing the old ones. This can soon become a problem in your hard disk if you don't handle it carefully. Here are a few indications that can help with this.
131+
132+
Nix has a garbage collector that **is not used by default** after every run. Instead, artifacts get accumulated in your disk unless configured otherwise. But if the full gargabe collector is executed (`nix-store --gc`), it will get the dependencies removed completely, and you can expect that the next time executing the Nix build will take hours to complete.
133+
134+
Instead, you can try to run `nix-env --delete-generations old` or any other time bound like `7d`. This will not have any effect on MacOS though. Alternatively, the [direnv](https://github.com/direnv/direnv) / [nix-direnv](https://github.com/nix-community/nix-direnv) tool can create garbage collector roots that won't be collected for removal. It just keeps one gc-root to the latest build of the dev shell so that `nix-store --gc` only removes older generations.
135+
136+
On top of that, adding `auto-optimise-store = true` to `/etc/nix/nix.conf` and running `nix-store --optimize` shoud help with disk usage, as it replaces duplicated files with symlinks.
137+
138+
### Runtime optimization
139+
140+
Other configurations are worth adding into your `/etc/nix/nix.conf`:
141+
142+
```bash
143+
keep-otuputs = true
144+
max-jobs = 20
145+
extra-substituters = https://storage.googleapis.com/mina-nix-cache
146+
extra-trusted-public-keys = nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4= nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c= mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10=
147+
```
148+
149+
The first of those flags tells the garbage collector to keep build time dependencies of current gc-roots, which should help reduce the amount of data that gets removed and rebuilt.
150+
151+
The second flag increases the default number of jobs being 1, so that rebuilding from scratch will take shorter time.
152+
153+
The last two lines tell Nix to use the Mina Foundation's cache whenever possible, which should as well speed things up when building code that has been build in Mina's CI before.
154+
126155
## Common errors
127156

128157
Errors while using Nix have been reported. This section collects a set of common
@@ -268,4 +297,4 @@ Then, the error message would still contain old directories.
268297

269298
#### Fix
270299

271-
Create a new environment for Nix and start from scratch.
300+
Create a new environment for Nix and start from scratch. In particular, run the garbage collector which will remove old dependencies.

0 commit comments

Comments
 (0)