···2929{
3030 plugins,
3131 hash ? fakeHash,
3232+ doInstallCheck ? true,
3233}:
33343435let
···83848485 # xcaddy built output always uses pseudo-version number
8586 # we enforce user provided plugins are present and have matching tags here
8686- doInstallCheck = true;
8787+ inherit doInstallCheck;
8788 installCheckPhase = ''
8889 runHook preInstallCheck
89909191+ declare -A modules errors
9092 ${toShellVar "notfound" pluginsSorted}
91939292- while read kind module version; do
9393- [[ "$kind" = "dep" ]] || continue
9494- module="''${module}@''${version}"
9595- for i in "''${!notfound[@]}"; do
9696- if [[ ''${notfound[i]} = ''${module} ]]; then
9797- unset 'notfound[i]'
9898- fi
9999- done
9494+ # put build info that we care about into `modules` list
9595+ while read -r kind module version _; do
9696+ case "$kind" in
9797+ 'dep'|'=>')
9898+ modules[$module]=$version
9999+ ;;
100100+ *)
101101+ # we only care about 'dep' and '=>' directives for now
102102+ ;;
103103+ esac
100104 done < <($out/bin/caddy build-info)
101105102102- if (( ''${#notfound[@]} )); then
103103- for plugin in "''${notfound[@]}"; do
104104- base=''${plugin%@*}
105105- specified=''${plugin#*@}
106106- found=0
106106+ # compare build-time (Nix side) against runtime (Caddy side)
107107+ for spec in "''${notfound[@]}"; do
108108+ if [[ $spec == *=* ]]; then
109109+ # orig=repl_mod@repl_ver
110110+ orig=''${spec%%=*}
111111+ repl=''${spec#*=}
112112+ repl_mod=''${repl%@*}
113113+ repl_ver=''${repl#*@}
107114108108- while read kind module expected; do
109109- [[ "$kind" = "dep" && "$module" = "$base" ]] || continue
110110- echo "Plugin \"$base\" have incorrect tag:"
111111- echo " specified: \"$base@$specified\""
112112- echo " got: \"$base@$expected\""
113113- found=1
114114- done < <($out/bin/caddy build-info)
115115+ if [[ -z ''${modules[$orig]} ]]; then
116116+ errors[$spec]="plugin \"$spec\" with replacement not found in build info:\n reason: \"$orig\" missing"
117117+ elif [[ -z ''${modules[$repl_mod]} ]]; then
118118+ errors[$spec]="plugin \"$spec\" with replacement not found in build info:\n reason: \"$repl_mod\" missing"
119119+ elif [[ "''${modules[$repl_mod]}" != "$repl_ver" ]]; then
120120+ errors[$spec]="plugin \"$spec\" have incorrect tag:\n specified: \"$spec\"\n got: \"$orig=$repl_mod@''${modules[$repl_mod]}\""
121121+ fi
122122+ else
123123+ # mod@ver
124124+ mod=''${spec%@*}
125125+ ver=''${spec#*@}
115126116116- if (( found == 0 )); then
117117- echo "Plugin \"$base\" not found in build:"
118118- echo " specified: \"$base@$specified\""
119119- echo " plugin does not exist in the xcaddy build output, open an issue in nixpkgs or upstream"
127127+ if [[ -z ''${modules[$mod]} ]]; then
128128+ errors[$spec]="plugin \"$spec\" not found in build info"
129129+ elif [[ "''${modules[$mod]}" != "$ver" ]]; then
130130+ errors[$spec]="plugin \"$spec\" have incorrect tag:\n specified: \"$spec\"\n got: \"$mod@''${modules[$mod]}\""
120131 fi
132132+ fi
133133+ done
134134+135135+ # print errors if any
136136+ if [[ ''${#errors[@]} -gt 0 ]]; then
137137+ for spec in "''${!errors[@]}"; do
138138+ printf "Error: ''${errors[$spec]}\n" >&2
121139 done
140140+141141+ echo "Tips:"
142142+ echo "If:"
143143+ echo " - you are using module replacement (e.g. \`plugin1=plugin2@version\`)"
144144+ echo " - the provided Caddy plugin is under a repository's subdirectory, and \`go.{mod,sum}\` files are not in that subdirectory"
145145+ echo " - you have custom build logic or other advanced use cases"
146146+ echo "Please consider:"
147147+ echo " - set \`doInstallCheck = false\`"
148148+ echo " - write your own \`installCheckPhase\` and override the default script"
149149+ echo "If you are sure this error is caused by packaging, or by caddy/xcaddy, raise an issue with upstream or nixpkgs"
122150123151 exit 1
124152 fi