|
| 1 | +{ |
| 2 | + lib, |
| 3 | + buildGoModule, |
| 4 | + fetchzip, |
| 5 | + testers, |
| 6 | + wireguard-go, |
| 7 | +}: |
| 8 | + |
| 9 | +buildGoModule ( |
| 10 | + finalAttrs: |
| 11 | + let |
| 12 | + rev = "12269c2761734b15625017d8565745096325392f"; |
| 13 | + shortVer = "${finalAttrs.version} (${lib.substring 0 7 rev})"; |
| 14 | + in |
| 15 | + { |
| 16 | + pname = "wireguard-go"; |
| 17 | + version = "0-unstable-2023-12-11"; |
| 18 | + |
| 19 | + src = fetchzip { |
| 20 | + url = "https://git.zx2c4.com/wireguard-go/snapshot/wireguard-go-${rev}.tar.xz"; |
| 21 | + hash = "sha256-br7/dwr/e4HvBGJXh+6lWqxBUezt5iZNy9BFqEA1bLk="; |
| 22 | + }; |
| 23 | + |
| 24 | + postPatch = '' |
| 25 | + # Skip formatting tests |
| 26 | + rm -f format_test.go |
| 27 | +
|
| 28 | + # Inject version |
| 29 | + printf 'package main\n\nconst Version = "${shortVer}"' > version.go |
| 30 | + ''; |
| 31 | + |
| 32 | + vendorHash = "sha256-RqZ/3+Xus5N1raiUTUpiKVBs/lrJQcSwr1dJib2ytwc="; |
| 33 | + |
| 34 | + subPackages = [ "." ]; |
| 35 | + |
| 36 | + ldflags = [ "-s" ]; |
| 37 | + |
| 38 | + # No tests besides the formatting one are in root. |
| 39 | + # We can't override subPackages per-phase (and we don't |
| 40 | + # want to needlessly build packages that have build |
| 41 | + # constraints), so just use the upstream Makefile (that |
| 42 | + # runs `go test ./...`) to actually run the tests. |
| 43 | + checkPhase = '' |
| 44 | + runHook preCheck |
| 45 | + export GOFLAGS=''${GOFLAGS//-trimpath/} |
| 46 | + make test |
| 47 | + runHook postCheck |
| 48 | + ''; |
| 49 | + |
| 50 | + # Tests require networking. |
| 51 | + __darwinAllowLocalNetworking = finalAttrs.doCheck; |
| 52 | + |
| 53 | + postInstall = '' |
| 54 | + mv $out/bin/wireguard $out/bin/wireguard-go |
| 55 | + ''; |
| 56 | + |
| 57 | + passthru.tests.version = testers.testVersion { |
| 58 | + package = wireguard-go; |
| 59 | + version = "v${shortVer}"; |
| 60 | + }; |
| 61 | + |
| 62 | + meta = with lib; { |
| 63 | + description = "Userspace Go implementation of WireGuard"; |
| 64 | + homepage = "https://git.zx2c4.com/wireguard-go/about/"; |
| 65 | + license = licenses.mit; |
| 66 | + maintainers = with maintainers; [ |
| 67 | + kirelagin |
| 68 | + winter |
| 69 | + zx2c4 |
| 70 | + ]; |
| 71 | + mainProgram = "wireguard-go"; |
| 72 | + }; |
| 73 | + } |
| 74 | +) |
0 commit comments