-
Notifications
You must be signed in to change notification settings - Fork 1
/
pkg.nix
154 lines (135 loc) · 3.67 KB
/
pkg.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
{
lib,
buildGoModule,
fetchFromGitHub,
gnused,
installShellFiles,
nixosTests,
caddy,
testers,
stdenv,
}: let
attrsToModule = map (plugin: plugin.repo);
attrsToVersionedModule = map ({
repo,
version,
...
}:
lib.escapeShellArg "${repo}@${version}");
pname = "caddy";
version = "2.8.4";
dist = fetchFromGitHub {
owner = "caddyserver";
repo = "dist";
rev = "v${version}";
hash = "sha256-O4s7PhSUTXoNEIi+zYASx8AgClMC5rs7se863G6w+l0=";
};
src = fetchFromGitHub {
owner = "caddyserver";
repo = "caddy";
rev = "v${version}";
hash = "sha256-CBfyqtWp3gYsYwaIxbfXO3AYaBiM7LutLC7uZgYXfkQ=";
};
subPackages = ["cmd/caddy"];
ldflags = [
"-s"
"-w"
"-X github.com/caddyserver/caddy/v2.CustomVersion=${version}"
];
# matches upstream since v2.8.0
tags = ["nobadger"];
nativeBuildInputs = [
gnused
installShellFiles
];
postInstall =
''
install -Dm644 ${dist}/init/caddy.service ${dist}/init/caddy-api.service -t $out/lib/systemd/system
substituteInPlace $out/lib/systemd/system/caddy.service \
--replace-fail "/usr/bin/caddy" "$out/bin/caddy"
substituteInPlace $out/lib/systemd/system/caddy-api.service \
--replace-fail "/usr/bin/caddy" "$out/bin/caddy"
''
+ lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
# Generating man pages and completions fail on cross-compilation
# https://github.com/NixOS/nixpkgs/issues/308283
$out/bin/caddy manpage --directory manpages
installManPage manpages/*
installShellCompletion --cmd caddy \
--bash <($out/bin/caddy completion bash) \
--fish <($out/bin/caddy completion fish) \
--zsh <($out/bin/caddy completion zsh)
'';
meta = with lib; {
homepage = "https://caddyserver.com";
description = "Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS";
license = licenses.asl20;
mainProgram = "caddy";
maintainers = with maintainers; [
Br1ght0ne
emilylange
techknowlogick
];
};
in
buildGoModule {
inherit
pname
version
src
subPackages
ldflags
tags
nativeBuildInputs
postInstall
meta
;
vendorHash = "sha256-1Api8bBZJ1/oYk4ZGIiwWCSraLzK9L+hsKXkFtk6iVM=";
passthru = {
withPlugins = {
caddyModules,
vendorHash ? lib.fakeHash,
}:
buildGoModule {
pname = "${caddy.pname}-with-plugins";
inherit
version
src
subPackages
ldflags
tags
nativeBuildInputs
postInstall
meta
;
modBuildPhase = ''
for module in ${toString (attrsToModule caddyModules)}; do
sed -i "/standard/a _ \"$module\"" ./cmd/caddy/main.go
done
for plugin in ${toString (attrsToVersionedModule caddyModules)}; do
go get $plugin
done
go mod vendor
'';
modInstallPhase = ''
mv -t vendor go.mod go.sum
cp -r vendor "$out"
'';
preBuild = ''
chmod -R u+w vendor
[ -f vendor/go.mod ] && mv -t . vendor/go.{mod,sum}
for module in ${toString (attrsToModule caddyModules)}; do
sed -i "/standard/a _ \"$module\"" ./cmd/caddy/main.go
done
'';
inherit vendorHash;
};
tests = {
inherit (nixosTests) caddy;
version = testers.testVersion {
command = "${caddy}/bin/caddy version";
package = caddy;
};
};
};
}