2024-02-02 10:51:31 +01:00
|
|
|
{
|
|
|
|
config,
|
|
|
|
lib,
|
|
|
|
pkgs,
|
|
|
|
sources,
|
|
|
|
...
|
|
|
|
}:
|
2023-09-26 18:12:56 +02:00
|
|
|
|
|
|
|
let
|
2024-02-02 10:51:31 +01:00
|
|
|
inherit (lib)
|
|
|
|
mapAttrs'
|
|
|
|
mkEnableOption
|
|
|
|
mkIf
|
|
|
|
mkOption
|
|
|
|
nameValuePair
|
|
|
|
types
|
|
|
|
;
|
2023-09-26 18:12:56 +02:00
|
|
|
|
|
|
|
package = import sources.linkal { inherit pkgs; };
|
|
|
|
|
|
|
|
cfg = config.dgn-linkal;
|
|
|
|
|
|
|
|
jsonFormat = pkgs.formats.json { };
|
2024-02-02 10:51:31 +01:00
|
|
|
in
|
|
|
|
{
|
2023-09-26 18:12:56 +02:00
|
|
|
options.dgn-linkal = {
|
|
|
|
enable = mkEnableOption "the linkal server.";
|
|
|
|
|
|
|
|
package = mkOption {
|
|
|
|
type = types.package;
|
|
|
|
default = package.overrideAttrs (_: { buildInputs = [ ]; });
|
|
|
|
};
|
|
|
|
|
|
|
|
domain = mkOption { type = types.str; };
|
|
|
|
|
|
|
|
calendarGroups = mkOption {
|
2024-02-02 10:51:31 +01:00
|
|
|
type =
|
|
|
|
let
|
|
|
|
inherit (types) attrsOf port submodule;
|
|
|
|
in
|
|
|
|
attrsOf (
|
|
|
|
submodule {
|
|
|
|
options = {
|
|
|
|
port = mkOption { type = port; };
|
|
|
|
calendars = mkOption { inherit (jsonFormat) type; };
|
|
|
|
};
|
|
|
|
}
|
|
|
|
);
|
2023-09-26 18:12:56 +02:00
|
|
|
default = { };
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf cfg.enable {
|
2024-02-02 10:51:31 +01:00
|
|
|
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;
|
2023-09-26 18:12:56 +02:00
|
|
|
|
2023-09-29 13:27:27 +02:00
|
|
|
# Configure bind for DNS certificate validation on *.cal.dgnum.eu.
|
2023-10-02 21:18:40 +02:00
|
|
|
# services.bind = {
|
|
|
|
# enable = true;
|
|
|
|
# ipv4Only = true;
|
|
|
|
# extraConfig = ''
|
|
|
|
# include "${config.age.secrets."named-bind_dnskeys_conf".path}";
|
|
|
|
# '';
|
|
|
|
#
|
|
|
|
# zones = [rec {
|
|
|
|
# name = "cal.dgnum.eu";
|
|
|
|
# file = "/var/db/bind/${name}";
|
|
|
|
# master = true;
|
|
|
|
# extraConfig = ''
|
|
|
|
# allow-update { key "rfc2136key.cal.dgnum.eu"; };
|
|
|
|
# '';
|
|
|
|
# }];
|
|
|
|
# };
|
|
|
|
#
|
|
|
|
# networking.firewall = {
|
|
|
|
# allowedTCPPorts = [ 53 ];
|
|
|
|
# allowedUDPPorts = [ 53 ];
|
|
|
|
# };
|
|
|
|
#
|
2024-01-09 14:48:33 +01:00
|
|
|
# age-secrets.options = [{ named-bind_dnskeys_conf.owner = "named"; }];
|
2023-10-02 21:18:40 +02:00
|
|
|
#
|
|
|
|
# # Configure ACME for DNS certificate validation
|
|
|
|
# security.acme = {
|
|
|
|
# acceptTerms = true;
|
|
|
|
# defaults = {
|
|
|
|
# dnsProvider = "rfc2136";
|
|
|
|
# credentialsFile = config.age.secrets."acme-certs_secret".path;
|
|
|
|
# dnsPropagationCheck = false;
|
|
|
|
# };
|
|
|
|
# };
|
2023-09-29 13:27:27 +02:00
|
|
|
|
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
virtualHosts =
|
|
|
|
mapAttrs'
|
|
|
|
(
|
|
|
|
name:
|
|
|
|
{ port, ... }:
|
|
|
|
nameValuePair "${name}.${cfg.domain}" {
|
|
|
|
enableACME = true;
|
|
|
|
# acmeRoot = null; # Use DNS-01 validation
|
|
|
|
forceSSL = true;
|
2023-09-29 13:27:27 +02:00
|
|
|
|
2024-02-02 10:51:31 +01:00
|
|
|
locations."/".proxyPass = "http://127.0.0.1:${builtins.toString port}/";
|
|
|
|
}
|
|
|
|
)
|
|
|
|
cfg.calendarGroups;
|
2023-09-29 13:27:27 +02:00
|
|
|
};
|
2023-09-26 18:12:56 +02:00
|
|
|
};
|
|
|
|
}
|