fix: compiling cloudflare caddy module

actually compile locally since xcaddy is impure
This commit is contained in:
Noah Masur
2023-06-01 03:44:43 +00:00
parent df5fba19f8
commit d337ffff51
2 changed files with 68 additions and 39 deletions

View File

@ -34,41 +34,6 @@ let
];
# Build with Cloudflare plugin for DNS validation
# Otherwise, requires HTTPS to be disabled for issuance
caddy = pkgs.stdenv.mkDerivation rec {
pname = "caddy";
version = "latest";
dontUnpack = true;
nativeBuildInputs = with pkgs; [ git go xcaddy ];
plugins = [
"github.com/caddy-dns/cloudflare@a9d3ae2690a1d232bc9f8fc8b15bd4e0a6960eec"
];
configurePhase = ''
export GOCACHE=$TMPDIR/go-cache
export GOPATH="$TMPDIR/go"
'';
buildPhase = let
pluginArgs =
lib.concatMapStringsSep " " (plugin: "--with ${plugin}") plugins;
in ''
runHook preBuild
${pkgs.xcaddy}/bin/xcaddy build "v${version}" ${pluginArgs}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv caddy $out/bin
runHook postInstall
'';
};
in {
options.cloudflare.enable = lib.mkEnableOption "Use Cloudflare.";
@ -85,20 +50,29 @@ in {
}];
# Tell Caddy to use Cloudflare DNS for ACME challenge validation
services.caddy.package = caddy;
services.caddy.package =
(pkgs.callPackage ../../../overlays/custom-caddy.nix {
plugins = [ "github.com/caddy-dns/cloudflare" ];
# vendorSha256 = "sha256-K9HPZnr+hMcK5aEd1H4gEg6PXAaNrNWFvaHYm5m62JY=";
});
caddy.tlsPolicies = [{
issuers = [{
module = "acme";
challenges = {
dns.provider = {
name = "cloudflare";
api_token = "{env.CF_API_TOKEN}";
dns = {
provider = {
name = "cloudflare";
api_token = "{env.CF_API_TOKEN}";
};
resolvers = [ "1.1.1.1" ];
};
};
}];
}];
systemd.services.caddy.serviceConfig.EnvironmentFile =
config.secrets.cloudflareApi.dest;
systemd.services.caddy.serviceConfig.AmbientCapabilities =
"CAP_NET_BIND_SERVICE";
# API key must have access to modify Cloudflare DNS records
secrets.cloudflareApi = {