feat: add customizable caddy package (with plugin support)

This commit is contained in:
oddlama 2023-06-05 01:14:46 +02:00
parent c5a863ce51
commit 6f84594c87
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
9 changed files with 90 additions and 26 deletions

49
pkgs/caddy.nix Normal file
View file

@ -0,0 +1,49 @@
final: prev: let
inherit
(final.lib)
escapeShellArg
concatMapStrings
flatten
flip
;
make-custom-caddy = {
plugins,
vendorHash,
}: let
caddyPatchMain =
flip concatMapStrings plugins
({name, ...}: "sed -i '/plug in Caddy modules here/a \\\\t_ \"${name}\"' cmd/caddy/main.go\n");
caddyPatchGoGet =
flip concatMapStrings plugins
({
name,
version,
}: "go get ${escapeShellArg name}@${escapeShellArg version}\n");
in
prev.caddy.override {
buildGoModule = args:
prev.buildGoModule (args
// {
inherit vendorHash;
passthru.plugins = plugins;
overrideModAttrs = _: {
preBuild = caddyPatchGoGet;
postInstall = "cp go.mod go.sum $out/";
};
postPatch = caddyPatchMain;
postConfigure = "cp vendor/go.mod vendor/go.sum .";
});
};
in {
# Example usage:
# caddy.withPackages {
# plugins = [
# { name = "github.com/greenpau/caddy-security"; version = "v1.1.18"; }
# ];
# vendorHash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
# }
caddy = prev.caddy.overrideAttrs (_: {passthru.withPackages = make-custom-caddy;});
}

3
pkgs/default.nix Normal file
View file

@ -0,0 +1,3 @@
[
(import ./caddy.nix)
]