Use custom caddy build

This commit is contained in:
TEC 2024-01-10 00:55:19 +08:00
parent 2eb2bf27dd
commit e7cc263cc3
Signed by: tec
SSH Key Fingerprint: SHA256:eobz41Mnm0/iYWBvWThftS0ElEs1ftBr6jamutnXc/A
2 changed files with 43 additions and 1 deletions

View File

@ -1,4 +1,4 @@
{ config, lib, ... }:
{ config, lib, pkgs, ... }:
with lib;
@ -11,6 +11,11 @@ with lib;
services.caddy = mkMerge [
{
enable = true;
package = pkgs.callPackage ../packages/caddy.nix {
plugins = [
"github.com/tecosaur/caddy-fs-git"
];
};
virtualHosts."tecosaur.net".extraConfig = ''
respond "__ __ _
\ \ / /__| | ___ ___ _ __ ___ ___

37
packages/caddy.nix Normal file
View File

@ -0,0 +1,37 @@
{ config, pkgs, plugins, ... }:
with pkgs;
stdenv.mkDerivation rec {
# Disable the Nix build sandbox for this specific build.
# This means the build can freely talk to the Internet.
# Requires the sandbox to be set to false/"relaxed".
__noChroot = true;
pname = "caddy";
# https://github.com/NixOS/nixpkgs/issues/113520
version = "latest";
dontUnpack = true;
nativeBuildInputs = [ git go xcaddy ];
configurePhase = ''
export GOCACHE=$TMPDIR/go-cache
export GOPATH="$TMPDIR/go"
'';
buildPhase = let
pluginArgs = lib.concatMapStringsSep " " (plugin: "--with ${plugin}") plugins;
in ''
runHook preBuild
${xcaddy}/bin/xcaddy build latest ${pluginArgs}
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/bin
mv caddy $out/bin
runHook postInstall
'';
}