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 |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 8 | caddySrc = fetchFromGitHub { |
| 9 | # github.com/caddyserver/caddy/v2 |
| 10 | owner = "caddyserver"; |
| 11 | repo = "caddy"; |
| 12 | rev = "v2.6.4"; |
| 13 | hash = "sha256-3a3+nFHmGONvL/TyQRqgJtrSDIn0zdGy9YwhZP17mU0="; |
| 14 | }; |
| 15 | l4Src = fetchFromGitHub { |
| 16 | # github.com/mholt/caddy-l4 |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 17 | owner = "mholt"; |
| 18 | repo = "caddy-l4"; |
| 19 | rev = "aa8cf68a3b5197c45a8b4ffd99b74465f0b5a6b1"; |
| 20 | hash = "sha256-3KcoOAB+YkOU8qKM75uQo58/dljRBmP25dionQ9K2dc="; |
| 21 | }; |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 22 | cloudflareSrc = fetchFromGitHub { |
| 23 | # github.com/caddy-dns/cloudflare |
| 24 | owner = "caddy-dns"; |
| 25 | repo = "cloudflare"; |
| 26 | rev = "a9d3ae2690a1d232bc9f8fc8b15bd4e0a6960eec"; |
| 27 | hash = "sha256-bqnk4XkhUI7YhCv24ha8mds5EaYphnYj8wy/mFOieqI="; |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 28 | }; |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 29 | |
| 30 | combinedSrc = stdenv.mkDerivation { |
| 31 | name = "caddy-src"; |
| 32 | |
| 33 | nativeBuildInputs = [ go ]; |
| 34 | |
| 35 | buildCommand = '' |
| 36 | export GOCACHE="$TMPDIR/go-cache" |
| 37 | export GOPATH="$TMPDIR/go" |
| 38 | |
| 39 | mkdir -p "$out/ourcaddy" |
| 40 | |
| 41 | cp -r ${caddySrc} "$out/caddy" |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 42 | cp -r ${l4Src} "$out/l4" |
| 43 | cp -r ${cloudflareSrc} "$out/cloudflare" |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 44 | |
| 45 | cd "$out/ourcaddy" |
| 46 | |
| 47 | go mod init caddy |
| 48 | echo "package main" >> main.go |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 49 | |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 50 | echo 'import caddycmd "github.com/caddyserver/caddy/v2/cmd"' >> main.go |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 51 | |
Skyler Grey | 0e71dcd | 2023-05-21 00:05:17 +0200 | [diff] [blame] | 52 | echo 'import _ "github.com/caddyserver/caddy/v2/modules/standard"' >> main.go |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 53 | echo 'import _ "github.com/mholt/caddy-l4"' >> main.go |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 54 | echo 'import _ "github.com/caddy-dns/cloudflare"' >> main.go |
| 55 | |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 56 | echo "func main(){ caddycmd.Main() }" >> main.go |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 57 | |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 58 | go mod edit -require=github.com/caddyserver/caddy/v2@v2.6.4 |
| 59 | go mod edit -replace github.com/caddyserver/caddy/v2=../caddy |
| 60 | go mod edit -require=github.com/mholt/caddy-l4@v0.0.0 |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 61 | go mod edit -replace github.com/mholt/caddy-l4=../l4 |
| 62 | go mod edit -require=github.com/caddy-dns/cloudflare@v0.0.0 |
| 63 | go mod edit -replace github.com/caddy-dns/cloudflare=../cloudflare |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 64 | ''; |
| 65 | }; |
Skyler Grey | fe1740c | 2023-10-21 01:24:18 +0000 | [diff] [blame^] | 66 | in buildGoModule { |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 67 | name = "caddy-with-plugins"; |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 68 | |
| 69 | src = combinedSrc; |
| 70 | |
Skyler Grey | 19f9fa2 | 2023-05-24 17:51:24 +0200 | [diff] [blame] | 71 | vendorHash = "sha256-34o91x7Y7DjIHom2Tk2ARBcJ3PzBVm+ALWK9ucj1g5A="; |
Skyler Grey | 70c83de | 2023-05-01 21:36:12 +0000 | [diff] [blame] | 72 | |
| 73 | overrideModAttrs = _: { |
| 74 | postPatch = "cd ourcaddy"; |
| 75 | |
| 76 | postConfigure = '' |
| 77 | go mod tidy |
| 78 | ''; |
| 79 | |
| 80 | postInstall = '' |
| 81 | mkdir -p "$out/.magic" |
| 82 | cp go.mod go.sum "$out/.magic" |
| 83 | ''; |
| 84 | }; |
| 85 | |
| 86 | postPatch = "cd ourcaddy"; |
| 87 | |
| 88 | postConfigure = '' |
| 89 | cp vendor/.magic/go.* . |
| 90 | ''; |
| 91 | } |