I have here a mono-repo where we enabled some Nix tooling, but I have some difficulties with vendorHash
and go.mod
containing replacements replace bla/bla/bla -> ../../mymodule-a
.
The monorepo consists of components, e.g. a
and lib-common
- components
+- /lib-common <---------------------------------------+
| + go.mod |
| |
+- /a |
+ go.mod (has "replace company/lib-common -> ../lib-common")
+ default.nix
The component a
reuses a lib-common
which is also just a Go module.
I can build a
with Nix and the buildGoModule
function by setting the correct vendorHash
and also doing some gimick with
lib.fileset
library to include all relevant sources which a
needs to build
→ it needs components/lib-common
and it-self components/a
.
The question is: For local development this works great with replace ...
in go.mod
, however
the problem is:
- Whenever something changes in
lib-common
the user HAS to change thevendorHash
in thedefault.nix
, because if the user does not,
the Nix build indefault.nix
MAY take an old chached derivation for thegoModules
(the dependencies)
which includeslib-common
anda
might compile but does not have the current changes fromlib-common
which is bad
I am searching a way to kind of work around that problem.
Does anybody have anything in mind here which makes a nice tooling such that one does not need to
constantly think about these vendor hashes with the replace
tooling in place or a better option?.
I found the following things, but not sure of all the caveats.
-
Employ some automatism to remind the user of checking
vendorHash
(if its not current) and
updating it, but how?? Our Nix CI might have chached things and might just build the derivation although its wrong…
Maybe there is an option to delete all derivations with/nix/store/XXXXX-go-modules
or find the one whicha/default.nix
depends on?- Change everything to
vendorHash = null
andgo mod vendor
all components.
Pro: The update is easier asgo mod vendor
can be executed and notnix build
→ copy hash → replace indefault.nix
, but if 1. is not possible its still flawed…
- Change everything to
-
Adjust the builder (our custom one)
such that it deletes all<modulePaths>
s inreplace <modulePath> -> <rel-path>
from the fetched vendor folder in thepostInstall
step
of the builder and in thepreBuild
step we place a symlink atvendor/<modulePath>
→<rel-path>
such that the build succeeds. (tested this and might work)