Created module for caddy with plugins
This commit is contained in:
parent
ecbf722032
commit
f4935560a4
3 changed files with 100 additions and 34 deletions
58
modules/networking/caddy.nix
Normal file
58
modules/networking/caddy.nix
Normal file
|
|
@ -0,0 +1,58 @@
|
||||||
|
{
|
||||||
|
config,
|
||||||
|
pkgs,
|
||||||
|
lib,
|
||||||
|
...
|
||||||
|
}:
|
||||||
|
|
||||||
|
with lib;
|
||||||
|
|
||||||
|
let
|
||||||
|
cfg = config.my.networking.caddy;
|
||||||
|
in
|
||||||
|
{
|
||||||
|
options.my.networking.caddy = {
|
||||||
|
enable = lib.mkEnableOption "Enable caddy as reverse proxy";
|
||||||
|
};
|
||||||
|
|
||||||
|
config = lib.mkIf cfg.enable {
|
||||||
|
|
||||||
|
age.secrets = {
|
||||||
|
cloudflare-tegola-apiKey = {
|
||||||
|
file = ../../secrets/cloudflare-tegola-apiKey.age;
|
||||||
|
owner = config.services.caddy.user;
|
||||||
|
group = config.services.caddy.group;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
services.caddy = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.caddy-custom;
|
||||||
|
# acmeCA = "https://acme-staging-v02.api.letsencrypt.org/directory"; # ONLY FOR DEVELOPMENT!
|
||||||
|
extraConfig = ''
|
||||||
|
(cloudflare) {
|
||||||
|
tls {
|
||||||
|
dns cloudflare {env.CLOUDFLARE_KEY}
|
||||||
|
resolvers 1.1.1.1 100.100.100.100
|
||||||
|
}
|
||||||
|
}
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.caddy.serviceConfig = {
|
||||||
|
EnvironmentFile = config.age.secrets.cloudflare-tegola-apiKey.path;
|
||||||
|
AmbientCapabilities = "CAP_NET_BIND_SERVICE";
|
||||||
|
};
|
||||||
|
|
||||||
|
networking.firewall.allowedTCPPorts = [
|
||||||
|
80
|
||||||
|
443
|
||||||
|
];
|
||||||
|
|
||||||
|
networking.firewall.allowedUDPPorts = [
|
||||||
|
80
|
||||||
|
443
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
{
|
{
|
||||||
imports = [
|
imports = [
|
||||||
./avahi.nix
|
./avahi.nix
|
||||||
|
./caddy.nix
|
||||||
./tailscale.nix
|
./tailscale.nix
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,46 +3,53 @@
|
||||||
with pkgs;
|
with pkgs;
|
||||||
|
|
||||||
caddy.override {
|
caddy.override {
|
||||||
buildGoModule = args: buildGoModule (args // {
|
buildGoModule =
|
||||||
src = stdenv.mkDerivation rec {
|
args:
|
||||||
pname = "caddy-using-xcaddy-${xcaddy.version}";
|
buildGoModule (
|
||||||
inherit (caddy) version;
|
args
|
||||||
|
// {
|
||||||
|
src = stdenv.mkDerivation rec {
|
||||||
|
pname = "caddy-using-xcaddy-${xcaddy.version}";
|
||||||
|
inherit (caddy) version;
|
||||||
|
|
||||||
dontUnpack = true;
|
dontUnpack = true;
|
||||||
dontFixup = true;
|
dontFixup = true;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
cacert
|
cacert
|
||||||
go
|
go
|
||||||
];
|
];
|
||||||
|
|
||||||
plugins = [
|
plugins = [ "github.com/caddy-dns/cloudflare@89f16b99c18ef49c8bb470a82f895bce01cbaece" ];
|
||||||
# https://github.com/caddy-dns/cloudflare
|
|
||||||
"github.com/caddy-dns/cloudflare@89f16b99c18ef49c8bb470a82f895bce01cbaece"
|
|
||||||
];
|
|
||||||
|
|
||||||
configurePhase = ''
|
configurePhase = ''
|
||||||
export GOCACHE=$TMPDIR/go-cache
|
export GOCACHE=$TMPDIR/go-cache
|
||||||
export GOPATH="$TMPDIR/go"
|
export GOPATH="$TMPDIR/go"
|
||||||
export XCADDY_SKIP_BUILD=1
|
export XCADDY_SKIP_BUILD=1
|
||||||
'';
|
'';
|
||||||
|
|
||||||
buildPhase = ''
|
buildPhase = ''
|
||||||
${xcaddy}/bin/xcaddy build "${caddy.src.rev}" ${lib.concatMapStringsSep " " (plugin: "--with ${plugin}") plugins}
|
${xcaddy}/bin/xcaddy build "${caddy.src.rev}" ${
|
||||||
cd buildenv*
|
lib.concatMapStringsSep " " (plugin: "--with ${plugin}") plugins
|
||||||
go mod vendor
|
}
|
||||||
'';
|
cd buildenv*
|
||||||
|
go mod vendor
|
||||||
|
'';
|
||||||
|
|
||||||
installPhase = ''
|
installPhase = ''
|
||||||
cp -r --reflink=auto . $out
|
cp -r --reflink=auto . $out
|
||||||
'';
|
'';
|
||||||
|
|
||||||
outputHash = "sha256-lyhEIOgGkR31bt9YV+W854TBZw419G8uuTtBSsFcgCA=";
|
outputHash = "sha256-lyhEIOgGkR31bt9YV+W854TBZw419G8uuTtBSsFcgCA=";
|
||||||
outputHashMode = "recursive";
|
outputHashMode = "recursive";
|
||||||
};
|
};
|
||||||
|
|
||||||
subPackages = [ "." ];
|
subPackages = [ "." ];
|
||||||
ldflags = [ "-s" "-w" ]; ## don't include version info twice
|
ldflags = [
|
||||||
vendorHash = null;
|
"-s"
|
||||||
});
|
"-w"
|
||||||
|
]; # # don't include version info twice
|
||||||
|
vendorHash = null;
|
||||||
|
}
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue