-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcaddy.nix
85 lines (77 loc) · 2.14 KB
/
caddy.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
{ self, ... }:
{
perSystem =
{ pkgs, lib, ... }:
{
packages.caddy-with-cloudflare = self.lib.caddyWithPackages {
inherit (pkgs) caddy buildGoModule;
plugins = [ "github.com/caddy-dns/cloudflare@44030f9306f4815aceed3b042c7f3d2c2b110c97" ];
vendorHash = "sha256-ov7pOA22jnIDB4TqWo3UBz/ol3IeD0wiG+D5rGP8sEE=";
};
};
flake = {
lib.caddyWithPackages =
{
caddy,
buildGoModule,
plugins,
vendorHash,
}:
let
pluginImports = builtins.concatStringsSep "\n" (
map (
pluginWithHash:
let
plugin = builtins.elemAt (builtins.split "@" pluginWithHash) 0;
in
"_ \"${plugin}\""
) plugins
);
pluginGoGetCmds = builtins.concatStringsSep "\n" (map (plugin: "go get ${plugin}") plugins);
main = ''
package main
import (
caddycmd "github.com/caddyserver/caddy/v2/cmd"
_ "github.com/caddyserver/caddy/v2/modules/standard"
_ "github.com/caddyserver/caddy/v2"
${pluginImports}
)
func main() {
caddycmd.Main()
}
'';
in
caddy.override {
buildGoModule =
args:
buildGoModule (
(builtins.removeAttrs args [
"vendorHash"
"pname"
])
// {
inherit vendorHash;
pname = "caddy-with-plugins";
overrideModAttrs = _: {
preBuild = "echo '${main}' > cmd/caddy/main.go";
postConfigure = ''
${pluginGoGetCmds}
go mod tidy
'';
postInstall = ''
mkdir -p "$out/.magic"
cp go.sum go.mod "$out/.magic"
'';
};
postPatch = ''
echo '${main}' > cmd/caddy/main.go
cat cmd/caddy/main.go
'';
postConfigure = ''
cp vendor/.magic/go.* .
'';
}
);
};
};
}