blob: 6856bf236f61c871038980cccf0f5d865a69d69d [file] [log] [blame]
Skyler Grey70c83de2023-05-01 21:36:12 +00001# https://github.com/NixOS/nixpkgs/issues/14671#issuecomment-1016376290
Skyler Grey0e71dcd2023-05-21 00:05:17 +02002{ lib, pkgs, fetchFromGitHub, buildGoModule, plugins ? [ ] }:
Skyler Grey70c83de2023-05-01 21:36:12 +00003
4with lib;
5with pkgs;
6
7let
8 pluginSrc = fetchFromGitHub {
9 owner = "mholt";
10 repo = "caddy-l4";
11 rev = "aa8cf68a3b5197c45a8b4ffd99b74465f0b5a6b1";
12 hash = "sha256-3KcoOAB+YkOU8qKM75uQo58/dljRBmP25dionQ9K2dc=";
13 };
Skyler Grey0e71dcd2023-05-21 00:05:17 +020014 caddySrc = fetchFromGitHub {
Skyler Grey70c83de2023-05-01 21:36:12 +000015 owner = "caddyserver";
16 repo = "caddy";
17 rev = "v2.6.4";
18 hash = "sha256-3a3+nFHmGONvL/TyQRqgJtrSDIn0zdGy9YwhZP17mU0=";
Skyler Grey0e71dcd2023-05-21 00:05:17 +020019 };
Skyler Grey70c83de2023-05-01 21:36:12 +000020
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 Grey0e71dcd2023-05-21 00:05:17 +020040 echo 'import _ "github.com/caddyserver/caddy/v2/modules/standard"' >> main.go
Skyler Grey70c83de2023-05-01 21:36:12 +000041 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 };
49in
50buildGoModule {
51 name = "meowdy";
52
53 src = combinedSrc;
54
Skyler Grey0e71dcd2023-05-21 00:05:17 +020055 vendorHash = "sha256-a49J7gKBYi9mQLlg+YFGaOetvbup5yRrWzX7kicvy+o=";
Skyler Grey70c83de2023-05-01 21:36:12 +000056
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}