Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 1 | # https://github.com/NixOS/nixpkgs/issues/14671#issuecomment-1016376290 |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 2 | { lib, pkgs, fetchFromGitHub, buildGoModule, plugins ? [ ] }: |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 3 | |
| 4 | with lib; |
| 5 | with pkgs; |
| 6 | |
| 7 | let |
| 8 | pluginSrc = fetchFromGitHub { |
| 9 | owner = "mholt"; |
| 10 | repo = "caddy-l4"; |
| 11 | rev = "aa8cf68a3b5197c45a8b4ffd99b74465f0b5a6b1"; |
| 12 | hash = "sha256-3KcoOAB+YkOU8qKM75uQo58/dljRBmP25dionQ9K2dc="; |
| 13 | }; |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 14 | caddySrc = fetchFromGitHub { |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 15 | owner = "caddyserver"; |
| 16 | repo = "caddy"; |
| 17 | rev = "v2.6.4"; |
| 18 | hash = "sha256-3a3+nFHmGONvL/TyQRqgJtrSDIn0zdGy9YwhZP17mU0="; |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 19 | }; |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 20 | |
| 21 | combinedSrc = stdenv.mkDerivation { |
| 22 | name = "caddy-src"; |
| 23 | |
| 24 | nativeBuildInputs = [ go ]; |
| 25 | |
| 26 | buildCommand = '' |
| 27 | export GOCACHE="$TMPDIR/go-cache" |
| 28 | export GOPATH="$TMPDIR/go" |
| 29 | |
| 30 | mkdir -p "$out/ourcaddy" |
| 31 | |
| 32 | cp -r ${caddySrc} "$out/caddy" |
| 33 | cp -r ${pluginSrc} "$out/plugin" |
| 34 | |
| 35 | cd "$out/ourcaddy" |
| 36 | |
| 37 | go mod init caddy |
| 38 | echo "package main" >> main.go |
| 39 | echo 'import caddycmd "github.com/caddyserver/caddy/v2/cmd"' >> main.go |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 40 | echo 'import _ "github.com/caddyserver/caddy/v2/modules/standard"' >> main.go |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 41 | echo 'import _ "github.com/mholt/caddy-l4"' >> main.go |
| 42 | echo "func main(){ caddycmd.Main() }" >> main.go |
| 43 | go mod edit -require=github.com/caddyserver/caddy/v2@v2.6.4 |
| 44 | go mod edit -replace github.com/caddyserver/caddy/v2=../caddy |
| 45 | go mod edit -require=github.com/mholt/caddy-l4@v0.0.0 |
| 46 | go mod edit -replace github.com/mholt/caddy-l4=../plugin |
| 47 | ''; |
| 48 | }; |
| 49 | in |
| 50 | buildGoModule { |
| 51 | name = "meowdy"; |
| 52 | |
| 53 | src = combinedSrc; |
| 54 | |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 55 | vendorHash = "sha256-a49J7gKBYi9mQLlg+YFGaOetvbup5yRrWzX7kicvy+o="; |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 56 | |
| 57 | overrideModAttrs = _: { |
| 58 | postPatch = "cd ourcaddy"; |
| 59 | |
| 60 | postConfigure = '' |
| 61 | go mod tidy |
| 62 | ''; |
| 63 | |
| 64 | postInstall = '' |
| 65 | mkdir -p "$out/.magic" |
| 66 | cp go.mod go.sum "$out/.magic" |
| 67 | ''; |
| 68 | }; |
| 69 | |
| 70 | postPatch = "cd ourcaddy"; |
| 71 | |
| 72 | postConfigure = '' |
| 73 | cp vendor/.magic/go.* . |
| 74 | ''; |
| 75 | } |