blob: eddcf80df913b6ad086eeb35475576af0fec17b9 [file] [log] [blame]
TheCodedProfbdc23452023-06-14 13:39:10 -04001{ base, config, pkgs, lib, ... }: lib.recursiveUpdate
2{
Skyler Grey4f3e6062023-03-04 01:29:29 +00003 services.caddy.enable = true;
Skyler Grey40ab9af2023-05-20 18:03:53 +02004 services.caddy.configFile = lib.pipe ./caddy/caddyfile.nix [
5 import
TheCodedProf85256bc2023-06-13 13:02:53 -04006 (f: f { inherit pkgs lib config; })
Skyler Grey40ab9af2023-05-20 18:03:53 +02007 builtins.toJSON
8 (pkgs.writeText "caddy.json")
9 ];
Skyler Grey0e71dcd2023-05-21 00:05:17 +020010 services.caddy.package = pkgs.callPackage ../packages/caddy.nix { };
Skyler Grey8b0e52f2023-05-01 21:31:07 +000011 services.caddy.user = "root";
12 systemd.services.caddy.serviceConfig.ProtectHome = lib.mkForce false;
Skyler Grey19f9fa22023-05-24 17:51:24 +020013
14 sops.secrets.cloudflare_token = {
15 mode = "0600";
16 owner = config.users.users.root.name;
17 group = config.users.users.nobody.group;
18 sopsFile = ../secrets/caddy.json;
19 format = "json";
20 };
TheCodedProfbdc23452023-06-14 13:39:10 -040021}
22 (
Skyler Grey19f9fa22023-05-24 17:51:24 +020023 let
TheCodedProfbdc23452023-06-14 13:39:10 -040024 isDerived = base != null;
Skyler Grey19f9fa22023-05-24 17:51:24 +020025 in
TheCodedProfbdc23452023-06-14 13:39:10 -040026 if isDerived
27 then
28 let
29 caddy_json = base.config.services.caddy.configFile;
30 in
31 {
32 scalpel.trafos."caddy.json" = {
33 source = toString caddy_json;
34 matchers."cloudflare_token".secret =
35 config.sops.secrets.cloudflare_token.path;
36 owner = config.users.users.root.name;
37 group = config.users.users.nobody.group;
38 mode = "0400";
39 };
Skyler Grey19f9fa22023-05-24 17:51:24 +020040
TheCodedProfbdc23452023-06-14 13:39:10 -040041 services.caddy.configFile = lib.mkForce config.scalpel.trafos."caddy.json".destination;
Skyler Greyb3516c22023-05-24 19:17:11 +020042
TheCodedProfbdc23452023-06-14 13:39:10 -040043 systemd.services.caddy.reloadTriggers = [ caddy_json ];
44 }
45 else { }
46 )