Commit 8319500
authored
refactor: greatly improves caching of rust packages (#144)
# Problem
The problem is broken into two separate parts. The first is that the
current Nix structure in the repository, with all packages being placed
into the `packages` cell block, does not reflect the actual contents of
the files. For example, in many cases, these packages are just Rust
libraries that produce zero artifacts during the build process. This
makes qualifying them as packages ambiguous at best and potentially
harmful at worst.
The second relates to the overall repository structure and how it
contributes to a problematic packaging experience. The repository is set
up as a cargo workspace where individual workspace members share the
cargo lockfile located at the workspace root. This is problematic in the
Nix ecosystem, which relies on lockfiles for reproducibly building
projects. The existing build process (which was copied over before the
`std` conversion) relied on building workspace members using this
lockfile which inadvertently added a dependency to the whole repository
into every single build. In other words, a change in one workspace
member would cause **all other workspace members** input hashes to
change, thus causing Nix to rebuild them unnecessarily. This is
particularly problematic when it comes to having proper caching. In the
current state, we effectively cannot reuse cache artifacts across
commits due to this unwanted dependency.
# Solution
The solution to the first stated problem is to refactor packages that
are strictly libraries into a separate cell block entitled `libraries`.
This at least clearly delineates these as packages that won't produce an
artifact (as is the default case with cargo libraries). However, the
utility of packaging these workspace members is still questionable. The
only real benefit I can foresee is possibly running unit tests during
the build process (which we are not currently doing). We should have a
follow-up action to discuss if these should just be removed instead to
reduce the size of the Nix codebase.
The solution to the second problem is a bit more creative. As noted, the
general structure of the repository, unfortunately, makes avoiding
bringing in unnecessary dependencies into the derivation closure
difficult. To get around this, the `mkPackage` function has been
reworked to minimize the number of unnecessary inputs being fed into the
underlying derivation. This is accomplished by working out the local
dependencies of a given package and only including those dependencies in
the final closure. This ensures that rebuilds will only happen when the
package or one of its dependencies changes.
In addition to the above two changes, the substitutes in the `flake.nix`
were updated to point to their proper values. This was causing some
builds to take over six hours because Nix was trying to "build the
world." It's worth nothing that this is primarily due to `voting-tools`
and its Haskell dependencies which are known to be unique and thus
heavily rely on an existing cache.File tree
18 files changed
+189
-91
lines changed- nix
- artifacts
- catalyst-toolbox
- chain-libs
- chain-wallet-libs
- jormungandr
- jortestkit
- lib
- vit-servicing-station
- vit-testing
- voting-tools-rs
18 files changed
+189
-91
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
| 40 | + | |
39 | 41 | | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
46 | 65 | | |
47 | | - | |
48 | 66 | | |
49 | | - | |
50 | | - | |
51 | 67 | | |
52 | | - | |
53 | 68 | | |
54 | 69 | | |
55 | 70 | | |
56 | 71 | | |
57 | 72 | | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | 73 | | |
64 | 74 | | |
65 | 75 | | |
66 | 76 | | |
67 | | - | |
68 | | - | |
| 77 | + | |
| 78 | + | |
69 | 79 | | |
70 | 80 | | |
71 | 81 | | |
72 | | - | |
| 82 | + | |
73 | 83 | | |
74 | 84 | | |
75 | 85 | | |
| |||
File renamed without changes.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | | - | |
21 | 18 | | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
| |||
Lines changed: 2 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | | - | |
15 | 12 | | |
16 | 13 | | |
17 | 14 | | |
18 | 15 | | |
19 | 16 | | |
20 | 17 | | |
21 | | - | |
| 18 | + | |
22 | 19 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
| 6 | + | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | | - | |
| 13 | + | |
16 | 14 | | |
17 | 15 | | |
18 | 16 | | |
19 | 17 | | |
20 | 18 | | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | 19 | | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | 20 | | |
Lines changed: 1 addition & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
11 | | - | |
12 | | - | |
| 10 | + | |
13 | 11 | | |
14 | 12 | | |
15 | 13 | | |
0 commit comments