nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 buildGo125Module,
4 callPackage,
5 fetchFromGitHub,
6 nixosTests,
7 caddy,
8 installShellFiles,
9 stdenv,
10 writableTmpDirAsHomeHook,
11 versionCheckHook,
12}:
13let
14 version = "2.10.2";
15 dist = fetchFromGitHub {
16 owner = "caddyserver";
17 repo = "dist";
18 tag = "v${version}";
19 hash = "sha256-D1qI7TDJpSvtgpo1FsPZk6mpqRvRharFZ8soI7Mn3RE=";
20 };
21in
22buildGo125Module (finalAttrs: {
23 pname = "caddy";
24 inherit version;
25
26 src = fetchFromGitHub {
27 owner = "caddyserver";
28 repo = "caddy";
29 tag = "v${finalAttrs.version}";
30 hash = "sha256-KvikafRYPFZ0xCXqDdji1rxlkThEDEOHycK8GP5e8vk=";
31 };
32
33 vendorHash = "sha256-wjcmWKVmLBAybILUi8tKEDnFbhtybf042ODH7jEq6r8=";
34
35 ldflags = [
36 "-s"
37 "-w"
38 "-X github.com/caddyserver/caddy/v2.CustomVersion=${finalAttrs.version}"
39 ];
40
41 # matches upstream since v2.8.0
42 tags = [
43 "nobadger"
44 "nomysql"
45 "nopgx"
46 ];
47
48 nativeBuildInputs = [ installShellFiles ];
49
50 nativeCheckInputs = [ writableTmpDirAsHomeHook ];
51
52 __darwinAllowLocalNetworking = true;
53
54 postInstall = ''
55 install -Dm644 ${dist}/init/caddy.service ${dist}/init/caddy-api.service -t $out/lib/systemd/system
56
57 substituteInPlace $out/lib/systemd/system/caddy.service \
58 --replace-fail "/usr/bin/caddy" "$out/bin/caddy"
59 substituteInPlace $out/lib/systemd/system/caddy-api.service \
60 --replace-fail "/usr/bin/caddy" "$out/bin/caddy"
61 ''
62 + lib.optionalString (stdenv.buildPlatform.canExecute stdenv.hostPlatform) ''
63 # Generating man pages and completions fail on cross-compilation
64 # https://github.com/NixOS/nixpkgs/issues/308283
65
66 $out/bin/caddy manpage --directory manpages
67 installManPage manpages/*
68
69 installShellCompletion --cmd caddy \
70 --bash <($out/bin/caddy completion bash) \
71 --fish <($out/bin/caddy completion fish) \
72 --zsh <($out/bin/caddy completion zsh)
73 '';
74
75 passthru = {
76 tests = {
77 inherit (nixosTests) caddy;
78 acme-integration = nixosTests.acme.caddy;
79 };
80 withPlugins = callPackage ./plugins.nix { inherit caddy; };
81 };
82
83 nativeInstallCheckInputs = [
84 writableTmpDirAsHomeHook
85 versionCheckHook
86 ];
87 versionCheckKeepEnvironment = [ "HOME" ];
88 doInstallCheck = true;
89
90 meta = {
91 homepage = "https://caddyserver.com";
92 description = "Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS";
93 changelog = "https://github.com/caddyserver/caddy/releases/tag/v${finalAttrs.version}";
94 license = lib.licenses.asl20;
95 mainProgram = "caddy";
96 maintainers = with lib.maintainers; [
97 stepbrobd
98 techknowlogick
99 ryan4yin
100 ];
101 };
102})