···29{
30 plugins,
31 hash ? fakeHash,
032}:
3334let
···8384 # 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
89090 ${toShellVar "notfound" pluginsSorted}
9192- 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
97- unset 'notfound[i]'
98- fi
99- done
00100 done < <($out/bin/caddy build-info)
101102- if (( ''${#notfound[@]} )); then
103- for plugin in "''${notfound[@]}"; do
104- base=''${plugin%@*}
105- specified=''${plugin#*@}
106- found=0
000107108- 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\""
113- found=1
114- done < <($out/bin/caddy build-info)
0000115116- 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"
120 fi
0000000121 done
0000000000122123 exit 1
124 fi
···29{
30 plugins,
31 hash ? fakeHash,
32+ doInstallCheck ? true,
33}:
3435let
···8485 # xcaddy built output always uses pseudo-version number
86 # we enforce user provided plugins are present and have matching tags here
87+ inherit doInstallCheck;
88 installCheckPhase = ''
89 runHook preInstallCheck
9091+ declare -A modules errors
92 ${toShellVar "notfound" pluginsSorted}
9394+ # put build info that we care about into `modules` list
95+ while read -r kind module version _; do
96+ case "$kind" in
97+ 'dep'|'=>')
98+ modules[$module]=$version
99+ ;;
100+ *)
101+ # we only care about 'dep' and '=>' directives for now
102+ ;;
103+ esac
104 done < <($out/bin/caddy build-info)
105106+ # compare build-time (Nix side) against runtime (Caddy side)
107+ for spec in "''${notfound[@]}"; do
108+ if [[ $spec == *=* ]]; then
109+ # orig=repl_mod@repl_ver
110+ orig=''${spec%%=*}
111+ repl=''${spec#*=}
112+ repl_mod=''${repl%@*}
113+ repl_ver=''${repl#*@}
114115+ if [[ -z ''${modules[$orig]} ]]; then
116+ errors[$spec]="plugin \"$spec\" with replacement not found in build info:\n reason: \"$orig\" missing"
117+ elif [[ -z ''${modules[$repl_mod]} ]]; then
118+ errors[$spec]="plugin \"$spec\" with replacement not found in build info:\n reason: \"$repl_mod\" missing"
119+ elif [[ "''${modules[$repl_mod]}" != "$repl_ver" ]]; then
120+ errors[$spec]="plugin \"$spec\" have incorrect tag:\n specified: \"$spec\"\n got: \"$orig=$repl_mod@''${modules[$repl_mod]}\""
121+ fi
122+ else
123+ # mod@ver
124+ mod=''${spec%@*}
125+ ver=''${spec#*@}
126127+ if [[ -z ''${modules[$mod]} ]]; then
128+ errors[$spec]="plugin \"$spec\" not found in build info"
129+ elif [[ "''${modules[$mod]}" != "$ver" ]]; then
130+ errors[$spec]="plugin \"$spec\" have incorrect tag:\n specified: \"$spec\"\n got: \"$mod@''${modules[$mod]}\""
131 fi
132+ fi
133+ done
134+135+ # print errors if any
136+ if [[ ''${#errors[@]} -gt 0 ]]; then
137+ for spec in "''${!errors[@]}"; do
138+ printf "Error: ''${errors[$spec]}\n" >&2
139 done
140+141+ echo "Tips:"
142+ echo "If:"
143+ echo " - you are using module replacement (e.g. \`plugin1=plugin2@version\`)"
144+ echo " - the provided Caddy plugin is under a repository's subdirectory, and \`go.{mod,sum}\` files are not in that subdirectory"
145+ echo " - you have custom build logic or other advanced use cases"
146+ echo "Please consider:"
147+ echo " - set \`doInstallCheck = false\`"
148+ echo " - write your own \`installCheckPhase\` and override the default script"
149+ echo "If you are sure this error is caused by packaging, or by caddy/xcaddy, raise an issue with upstream or nixpkgs"
150151 exit 1
152 fi