infrastructure/machines/web01/linkal/module.nix

72 lines
1.9 KiB
Nix
Raw Normal View History

{ config, lib, pkgs, sources, ... }:
let
inherit (lib) mapAttrs' mkEnableOption mkIf mkOption nameValuePair types;
package = import sources.linkal { inherit pkgs; };
cfg = config.dgn-linkal;
jsonFormat = pkgs.formats.json { };
in {
options.dgn-linkal = {
enable = mkEnableOption "the linkal server.";
package = mkOption {
type = types.package;
default = package.overrideAttrs (_: { buildInputs = [ ]; });
};
domain = mkOption { type = types.str; };
calendarGroups = mkOption {
type = let inherit (types) attrsOf port submodule;
in attrsOf (submodule {
options = {
port = mkOption { type = port; };
calendars = mkOption { inherit (jsonFormat) type; };
};
});
default = { };
};
};
config = mkIf cfg.enable {
systemd.services = mapAttrs' (name:
{ port, calendars }:
nameValuePair "linkal-${name}" {
description = "Linkal - ${name}";
wantedBy = [ "multi-user.target" ];
serviceConfig = {
Type = "simple";
ExecStart = "${cfg.package}/bin/linkal --port ${
builtins.toString port
} --calendar-file ${
jsonFormat.generate "linkal-${name}.json" { inherit calendars; }
}";
};
}) cfg.calendarGroups;
services.nginx = {
enable = true;
virtualHosts.${cfg.domain} = {
enableACME = true;
forceSSL = true;
locations = mapAttrs' (name:
{ port, ... }:
nameValuePair "^~ /${name}" {
proxyPass = "http://127.0.0.1:${builtins.toString port}/";
# extraConfig = ''
# proxy_set_header X-Real-IP $remote_addr;
# proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
# proxy_set_header Host $host;
# proxy_redirect off;
# '';
}) cfg.calendarGroups;
};
};
};
}