Package Linkerd (Go)

I can build Linkerd (21.6.2 or any later version) manually but not as a Nix package.

I understand the sandbox won’t allow network access. But I need to make it work somehow. Any ideas?


1 Like

Up and cc for guys that helped us:

cc: @tomberek @jnetod @ldesgoui @Gonzih

issue: linkerd-unstable contains no binary · Issue #113218 · NixOS/nixpkgs · GitHub

1 Like

That does build for me after removing runVend and deleteVendor attributes as well as fixing the vendorSha256, what is the error you get?

PS: Due to how the builder works the binary will be named cli, you might want to rename it in postInstall.

If you do that, it builds, but it is broken.
As package isn’t working, all the options are filling blanks. I haven’t found what works.
Without go generate, the application is dysfunctional.
It should work like this:
Try running it and see output.
Yes, it can be renamed.

Thanks for trying.

I just ran result/bin/cli and the help output from your paste was exactly what I got.

Also I didn’t say to remove the go generate. I just removed 2 attributes and fixed the vendor sha.

That is great then! I’ll give it a try!

Can you paste the code you are using?

I have removed runVend and deleteVendor attributes. UpdatedvendorSha256.

It doesn’t even build:

FATA[0000] open no such file or directory
exit status 1
pkg/charts/static/templates.go:1: running “go”: exit status 1

cat default.nix
{ lib, fetchFromGitHub, buildGoModule }:

buildGoModule rec {
  pname = "linkerd";
  version = "edge-21.6.2";

  src = fetchFromGitHub {
    owner = "linkerd";
    repo = "linkerd2";
    rev = version;
    sha256 = "sha256-kgdKH+cIYRg5A3+wrJJ7jcY6Xl206EwBYa37PT3xn1k=";

  preBuild = ''
    go generate ./pkg/charts/static
    go generate ./jaeger/static
    go generate ./multicluster/static
    go generate ./viz/static

  buildFlagsArray = [
    "-s -w"

  vendorSha256 = "sha256-i8vbotBWik/Yu28CZijrloo7t5HXXXpYNzxxLBNUag4=";

  doCheck = true;

  # deleteVendor = true; # Tried combinations.

  # runVend = true; # Tried combinations.

  subPackages = [ "cli" ];

  meta = with lib; {
    description = "A service mesh for Kubernetes and beyond";
    downloadPage = "";
    homepage = "";
    license = licenses.asl20;
    maintainers = with maintainers; [ Gonzih ];
$ nix-build -E 'with import <nixpkgs> {}; callPackage ./. {}' --keep-failed -I nixpkgs=channel:nixos-20.09
$ ./result/bin/cli | head
linkerd manages the Linkerd service mesh.

  linkerd [command]

Available Commands:
  check        Check the Linkerd installation for potential problems
  completion   Output shell completion code for the specified shell (bash, zsh or fish)
  diagnostics  Commands used to diagnose Linkerd components
  help         Help about any command

For some reason though I get the same error as you when building from nixos-21.05, so probably something changed with the Go version?

I am on nixos-unstable and can’t build too, same error as @superherointj.

Either I’m getting tired or these expressions are starting to look the same lol

Yeah, tried unstable as well, fails there too.

So whats the bet? Go version or some change in buildGoModule expression?

I have tried Go version and buildGoModule, 14, 15, 16 (current). But not 13 because it is unavailable.

So it has to be something in buildGoModule that changed between whats on nixos-20.09 and nixos-{unstable,21.05}.

Sadly I do not currently have the time to bisec that.

1 Like

Seems to break here:

@zowoq Any idea?

4e9f7bbf8573d07f7b0c87d97c026cd4aad5a758 is the first bad commit
commit 4e9f7bbf8573d07f7b0c87d97c026cd4aad5a758
Author: zowoq <>
Date:   Thu Oct 29 13:27:20 2020 +1000

    buildGo{Package,Module}: set trimpath in GOFLAGS
    Also drop removeReferencesTo
    `-trimpath` removes all file system paths from the compiled executable,
    this should improve reproducibility.

 pkgs/development/go-modules/generic/default.nix  | 14 +++-----------
 pkgs/development/go-packages/generic/default.nix | 13 +++----------
 2 files changed, 6 insertions(+), 21 deletions(-)

@kalbasit (GitHub user) answered me:

The only way to build something in Nix with network support is to create a separate derivation that includes the following attributes: outputHashMode, outputHashAlgo, outputHash similar to how the go-modules derivation work. Essentially, what you’ll have to do is to declare a new derivation that will use the src in question and does a go generate and only copies the generated files to $out which will be of a known hash as it’s a pure operation (Go generate the same thing unless there’s some timestamps in the generated code or something). Once you have that derivation working, you can refer to it to copy those files back to your source directory in a preBuild step.

The solution was found by @jnetod . PR is made here:

1 Like

What was the trick that worked, setting GOFLAGS to empty string?

1 Like

Yes. The Linkerd bisect cleared things a bit. But it was after I sent you the e-mail. Tricky package. We still made it. :smile:

Btw, thanks for helping.