13 inherit (builtins) hashString;
28 # pkgs.caddy.withPlugins args
35 pluginsSorted = sort lessThan plugins;
36 pluginsList = concatMapStrings (plugin: "${plugin}-") pluginsSorted;
37 pluginsHash = hashString "md5" pluginsList;
38 pluginsWithoutVersion = filter (p: !hasInfix "@" p) pluginsSorted;
41 # eval barrier: user provided plugins must have tags
42 # the go module must either be tagged in upstream repo
43 # or user must provide commit sha or a pseudo-version number
44 # https://go.dev/doc/modules/version-numbers#pseudo-version-number
46 length pluginsWithoutVersion == 0
47 ) "Plugins must have tags present (e.g. ${elemAt pluginsWithoutVersion 0}@x.y.z)!";
50 finalAttrs: prevAttrs: {
52 subPackages = [ "." ];
54 src = stdenv.mkDerivation {
55 pname = "caddy-src-with-plugins-${pluginsHash}";
56 version = finalAttrs.version;
67 withArgs = concatMapStrings (plugin: "--with ${plugin} ") pluginsSorted;
70 export GOCACHE=$TMPDIR/go-cache
71 export GOPATH="$TMPDIR/go"
72 XCADDY_SKIP_BUILD=1 TMPDIR="$PWD" xcaddy build v${finalAttrs.version} ${withArgs}
73 (cd buildenv* && go mod vendor)
79 outputHashMode = "recursive";
81 outputHashAlgo = "sha256";
84 # xcaddy built output always uses pseudo-version number
85 # we enforce user provided plugins are present and have matching tags here
86 doInstallCheck = true;
87 installCheckPhase = ''
88 runHook preInstallCheck
90 ${toShellVar "notfound" pluginsSorted}
92 while read kind module version; do
93 [[ "$kind" = "dep" ]] || continue
94 module="''${module}@''${version}"
95 for i in "''${!notfound[@]}"; do
96 if [[ ''${notfound[i]} = ''${module} ]]; then
100 done < <($out/bin/caddy build-info)
102 if (( ''${#notfound[@]} )); then
103 for plugin in "''${notfound[@]}"; do
105 specified=''${plugin#*@}
108 while read kind module expected; do
109 [[ "$kind" = "dep" && "$module" = "$base" ]] || continue
110 echo "Plugin \"$base\" have incorrect tag:"
111 echo " specified: \"$base@$specified\""
112 echo " got: \"$base@$expected\""
114 done < <($out/bin/caddy build-info)
116 if (( found == 0 )); then
117 echo "Plugin \"$base\" not found in build:"
118 echo " specified: \"$base@$specified\""
119 echo " plugin does not exist in the xcaddy build output, open an issue in nixpkgs or upstream"
126 runHook postInstallCheck