Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 125 lines 3.4 kB view raw
1{ 2 stdenv, 3 lib, 4 nixosTests, 5 nix-update-script, 6 buildGoModule, 7 fetchFromGitHub, 8 installShellFiles, 9 pkg-config, 10 gtk3, 11 libayatana-appindicator, 12 libX11, 13 libXcursor, 14 libXxf86vm, 15 ui ? false, 16 netbird-ui, 17 versionCheckHook, 18}: 19let 20 modules = 21 if ui then 22 { 23 "client/ui" = "netbird-ui"; 24 } 25 else 26 { 27 client = "netbird"; 28 management = "netbird-mgmt"; 29 signal = "netbird-signal"; 30 }; 31in 32buildGoModule (finalAttrs: { 33 pname = "netbird"; 34 version = "0.49.0"; 35 36 src = fetchFromGitHub { 37 owner = "netbirdio"; 38 repo = "netbird"; 39 tag = "v${finalAttrs.version}"; 40 hash = "sha256-Hv0A9/NTMzRAf9YvYGvRLyy2gdigF9y2NfylE8bLcTw="; 41 }; 42 43 vendorHash = "sha256-t/X/muMwHVwg8Or+pFTSEQEsnkKLuApoVUmMhyCImWI="; 44 45 nativeBuildInputs = [ installShellFiles ] ++ lib.optional ui pkg-config; 46 47 buildInputs = lib.optionals (stdenv.hostPlatform.isLinux && ui) [ 48 gtk3 49 libayatana-appindicator 50 libX11 51 libXcursor 52 libXxf86vm 53 ]; 54 55 subPackages = lib.attrNames modules; 56 57 ldflags = [ 58 "-s" 59 "-w" 60 "-X github.com/netbirdio/netbird/version.version=${finalAttrs.version}" 61 "-X main.builtBy=nix" 62 ]; 63 64 # needs network access 65 doCheck = false; 66 67 postPatch = '' 68 # make it compatible with systemd's RuntimeDirectory 69 substituteInPlace client/cmd/root.go \ 70 --replace-fail 'unix:///var/run/netbird.sock' 'unix:///var/run/netbird/sock' 71 substituteInPlace client/ui/client_ui.go \ 72 --replace-fail 'unix:///var/run/netbird.sock' 'unix:///var/run/netbird/sock' 73 ''; 74 75 postInstall = 76 lib.concatStringsSep "\n" ( 77 lib.mapAttrsToList ( 78 module: binary: 79 '' 80 mv $out/bin/${lib.last (lib.splitString "/" module)} $out/bin/${binary} 81 '' 82 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform && !ui) '' 83 installShellCompletion --cmd ${binary} \ 84 --bash <($out/bin/${binary} completion bash) \ 85 --fish <($out/bin/${binary} completion fish) \ 86 --zsh <($out/bin/${binary} completion zsh) 87 '' 88 ) modules 89 ) 90 + lib.optionalString (stdenv.hostPlatform.isLinux && ui) '' 91 install -Dm644 "$src/client/ui/assets/netbird-systemtray-connected.png" "$out/share/pixmaps/netbird.png" 92 install -Dm644 "$src/client/ui/build/netbird.desktop" "$out/share/applications/netbird.desktop" 93 94 substituteInPlace $out/share/applications/netbird.desktop \ 95 --replace-fail "Exec=/usr/bin/netbird-ui" "Exec=$out/bin/netbird-ui" 96 ''; 97 98 nativeInstallCheckInputs = [ 99 versionCheckHook 100 ]; 101 versionCheckProgram = "${placeholder "out"}/bin/${finalAttrs.meta.mainProgram}"; 102 versionCheckProgramArg = "version"; 103 # Disabled for the `netbird-ui` version because it does a network request. 104 doInstallCheck = !ui; 105 106 passthru = { 107 tests = { 108 nixos = nixosTests.netbird; 109 withUI = netbird-ui; 110 }; 111 updateScript = nix-update-script { }; 112 }; 113 114 meta = { 115 homepage = "https://netbird.io"; 116 changelog = "https://github.com/netbirdio/netbird/releases/tag/v${finalAttrs.version}"; 117 description = "Connect your devices into a single secure private WireGuard®-based mesh network with SSO/MFA and simple access controls"; 118 license = lib.licenses.bsd3; 119 maintainers = with lib.maintainers; [ 120 saturn745 121 loc 122 ]; 123 mainProgram = if ui then "netbird-ui" else "netbird"; 124 }; 125})