···
<para>The function <varname>buildGoPackage</varname> builds
8
-
standard Go packages.
8
+
standard Go programs.
<example xml:id='ex-buildGoPackage'><title>buildGoPackage</title>
13
-
net = buildGoPackage rec {
14
-
name = "go.net-${rev}";
15
-
goPackagePath = "golang.org/x/net"; <co xml:id='ex-buildGoPackage-1' />
16
-
subPackages = [ "ipv4" "ipv6" ]; <co xml:id='ex-buildGoPackage-2' />
17
-
rev = "e0403b4e005";
13
+
deis = buildGoPackage rec {
14
+
name = "deis-${version}";
17
+
goPackagePath = "github.com/deis/deis"; <co xml:id='ex-buildGoPackage-1' />
18
+
subPackages = [ "client" ]; <co xml:id='ex-buildGoPackage-2' />
22
-
sha256 = "1g7cjzw4g4301a3yqpbk8n1d4s97sfby2aysl275x04g0zh8jxqp";
23
+
rev = "v${version}";
24
+
sha256 = "1qv9lxqx7m18029lj8cw3k7jngvxs4iciwrypdy0gd2nnghc68sw";
24
-
goPackageAliases = [ "code.google.com/p/go.net" ]; <co xml:id='ex-buildGoPackage-3' />
25
-
propagatedBuildInputs = [ goPackages.text ]; <co xml:id='ex-buildGoPackage-4' />
26
-
buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-5' />
27
-
disabled = isGo13;<co xml:id='ex-buildGoPackage-6' />
27
+
goDeps = ./deps.json; <co xml:id='ex-buildGoPackage-3' />
29
+
buildFlags = "--tags release"; <co xml:id='ex-buildGoPackage-4' />
···
50
-
In this example only <literal>code.google.com/p/go.net/ipv4</literal> and
51
-
<literal>code.google.com/p/go.net/ipv6</literal> will be built.
52
+
In this example only <literal>github.com/deis/deis/client</literal> will be built.
<callout arearefs='ex-buildGoPackage-3'>
57
-
<varname>goPackageAliases</varname> is a list of alternative import paths
58
-
that are valid for this library.
59
-
Packages that depend on this library will automatically rename
60
-
import paths that match any of the aliases to <literal>goPackagePath</literal>.
58
+
<varname>goDeps</varname> is where the Go dependencies of a Go program are listed
59
+
in a JSON format described below.
63
+
<callout arearefs='ex-buildGoPackage-4'>
63
-
In this example imports will be renamed from
64
-
<literal>code.google.com/p/go.net</literal> to
65
-
<literal>golang.org/x/net</literal> in every package that depend on the
66
-
<literal>go.net</literal> library.
65
+
<varname>buildFlags</varname> is a list of flags passed to the go build command.
73
+
<para>The <varname>goDeps</varname> attribute should point to a JSON file that defines which Go libraries
74
+
are needed and should be included in <varname>GOPATH</varname> for <varname>buildPhase</varname>.
78
+
<example xml:id='ex-goDeps'><title>deps.json</title>
80
+
[ <co xml:id='ex-goDeps-1' />
82
+
"goPackagePath": "gopkg.in/yaml.v2", <co xml:id='ex-goDeps-2' />
84
+
"type": "git", <co xml:id='ex-goDeps-3' />
85
+
"url": "https://gopkg.in/yaml.v2",
86
+
"rev": "a83829b6f1293c91addabc89d0571c246397bbf4",
87
+
"sha256": "1m4dsmk90sbi17571h6pld44zxz7jc4lrnl4f27dpd1l8g5xvjhh"
91
+
"include": "../../libs.json", <co xml:id='ex-goDeps-4' />
92
+
"packages": [ <co xml:id='ex-goDeps-5' />
93
+
"github.com/docopt/docopt-go",
94
+
"golang.org/x/crypto",
105
+
<callout arearefs='ex-goDeps-1'>
107
+
<varname>goDeps</varname> is a list of Go dependencies.
70
-
<callout arearefs='ex-buildGoPackage-4'>
111
+
<callout arearefs='ex-goDeps-2'>
72
-
<varname>propagatedBuildInputs</varname> is where the dependencies of a Go library are
73
-
listed. Only libraries should list <varname>propagatedBuildInputs</varname>. If a standalone
74
-
program is being built instead, use <varname>buildInputs</varname>. If a library's tests require
75
-
additional dependencies that are not propagated, they should be listed in <varname>buildInputs</varname>.
113
+
<varname>goPackagePath</varname> specifies Go package import path.
79
-
<callout arearefs='ex-buildGoPackage-5'>
117
+
<callout arearefs='ex-goDeps-3'>
81
-
<varname>buildFlags</varname> is a list of flags passed to the go build command.
119
+
<varname>fetch type</varname> that needs to be used to get package source. If <varname>git</varname>
120
+
is used there should be <varname>url</varname>, <varname>rev</varname> and <varname>sha256</varname>
121
+
defined next to it.
85
-
<callout arearefs='ex-buildGoPackage-6'>
125
+
<callout arearefs='ex-goDeps-4'>
87
-
If <varname>disabled</varname> is <literal>true</literal>,
88
-
nix will refuse to build this package.
127
+
<varname>include</varname> could be used to reuse <varname>goDeps</varname> between Go programs.
128
+
There is a common libs set in <varname><nixpkgs/pkgs/development/go-modules/libs.json></varname>
129
+
with pinned versions of many packages that you can reuse.
133
+
<callout arearefs='ex-goDeps-5'>
91
-
In this example the package will not be built for go 1.3. The <literal>isGo13</literal>
92
-
is an utility function that returns <literal>true</literal> if go used to build the
93
-
package has version 1.3.x.
135
+
<varname>packages</varname> enumerates all Go packages that will be imported from included file.
···
102
-
Reusable Go libraries may be found in the <varname>goPackages</varname> set. You can test
103
-
build a Go package as follows:
106
-
$ nix-build -A goPackages.net
You may use Go packages installed into the active Nix profiles by adding
the following to your ~/.bashrc:
···
122
-
<para>To extract dependency information from a Go package in automated way use <link xlink:href="https://github.com/kamilchm/go2nix">go2nix</link>.</para>
154
+
<para>To extract dependency information from a Go package in automated way use <link xlink:href="https://github.com/kamilchm/go2nix">go2nix</link>.
155
+
It can produce complete derivation and <varname>goDeps</varname> file for Go programs.</para>