Skip to content

Commit 24b2dc0

Browse files
committed
review
1 parent c021d77 commit 24b2dc0

File tree

3 files changed

+27
-22
lines changed

3 files changed

+27
-22
lines changed

.github/actions/build/action.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ runs:
2424
nix_conf: |
2525
keep-env-derivations = true
2626
keep-outputs = true
27-
extra-substituters = https://storage.googleapis.com/mina-nix-cache
28-
extra-trusted-public-keys = nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4= nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c= mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10=
2927
- name: Fallback to persistant nix
3028
# only available on some runners
3129
shell: bash

README-nix.md

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,11 @@ with all the dependencies required executing `nix develop o1js#default`.
8888
nix develop o1js#default
8989
```
9090
91-
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
91+
On macos the first time you run this command, you can expect it to take hours (or even a full day) to complete, due to the lack of cached builds.
92+
Then, you will observe that the current devshell becomes a Nix shell with the right
9293
configuration for `o1js` and `mina`.
9394
95+
9496
From within the shell, you can build o1js and update the bindings.
9597
9698
```console
@@ -114,28 +116,31 @@ nix develop mina
114116
115117
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.
116118
117-
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.
118-
119-
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.
119+
Nix has a garbage collector that **is not used by default** after every run. Instead, artifacts get accumulated in your disk unless configured otherwise.
120+
This is why we recomend `auto-optimise-store = true` (you will be prompted to accept this). You can also run `nix-store --optimize` retroactively.
120121
121-
On top of that, adding `auto-optimise-store = true` to `/etc/nix/nix.conf` and running `nix-store --optimize` should help with disk usage, as it replaces duplicated files with symlinks.
122+
If you still need to free up space you can run `nix-store --gc`, unfortunately this can slow down futurue nix builds by forcing you to rebuild dependencies.
123+
This can be mitigated with [direnv](https://github.com/direnv/direnv) and [nix-direnv](https://github.com/nix-community/nix-direnv) which can create garbage collector roots,
124+
keeping one gc-root to the latest build of the dev shell so that `nix-store --gc` won't remove it.
125+
You can also create a gc root any time you run `nix build` (until you remove `./result`) so running `nix build o1js#bindings` before `nix-store --gc` may also help.
122126
123127
### Runtime optimization
124128
125-
Other configurations are worth adding into your `/etc/nix/nix.conf`:
126-
127-
```bash
128-
keep-outputs = true
129-
max-jobs = 20
130-
extra-substituters = https://storage.googleapis.com/mina-nix-cache
131-
extra-trusted-public-keys = nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4= nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c= mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10=
132-
```
129+
We suggest a few settings in `flake.nix`.
130+
You will be prompted to accept or reject these the first time you use nix in this repo.
131+
You can also use `--accept-flake-config` to accept all of them.
133132
134-
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.
133+
`max-jobs = auto`
134+
For some reason the default is `1`.
135135
136-
The second flag increases the default number of jobs being 1, so that rebuilding from scratch will take shorter time.
136+
`auto-optimize-store = true;`
137+
When building slightly different versions of the same repo your nix store can fill up with coppies of the same files.
138+
This saves space by replacing them with symlinks.
137139
138-
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.
140+
`substituters = ...`
141+
`trusted-public-keys = ...`
142+
These make sure you are using the mina-nix-cache which will save time by downloading any derivations already available.
143+
Anything built in CI is added to this nix-cache, so it should make a big difference in build times.
139144
140145
## Common Issues
141146

flake.nix

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@
1717
nixConfig = {
1818
auto-optimize-store = true;
1919
max-jobs = "auto";
20+
#coppied from flake.nix in mina
21+
allow-import-from-derivation = "true";
2022
substituters =
21-
[ "https://cache.nixos.org https://cache.nixos.org/"
22-
"https://storage.googleapis.com/mina-nix-cache"
23+
[ "https://storage.googleapis.com/mina-nix-cache"
2324
];
2425
trusted-public-keys =
25-
[ "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY="
26-
"mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10="
26+
[ "mina-nix-cache-1:djtioLfv2oxuK2lqPUgmZbf8bY8sK/BnYZCU2iU5Q10="
27+
"nix-cache.minaprotocol.org:fdcuDzmnM0Kbf7yU4yywBuUEJWClySc1WIF6t6Mm8h4="
28+
"nix-cache.minaprotocol.org:D3B1W+V7ND1Fmfii8EhbAbF1JXoe2Ct4N34OKChwk2c="
2729
];
2830
};
2931
outputs = { self, nixpkgs-mina, nixpkgs-newer, flake-utils, ... }@inputs:

0 commit comments

Comments
 (0)