-
-
Notifications
You must be signed in to change notification settings - Fork 18.1k
caddy: add suport for compiling Caddy with plugins #358586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,6 +6,10 @@ | |
| , testers | ||
| , installShellFiles | ||
| , stdenv | ||
| , go | ||
| , xcaddy | ||
| , cacert | ||
| , git | ||
| }: | ||
| let | ||
| version = "2.8.4"; | ||
|
|
@@ -32,7 +36,8 @@ buildGoModule { | |
| subPackages = [ "cmd/caddy" ]; | ||
|
|
||
| ldflags = [ | ||
| "-s" "-w" | ||
| "-s" | ||
| "-w" | ||
| "-X github.com/caddyserver/caddy/v2.CustomVersion=${version}" | ||
| ]; | ||
|
|
||
|
|
@@ -61,12 +66,83 @@ buildGoModule { | |
| --zsh <($out/bin/caddy completion zsh) | ||
| ''; | ||
|
|
||
| passthru.tests = { | ||
| inherit (nixosTests) caddy; | ||
| version = testers.testVersion { | ||
| command = "${caddy}/bin/caddy version"; | ||
| package = caddy; | ||
| passthru = { | ||
| tests = { | ||
| inherit (nixosTests) caddy; | ||
| version = testers.testVersion { | ||
| command = "${caddy}/bin/caddy version"; | ||
| package = caddy; | ||
| }; | ||
| }; | ||
| withPlugins = | ||
| { plugins | ||
|
||
| , hash ? lib.fakeHash | ||
| }: caddy.overrideAttrs (finalAttrs: prevAttrs: | ||
| let | ||
| pluginsSorted = builtins.sort builtins.lessThan plugins; | ||
| pluginsList = lib.concatMapStrings (plugin: "${plugin}-") pluginsSorted; | ||
| pluginsHash = builtins.hashString "md5" pluginsList; | ||
| pluginsWithoutVersion = builtins.filter (p: !lib.hasInfix "@" p) pluginsSorted; | ||
| in | ||
| assert lib.assertMsg (builtins.length pluginsWithoutVersion == 0) | ||
|
||
| "All plugins should have a version (eg ${builtins.elemAt pluginsWithoutVersion 0}@x.y.z)!"; | ||
| { | ||
| vendorHash = null; | ||
| subPackages = [ "." ]; | ||
|
|
||
| src = stdenv.mkDerivation { | ||
| pname = "caddy-src-with-plugins-${pluginsHash}"; | ||
|
||
| version = finalAttrs.version; | ||
|
|
||
| nativeBuildInputs = [ | ||
| go | ||
| xcaddy | ||
| cacert | ||
| git | ||
| ]; | ||
| dontUnpack = true; | ||
| buildPhase = | ||
| let | ||
| withArgs = lib.concatMapStrings (plugin: "--with ${plugin} ") pluginsSorted; | ||
| in | ||
| '' | ||
| export GOCACHE=$TMPDIR/go-cache | ||
| export GOPATH="$TMPDIR/go" | ||
| XCADDY_SKIP_BUILD=1 TMPDIR="$PWD" xcaddy build v${finalAttrs.version} ${withArgs} | ||
| (cd buildenv* && go mod vendor) | ||
| ''; | ||
| installPhase = '' | ||
| mv buildenv* $out | ||
| ''; | ||
|
|
||
| outputHashMode = "recursive"; | ||
| outputHash = hash; | ||
| outputHashAlgo = "sha256"; | ||
| }; | ||
|
|
||
|
|
||
| doInstallCheck = true; | ||
| installCheckPhase = '' | ||
| runHook preInstallCheck | ||
|
|
||
| ${lib.toShellVar "notfound" pluginsSorted} | ||
| while read kind module version; do | ||
| [[ "$kind" = "dep" ]] || continue | ||
| module="''${module}@''${version}" | ||
| for i in "''${!notfound[@]}"; do | ||
| if [[ ''${notfound[i]} = ''${module} ]]; then | ||
| unset 'notfound[i]' | ||
| fi | ||
| done | ||
| done < <($out/bin/caddy build-info) | ||
| if (( ''${#notfound[@]} )); then | ||
| >&2 echo "Plugins not found: ''${notfound[@]}" | ||
|
||
| exit 1 | ||
| fi | ||
|
|
||
| runHook postInstallCheck | ||
| ''; | ||
| }); | ||
| }; | ||
|
|
||
| meta = with lib; { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit, but I think this is very long function to be defined at the body of the derivation. I suggest moving this to
with-plugins.nixor something and importing the file here.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will not block PR for my nit, so if someone else wants to merge feel free.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done, moved to
plugins.nixand use ofcallPackage. I think this is the right way, but maybe I should inherit more stuff?