nix

configuration files that power my machines
Log | Files | Refs | README | LICENSE

static.nix (1398B)


      1 {
      2   config,
      3   lib,
      4   ...
      5 }: let
      6   cfg = config.services.haravara.static;
      7 in {
      8   options.services.haravara.static = {
      9     enable = lib.mkEnableOption "Static site assets deployment";
     10     domains = lib.mkOption {
     11       type = lib.types.attrsOf (lib.types.submodule {
     12         options = {
     13           bucket = lib.mkOption {
     14             type = lib.types.str;
     15             default = "";
     16             description = "Garage bucket name; defaults to the domain when empty";
     17           };
     18           endpoint = lib.mkOption {
     19             type = lib.types.str;
     20             description = "Garage web endpoint (host:port); bucket is selected via the Host header";
     21           };
     22           extraConfig = lib.mkOption {
     23             type = lib.types.lines;
     24             default = "";
     25             description = "Extra Caddy config appended to the virtual host";
     26           };
     27         };
     28       });
     29     };
     30   };
     31 
     32   config = lib.mkIf cfg.enable {
     33     services.caddy.virtualHosts =
     34       lib.mapAttrs' (
     35         domain: opt: let
     36           bucket =
     37             if opt.bucket != ""
     38             then opt.bucket
     39             else domain;
     40         in
     41           lib.nameValuePair domain {
     42             extraConfig =
     43               ''
     44                 reverse_proxy ${opt.endpoint} {
     45                   header_up Host ${bucket}
     46                 }
     47               ''
     48               + opt.extraConfig;
     49           }
     50       )
     51       cfg.domains;
     52   };
     53 }