go-mockery: fix env.CGO_ENABLED set to ""

instead of 0.

Note that the official docs specify that only 1 or 0 are valid:
https://pkg.go.dev/cmd/cgo and look for CGO_ENABLED.

If set to 'false', it gets rendered as an empty string:

$ nix derivation show nixpkgs#go-mockery | jq '.derivations[].env | {CGO_ENABLED}'
{
  "CGO_ENABLED": ""
}
$ nix derivation show nixpkgs#go-mockery_2 | jq '.derivations[].env | {CGO_ENABLED}'
{
  "CGO_ENABLED": ""
}

which has the same effect as not defining `env.CGO_ENABLED` at all,
i.e., it generates a dynamically linked executable:

$ nix shell nixpkgs#go-mockery
$ ldd $(which mockery)
	linux-vdso.so.1 (0x00007c440bdd3000)
	libresolv.so.2 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libresolv.so.2 (0x00007c440bdb8000)
	libpthread.so.0 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libpthread.so.0 (0x00007c440bdb3000)
	libc.so.6 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6 (0x00007c440ba00000)
	/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/ld-linux-x86-64.so.2 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib64/ld-linux-x86-64.so.2 (0x00007c440bdd5000)

ditto for v2:

$ nix shell nixpkgs#go-mockery_2
$ ldd $(which mockery)
	linux-vdso.so.1 (0x000077377575f000)
	libresolv.so.2 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libresolv.so.2 (0x0000773775744000)
	libpthread.so.0 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libpthread.so.0 (0x000077377573f000)
	libc.so.6 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/libc.so.6 (0x0000773775400000)
	/nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib/ld-linux-x86-64.so.2 => /nix/store/8kvxvr3pmsypxiypq4g8zy13glnfr7nx-glibc-2.42-67/lib64/ld-linux-x86-64.so.2 (0x0000773775761000)

whereas after setting it to 0:

$ nix derivation show .#go-mockery | jq '.derivations[].env | {CGO_ENABLED}'
{
  "CGO_ENABLED": "0"
}
$ nix derivation show .#go-mockery_2 | jq '.derivations[].env | {CGO_ENABLED}'
{
  "CGO_ENABLED": "0"
}

and now the executables are not dynamic, as intended:

$ nix shell .#go-mockery
$ ldd $(which mockery)
	not a dynamic executable

$ nix shell .#go-mockery_2
$ ldd $(which mockery)
	not a dynamic executable
This commit is contained in:
pancho horrillo
2026-07-08 15:01:48 +02:00
parent f205b5574f
commit b1ba85535d
2 changed files with 2 additions and 2 deletions
+1 -1
View File
@@ -28,7 +28,7 @@ buildGoModule (finalAttrs: {
"-X github.com/vektra/mockery/v${lib.versions.major finalAttrs.version}/internal/logging.SemVer=v${finalAttrs.version}"
];
env.CGO_ENABLED = false;
env.CGO_ENABLED = 0;
subPackages = [ "." ];
+1 -1
View File
@@ -30,7 +30,7 @@ buildGoModule (finalAttrs: {
"-X github.com/vektra/mockery/v${lib.versions.major finalAttrs.version}/pkg/logging.SemVer=v${finalAttrs.version}"
];
env.CGO_ENABLED = false;
env.CGO_ENABLED = 0;
subPackages = [ "." ];