summary refs log tree commit diff
path: root/pkgs/tools/networking/netbird/default.nix
blob: 80cc4f097a217160582d5272d285709f007f7ed5 (plain) (blame)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
{ stdenv, lib, nixosTests, buildGoModule, fetchFromGitHub, installShellFiles
, pkg-config
, gtk3, libayatana-appindicator, libX11, libXcursor, libXxf86vm
, Cocoa, IOKit, Kernel, UserNotifications, WebKit
, ui ? false }:
let
  modules = if ui then {
    "client/ui" = "netbird-ui";
  } else {
    client = "netbird";
    management = "netbird-mgmt";
    signal = "netbird-signal";
  };
in
buildGoModule rec {
  pname = "netbird";
  version = "0.14.4";

  src = fetchFromGitHub {
    owner = "netbirdio";
    repo = pname;
    rev = "v${version}";
    sha256 = "sha256-AzWYJGYlUsgR5ihXwY9ZyN/pL5avionql/jwqhYKsxc=";
  };

  vendorHash = "sha256-8cVEujVKwKvO81H+ukVxQouVVH7uZm/FwK9RAKJLN2c=";

  nativeBuildInputs = [ installShellFiles ] ++ lib.optional ui pkg-config;

  buildInputs = lib.optionals (stdenv.isLinux && ui) [
    gtk3
    libayatana-appindicator
    libX11
    libXcursor
    libXxf86vm
  ] ++ lib.optionals (stdenv.isDarwin && ui) [
    Cocoa
    IOKit
    Kernel
    UserNotifications
    WebKit
  ];

  subPackages = lib.attrNames modules;

  ldflags = [
    "-s"
    "-w"
    "-X github.com/netbirdio/netbird/client/system.version=${version}"
    "-X main.builtBy=nix"
  ];

  # needs network access
  doCheck = false;

  postPatch = ''
    # make it compatible with systemd's RuntimeDirectory
    substituteInPlace client/cmd/root.go \
      --replace 'unix:///var/run/netbird.sock' 'unix:///var/run/netbird/sock'
    substituteInPlace client/ui/client_ui.go \
      --replace 'unix:///var/run/netbird.sock' 'unix:///var/run/netbird/sock'
  '';

  postInstall = lib.concatStringsSep "\n" (lib.mapAttrsToList
    (module: binary: ''
      mv $out/bin/${lib.last (lib.splitString "/" module)} $out/bin/${binary}
    '' + lib.optionalString (!ui) ''
      installShellCompletion --cmd ${binary} \
        --bash <($out/bin/${binary} completion bash) \
        --fish <($out/bin/${binary} completion fish) \
        --zsh <($out/bin/${binary} completion zsh)
    '')
    modules) + lib.optionalString (stdenv.isLinux && ui) ''
      mkdir -p $out/share/pixmaps
      cp $src/client/ui/disconnected.png $out/share/pixmaps/netbird.png

      mkdir -p $out/share/applications
      cp $src/client/ui/netbird.desktop $out/share/applications/netbird.desktop

      substituteInPlace $out/share/applications/netbird.desktop \
        --replace "Exec=/usr/bin/netbird-ui" "Exec=$out/bin/netbird-ui"
    '';

  passthru.tests.netbird = nixosTests.netbird;

  meta = with lib; {
    homepage = "https://netbird.io";
    changelog = "https://github.com/netbirdio/netbird/releases/tag/v${version}";
    description = "Connect your devices into a single secure private WireGuard®-based mesh network with SSO/MFA and simple access controls";
    license = licenses.bsd3;
    maintainers = with maintainers; [ misuzu ];
  };
}