# Go

The function `buildGoPackage` builds standard Go packages.

## buildGoPackage

    net = buildGoPackage rec {
      name = "go.net-${rev}";
      goPackagePath = "golang.org/x/net";
      subPackages = [ "ipv4" "ipv6" ];
      rev = "e0403b4e005";
      src = fetchFromGitHub {
        inherit rev;
        owner = "golang";
        repo = "net";
        sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp";
      };
      goPackageAliases = [ "code.google.com/p/go.net" ];
      propagatedBuildInputs = [ goPackages.text ];
      buildFlags = "--tags release";
      disabled = isGo13;
    };

is an example expression using buildGoPackage, the following arguments are of special significance to the function:

`goPackagePath` specifies the package's canonical Go import path.

`subPackages` limits the builder from building child packages that have not been listed. If `subPackages` is not specified, all child packages will be built.

In this example only `code.google.com/p/go.net/ipv4` and `code.google.com/p/go.net/ipv6` will be built.

`goPackageAliases` is a list of alternative import paths that are valid for this library. Packages that depend on this library will automatically rename import paths that match any of the aliases to `goPackagePath`.

In this example imports will be renamed from `code.google.com/p/go.net` to `golang.org/x/net` in every package that depend on the `go.net` library.

`propagatedBuildInputs` is where the dependencies of a Go library are listed. Only libraries should list `propagatedBuildInputs`. If a standalone program is being built instead, use `buildInputs`. If a library's tests require additional dependencies that are not propagated, they should be listed in `buildInputs`.

`buildFlags` is a list of flags passed to the go build command.

If `disabled` is `true`, nix will refuse to build this package.

In this example the package will not be built for go 1.3. The `isGo13` is an utility function that returns `true` if go used to build the package has version 1.3.x.

Reusable Go libraries may be found in the `goPackages` set. You can test build a Go package as follows:

    $ nix-build -A goPackages.net

You may use Go packages installed into the active Nix profiles by adding the following to your ~/.bashrc:

    for p in $NIX_PROFILES; do
        GOPATH="$p/share/go:$GOPATH"
    done

To extract dependency information from a Go package in automated way use go2nix.