buildGoModule fails during tests

Hello, I’m trying to write a derivation for a Go module, but the build process breaks with an unclear network error that does not seem correlated with my system. The error is not transient and is not present when running tests outside Home Manager build process.

The same go module builds correctly if built directly from source (outside Nix). I’m using home-manager build, I’m not sure if this may be a cause (I’m a newbie to the Nix world and Home Manager felt more approachable).

This is my derivation:

{ stdenv, buildGoModule, fetchFromGitHub, lib }:

buildGoModule rec {
  pname = "elastic-package";
  version = "0.17.0";

  src = fetchFromGitHub {
    owner = "elastic";
    repo = "elastic-package";
    rev = "v${version}";
    sha256 = "0piqnw3gd9f3ymj06dzydaq09ajhw32f0gyms2bi6cm9q3vnidbs";
  };

  vendorSha256 = "02wpacmqjmmzmhxdzb19w7jwd2qwazszmwhybhfm4dxqwvcq2p4g";

  meta = with lib; {
    description = "Command line tool for developing Elastic Integrations";
    homepage = "https://github.com/elastic/elastic-package";
    license = licenses.elastic;
    platforms = platforms.linux;
  };
}

The build goes smooth until it execute package tests, where a test fails with the error

dial tcp: lookup raw.githubusercontent.com on [::1]:53: read udp [::1]:58217->[::1]:53: read: connection refused

This is the relevant log lines:

=== RUN   TestValidate_geo_point
    validate_test.go:230: 
                Error Trace:    validate_test.go:230
                Error:          Received unexpected error:
                                Get "https://raw.githubusercontent.com/elastic/ecs/1.10/generated/beats/fields.ecs.yml": dial tcp: lookup raw.githubusercontent.com on [::1]:53: read udp [::1]:58217->[::1]:53: read: connection refused
                                can't download the online schema (URL: https://raw.githubusercontent.com/elastic/ecs/1.10/generated/beats/fields.ecs.yml)

The build then ends with an error:

builder for '/nix/store/1bi9hrwrjwp8s1xlyzm5hmn6aiwqmpy2-elastic-package-0.17.0.drv' failed with exit code 1
cannot build derivation '/nix/store/06r0j5rhpc5swvq0csgvyvqbnmlywn16-home-manager-path.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/idl848qm1g1rk25hjf8r19ppiww3bsd1-home-manager-generation.drv': 1 dependencies couldn't be built
error: build of '/nix/store/idl848qm1g1rk25hjf8r19ppiww3bsd1-home-manager-generation.drv' failed

When I run tests on the source code for that package everything works as expected, so it seems something in my Nix environment causing this issue.

Any clue what could be going on producing this issue?
Thank you!

Nix builds do not have access to the network. You probably have sandboxed builds on (default in many cases). Common for this case is to disable that specific test or provide that needed schema via a file that is fetched in a reproducible way/fixed-output derivation.

1 Like