Go: Difference between revisions
imported>Milahu link to implementation of buildGoModule |
imported>Milahu move buildGoPackage to separate section, add link to implementation |
||
| Line 2: | Line 2: | ||
== Packaging go modules == | == Packaging go modules == | ||
The nixpkgs library function '''buildGoModule''' ([https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/go-modules/generic/default.nix implementation]) works in most cases of packaging go modules or applications. | |||
See [https://nixos.org/manual/nixpkgs/stable/#sec-language-go nixpkgs manual '''Language: Go'''] | See [https://nixos.org/manual/nixpkgs/stable/#sec-language-go nixpkgs manual '''Language: Go'''] | ||
=== | === buildGoModule === | ||
the <tt>go.mod</tt> file must be in the source root for <tt>buildGoModule</tt>. | the <tt>go.mod</tt> file must be in the source root for <tt>buildGoModule</tt>. | ||
to change the source root, use | to change the source root, use | ||
| Line 16: | Line 16: | ||
}; | }; | ||
</syntaxhighlight> | </syntaxhighlight> | ||
=== buildGoPackage === | |||
If no <tt>go.mod</tt> file is available, '''buildGoPackage''' ([https://github.com/NixOS/nixpkgs/blob/master/pkgs/development/go-packages/generic/default.nix implementation]) can be used. | |||
Dependencies must be specified manually in a <tt>deps.nix</tt> file, | |||
which is linked with | |||
<syntaxhighlight lang=nix> | |||
some-package = buildGoPackage { | |||
# ... | |||
goDeps = ./deps.nix; | |||
}; | |||
</syntaxhighlight> | |||
The <tt>deps.nix</tt> file can be generated with helper tools | |||
such as [https://github.com/nix-community/vgo2nix vgo2nix] | |||
and [https://github.com/tweag/gomod2nix gomod2nix]. | |||
==Install using Home Manger== | ==Install using Home Manger== | ||