blob: 26e0a58092c09671a25ad14f86fb0b346317b559 [file] [log] [blame]
TheCodedProfbdc23452023-06-14 13:39:10 -04001{ base, config, pkgs, lib, ... }: lib.recursiveUpdate
2{
Skyler Grey09c5cda2023-10-09 07:10:10 +00003 services.nginx.enable = false; # PrivateBin, nextcloud etc. attempts to enable nginx but we already use caddy
Skyler Grey4f3e6062023-03-04 01:29:29 +00004 services.caddy.enable = true;
Skyler Grey40ab9af2023-05-20 18:03:53 +02005 services.caddy.configFile = lib.pipe ./caddy/caddyfile.nix [
6 import
TheCodedProf85256bc2023-06-13 13:02:53 -04007 (f: f { inherit pkgs lib config; })
Skyler Grey40ab9af2023-05-20 18:03:53 +02008 builtins.toJSON
9 (pkgs.writeText "caddy.json")
10 ];
Skyler Grey0e71dcd2023-05-21 00:05:17 +020011 services.caddy.package = pkgs.callPackage ../packages/caddy.nix { };
Skyler Grey8b0e52f2023-05-01 21:31:07 +000012 services.caddy.user = "root";
13 systemd.services.caddy.serviceConfig.ProtectHome = lib.mkForce false;
Skyler Grey19f9fa22023-05-24 17:51:24 +020014
15 sops.secrets.cloudflare_token = {
16 mode = "0600";
17 owner = config.users.users.root.name;
18 group = config.users.users.nobody.group;
19 sopsFile = ../secrets/caddy.json;
20 format = "json";
21 };
TheCodedProfbdc23452023-06-14 13:39:10 -040022}
23 (
Skyler Grey19f9fa22023-05-24 17:51:24 +020024 let
TheCodedProfbdc23452023-06-14 13:39:10 -040025 isDerived = base != null;
Skyler Grey19f9fa22023-05-24 17:51:24 +020026 in
TheCodedProfbdc23452023-06-14 13:39:10 -040027 if isDerived
28 then
29 let
30 caddy_json = base.config.services.caddy.configFile;
31 in
32 {
33 scalpel.trafos."caddy.json" = {
34 source = toString caddy_json;
35 matchers."cloudflare_token".secret =
36 config.sops.secrets.cloudflare_token.path;
37 owner = config.users.users.root.name;
38 group = config.users.users.nobody.group;
39 mode = "0400";
40 };
Skyler Grey19f9fa22023-05-24 17:51:24 +020041
TheCodedProfbdc23452023-06-14 13:39:10 -040042 services.caddy.configFile = lib.mkForce config.scalpel.trafos."caddy.json".destination;
Skyler Greyb3516c22023-05-24 19:17:11 +020043
TheCodedProfbdc23452023-06-14 13:39:10 -040044 systemd.services.caddy.reloadTriggers = [ caddy_json ];
45 }
46 else { }
47 )