summaryrefslogtreecommitdiff
path: root/Building Go applications or packages with Nix.md
blob: 27be8e1c42a46fec983c7ea8c66c794063544167 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
---
tags:
  - nix
---
In [[A nice way to test flake output]] we see a failing build due to `go build` requiring an intermediate caching step.

I learnt [from this article](https://discourse.nixos.org/t/go-package-compilation/29165/2) that there are some helper functions in Nixpkgs to build go packages that we should use.

The [Go](https://github.com/NixOS/nixpkgs/blob/master/lib/licenses.nix) section of the Nixpkgs manual describes this proces in detail.

Useful example:
```nix
{
  pet = buildGoModule rec {
    pname = "pet";
    version = "0.3.4";

    src = fetchFromGitHub {
      owner = "knqyf263";
      repo = "pet";
      rev = "v${version}";
      hash = "sha256-Gjw1dRrgM8D3G7v6WIM2+50r4HmTXvx0Xxme2fH9TlQ=";
    };

    vendorHash = "sha256-ciBIR+a1oaYH+H1PcC8cD8ncfJczk1IiJ8iYNM+R6aA=";

    meta = {
      description = "Simple command-line snippet manager, written in Go";
      homepage = "https://github.com/knqyf263/pet";
      license = lib.licenses.mit;
      maintainers = with lib.maintainers; [ kalbasit ];
    };
  };
}
```