feat(linkal): Put calendars of metis in a linkal instance

This commit is contained in:
sinavir 2023-10-03 01:03:42 +02:00
parent 566b392b21
commit 0ee8760f8d
3 changed files with 47 additions and 19 deletions

View file

@ -1,6 +1,26 @@
_: { lib, pkgs, sources, metisProviders, ...}:
let let
metisConf = pkgs.runCommandLocal "linkal-metis.json" {} ''
# jq dark magic
cat << EOF > script.jq
.sources |
${lib.concatStringsSep " |\n"
(lib.mapAttrsToList (name: value:
".\"${name}\" |= (
to_entries |
map({(\"https://${value}/remote.php/dav/public-calendars/\" + .key): .value}) |
add
)"
) metisProviders)
} |
to_entries |
map(.value) |
add |
{ calendars: . }
EOF
${pkgs.jq}/bin/jq -f script.jq > $out < ${sources.metis}/data/calendars.json
'';
host = "cal.dgnum.eu"; host = "cal.dgnum.eu";
calendarGroups = { calendarGroups = {
@ -19,6 +39,10 @@ let
}; };
}; };
}; };
ens = {
port = 8445;
config = metisConf;
};
}; };
in { in {
imports = [ ./module.nix ]; imports = [ ./module.nix ];

View file

@ -1,7 +1,7 @@
{ config, lib, pkgs, sources, ... }: { config, lib, pkgs, sources, ... }:
let let
inherit (lib) mapAttrs' mkEnableOption mkIf mkOption nameValuePair types; inherit (lib) mapAttrs mapAttrs' mkEnableOption mkIf mkOption nameValuePair types;
package = import sources.linkal { inherit pkgs; }; package = import sources.linkal { inherit pkgs; };
@ -20,20 +20,26 @@ in {
domain = mkOption { type = types.str; }; domain = mkOption { type = types.str; };
calendarGroups = mkOption { calendarGroups = mkOption {
type = let inherit (types) attrsOf port submodule; type = let inherit (types) attrsOf port submodule path;
in attrsOf (submodule { in attrsOf (submodule ({ config, ... }: {
options = { options = {
port = mkOption { type = port; }; port = mkOption { type = port; };
calendars = mkOption { inherit (jsonFormat) type; }; calendars = mkOption { inherit (jsonFormat) type; };
config = mkOption {
type = path;
default = jsonFormat.generate "linkal-config.json" { inherit (config) calendars; };
internal = true;
};
}; };
}); }));
default = { }; default = { };
}; };
}; };
config = mkIf cfg.enable { config = mkIf cfg.enable {
systemd.services = mapAttrs' (name: systemd.services = mapAttrs' (name:
{ port, calendars }: { port, config, ... }:
nameValuePair "linkal-${name}" { nameValuePair "linkal-${name}" {
description = "Linkal - ${name}"; description = "Linkal - ${name}";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];
@ -42,7 +48,7 @@ in {
ExecStart = "${cfg.package}/bin/linkal --port ${ ExecStart = "${cfg.package}/bin/linkal --port ${
builtins.toString port builtins.toString port
} --calendar-file ${ } --calendar-file ${
jsonFormat.generate "linkal-${name}.json" { inherit calendars; } config
}"; }";
}; };
}) cfg.calendarGroups; }) cfg.calendarGroups;

View file

@ -1,30 +1,23 @@
{ lib, pkgs, sources, ... }: { lib, pkgs, sources, metisProviders, ... }:
let let
package = (import sources.metis { inherit pkgs; }).production; package = (import sources.metis { inherit pkgs; }).production;
providers = {
klub-reseau = "nuage.beta.rz.ens.wtf";
eleves-ens = "cloud.eleves.ens.fr";
frama-agenda = "framagenda.org";
};
nginxConf = { nginxConf = {
enableACME = true; enableACME = true;
forceSSL = true; forceSSL = true;
root = package; root = package;
locations = lib.mapAttrs' (name: attrs: locations = lib.mapAttrs' (name: value:
lib.nameValuePair "/cal/${name}/" { lib.nameValuePair "/cal/${name}/" {
extraConfig = '' extraConfig = ''
proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Server $host; proxy_set_header X-Forwarded-Server $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass https://${ proxy_pass https://${value}/remote.php/dav/public-calendars/;
providers.${name}
}/remote.php/dav/public-calendars/;
''; '';
}) providers; }) metisProviders;
extraConfig = '' extraConfig = ''
rewrite ^/calendrier(.*)$ $1 permanent; rewrite ^/calendrier(.*)$ $1 permanent;
@ -32,6 +25,11 @@ let
}; };
in { in {
_module.args.metisProviders = {
klub-reseau = "nuage.beta.rz.ens.wtf";
eleves-ens = "cloud.eleves.ens.fr";
frama-agenda = "framagenda.org";
};
services.nginx.virtualHosts = { services.nginx.virtualHosts = {
"calendrier.eleves.ens.fr" = nginxConf; "calendrier.eleves.ens.fr" = nginxConf;
"calendrier.dgnum.eu" = nginxConf; "calendrier.dgnum.eu" = nginxConf;