Skip to content

Commit 9f65969

Browse files
authored
Merge pull request #5795 from sellout/nix-cache-instructions
Add instructions for updating the Nix cache
2 parents 2da1dfe + 654e4cc commit 9f65969

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

nix/README.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,51 @@ nix develop '.#cabal-unison-parser-typechecker'
105105
cd unison-cli
106106
cabal run --enable-profiling unison-cli-main:exe:unison -- +RTS -p
107107
```
108+
109+
## updating the Nix cache
110+
111+
There is [a cache for Unison artifacts on Cachix](https://unison.cachix.org). It is primarily used for two purposes:
112+
113+
1. to keep an up-to-date development environment for Unison contributors and
114+
2. to maintain built versions of the last few releases.
115+
116+
Correspondingly, CI automatically updates the cache on merges to trunk (to satisfy the first use case) and on release tags to mostly satisfy the second.
117+
118+
### updating when the development environment changes
119+
120+
Any PR that affects the Nix development environment (e.g., touches flake.nix or files in nix/) should ensure the cache is updated before it’s merged into trunk – to avoid there being any time when contributors end up rebuilding the tooling locally.
121+
122+
The easiest way to do this is to manually run the [Nix development cache](https://github.com/unisonweb/unison/actions/workflows/nix-dev-cache.yaml) workflow on the PR’s branch (which may be located on your fork).
123+
124+
Depending on how much needs to be rebuilt, some or all of the jobs may fail. In this case, you can populate the cache from another machine[^1].
125+
126+
``` bash
127+
nix build .#all --accept-flake-config --json --keep-going --system ${system} \
128+
| jq --raw-output '.[].outputs | to_entries[].value' \
129+
| cachix --verbose push unison
130+
```
131+
(adapted from [the Cachix documentation](https://docs.cachix.org/pushing#pushing-runtime-closure))
132+
133+
`system` is generally the Nix system (e.g., `x86_64-linux`, `aarch64-darwin`) you are running this on, but you can also use different systems in some cases. E.g.,
134+
if you are running on an Apple silicon Mac, you can also run the above command using `--system x86_64-darwin` to cache Intel Mac derivations.
135+
136+
Another issue @sellout has run into is that `cachix` seems to crash a lot on at least some Macs. To keep re-trying until it succeeds, try
137+
138+
``` bash
139+
until
140+
nix build .#all --accept-flake-config --json --keep-going \
141+
| jq --raw-output '.[].outputs | to_entries[].value' \
142+
| cachix --verbose push unison
143+
do :
144+
done
145+
```
146+
147+
### updating after a release
148+
149+
After a release tag is made, we additionally need to [pin](https://unison.cachix.org#pins) the new releases in the cache, so they don’t expire.
150+
151+
```bash
152+
cachix pin unison "ucm-${version}-${system}" "/nix/store/${hash}-unison-cli-main-exe-unison-0.0.0"
153+
```
154+
155+
__NB__: Since the Cabal files don’t have the version set, the version in the Nix store will always be “0.0.0”, regardless of the actual release.

nix/haskell-nix-flake.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
pkgs.cachix
3535
pkgs.gettext # for envsubst, used by unison-src/builtin-tests/interpreter-tests.sh
3636
pkgs.hpack
37+
pkgs.jq # helpful when pushing to Cachix
3738
pkgs.pkg-config
3839
pkgs.stack-wrapped
3940
];

0 commit comments

Comments
 (0)