mirror of
https://github.com/oddlama/nix-config.git
synced 2025-10-10 23:00:39 +02:00
feat: add customizable caddy package (with plugin support)
This commit is contained in:
parent
c5a863ce51
commit
6f84594c87
9 changed files with 90 additions and 26 deletions
49
pkgs/caddy.nix
Normal file
49
pkgs/caddy.nix
Normal 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
3
pkgs/default.nix
Normal file
|
@ -0,0 +1,3 @@
|
|||
[
|
||||
(import ./caddy.nix)
|
||||
]
|
Loading…
Add table
Add a link
Reference in a new issue