I’m trying to use gomod2nix to build a simple http server that listen to a requests. Everything works well with my local modules. go run
and nix run
works perfectly, however when I add an outside module, go run
works but nix run
stop working. This is what I get after using an external module and trying to build/run the application with nix:
error: builder for '/nix/store/192rxacfr8al42fd0zaq74wk8dcqbh0g-sim-cards-bot-0.1.drv' failed with exit code 1;
last 10 log lines:
> Running phase: updateAutotoolsGnuConfigScriptsPhase
> Running phase: configurePhase
> Running phase: buildPhase
> Building subPackage .
> go: inconsistent vendoring in /build/bot:
> github.com/joho/godotenv@v1.5.1: is explicitly required in go.mod, but not marked as explicit in vendor/modules.txt
>
> To ignore the vendor directory, use -mod=readonly or -mod=mod.
> To sync the vendor directory, run:
> go work vendor
For full logs, run 'nix log /nix/store/192rxacfr8al42fd0zaq74wk8dcqbh0g-bot-0.1.drv'.
After reading the output I tried to add the -mod=readonly
and -mod=mod.
to the default.nix
but it gets the same output.
{ pkgs ? (
let
inherit (builtins) fetchTree fromJSON readFile;
inherit ((fromJSON (readFile ./flake.lock)).nodes) nixpkgs gomod2nix;
in
import (fetchTree nixpkgs.locked) {
overlays = [
(import "${fetchTree gomod2nix.locked}/overlay.nix")
];
}
)
, buildGoApplication ? pkgs.buildGoApplication
}:
buildGoApplication {
pname = "bot";
version = "0.1";
pwd = ./.;
src = ./.;
modules = ./gomod2nix.toml;
ldflags = [
"-mod=mod"
"-mod=readonly"
];
}
This is my tree:
├── container.nix
├── default.nix
├── Dockerfile
├── flake.lock
├── flake.nix
├── go.mod
├── gomod2nix.toml
├── go.sum
├── go.work
├── go.work.sum
├── helpers
│ ├── auth
│ ├── checkRequest.go
│ ├── go.mod
│ ├── go.sum
│ └── secrets.go
├── main.go
├── README.md
├── result -> /nix/store/az2pfxrkr8s6q66ryawmias66by388m2-docker-image-example.tar.gz
├── shell.nix
└── vendor
├── github.com
│ └── joho
│ └── godotenv
│ ├── godotenv.go
│ ├── LICENCE
│ ├── parser.go
│ └── README.md
└── modules.txt
Any help would be much appreciated it!!!