Go package tests run endlessly with nix-build but work in nix-shell

As part of the earth-view Nix module I advertised here a few weeks ago, I am rebuilding the Go modules into a small Go CLI program.

The program works fine and I plan to release it soon. I’m in the process of adding some tests, which work fine with go test ./....

However, I am facing a weird issue with both nix-build and nix build: the checkPhase never ends when I try to build the package! The build worked fine without the tests, so I disabled them for now.

Weirdly, if I enter a nix-shell and manually run the phases, everything is working fine.

Here is the source code. And below are the commands I run:

Build with nix build

# enable check phase
$ sed -i 's/doCheck = false;/doCheck = true;/' package.nix

$ nix build -L .#earth-view
earth-view> Running phase: unpackPhase
earth-view> unpacking source archive /nix/store/5fz0pjkqxxypdxxciw05zzqzavfhr7sm-src
earth-view> source root is src
earth-view> Running phase: patchPhase
earth-view> Running phase: updateAutotoolsGnuConfigScriptsPhase
earth-view> Running phase: configurePhase
earth-view> Running phase: buildPhase
earth-view> Building subPackage .
earth-view> Building subPackage ./cmd
earth-view> Building subPackage ./cmd/fetch
earth-view> Building subPackage ./cmd/list
earth-view> Building subPackage ./lib
earth-view> Running phase: checkPhase

Once the checkPhase is reached, my laptop fans start and quickly reach their max speed. I tried to let the checkPhase run for 5 minutes but it never ended, I had to kill the build. Note that running the tests are running fine with go test ./....

The same issue appears with nix-build:

$ nix-build -A earth-view
this derivation will be built:
  /nix/store/75j98kk617qrs4afy55d8axn9i7gmrhb-earth-view-1.0.0.drv
building '/nix/store/75j98kk617qrs4afy55d8axn9i7gmrhb-earth-view-1.0.0.drv'...
Running phase: unpackPhase
unpacking source archive /nix/store/9dvyi9p0kpvddfbb10mmdqsvy365m0jw-src
source root is src
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Running phase: buildPhase
Building subPackage .
Building subPackage ./cmd
Building subPackage ./cmd/fetch
Building subPackage ./cmd/list
Building subPackage ./lib
Running phase: checkPhase

Build through nix-shell

As mentioned, everything is fine when run manually with nix-shell

$ mv shell.nix _shell.nix
$ nix-shell
$ mkdir build && cd $_
$ export out=$PWD/out
$ source $stdenv/setup
$ set +e
$ genericBuild
Running phase: unpackPhase
unpacking source archive /nix/store/9dvyi9p0kpvddfbb10mmdqsvy365m0jw-src
source root is src
Running phase: patchPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: updateAutotoolsGnuConfigScriptsPhase
Running phase: configurePhase
Running phase: buildPhase
Building subPackage .
Building subPackage ./cmd
Building subPackage ./cmd/fetch
Building subPackage ./cmd/list
Building subPackage ./lib
Running phase: checkPhase
ok  	earth-view/cmd/fetch	0.934s
Running phase: installPhase
Running phase: fixupPhase
shrinking RPATHs of ELF executables and libraries in /home/nicolas/work/perso/earth-view/build/out
shrinking /home/nicolas/work/perso/earth-view/build/out/bin/earth-view
checking for references to /run/user/1000/ in /home/nicolas/work/perso/earth-view/build/out...
patching script interpreter paths in /home/nicolas/work/perso/earth-view/build/out
stripping (with command strip and flags -S -p) in  /home/nicolas/work/perso/earth-view/build/out/bin
shrinking RPATHs of ELF executables and libraries in /home/nicolas/work/perso/earth-view/build/out
shrinking /home/nicolas/work/perso/earth-view/build/out/bin/earth-view
checking for references to /run/user/1000/ in /home/nicolas/work/perso/earth-view/build/out...
patching script interpreter paths in /home/nicolas/work/perso/earth-view/build/out
stripping (with command strip and flags -S -p) in  /home/nicolas/work/perso/earth-view/build/out/bin

Any ideas?

What does the test do? Does it try to actually download something from the internet? If so, then (i) that won’t work, as the build is sandboxed, and (ii) you’re lacking proper error handling for the no-connectivity case.

Yes, some tests are actually trying to download things from the internet. So that’s the issue. However, I didn’t find any note about this in the manuals, that would have been great :sweat_smile:

Indeed, there isn’t any error handling for the no connectivity case, thanks for pointing this out! I’ll add this before releasing.

For what it’s worth, it’s documented in the nix.conf section, but that is quite hidden if you don’t know where to look for it.

2 Likes