From 2857736e6bbc5ef15fb75f985129f04d5ece27a3 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Tue, 26 Sep 2023 18:12:56 +0200 Subject: [PATCH] feat(web01): Deploy multiple linkals on linkal.dgnum.eu --- machines/web01/_configuration.nix | 1 + machines/web01/linkal/default.nix | 32 ++++++++++++++ machines/web01/linkal/module.nix | 71 +++++++++++++++++++++++++++++++ npins/sources.json | 14 +++++- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 machines/web01/linkal/default.nix create mode 100644 machines/web01/linkal/module.nix diff --git a/machines/web01/_configuration.nix b/machines/web01/_configuration.nix index e323df0..8b38dd5 100644 --- a/machines/web01/_configuration.nix +++ b/machines/web01/_configuration.nix @@ -13,6 +13,7 @@ let # List of services to enable enabledServices = [ "metis" + "linkal" "plausible" # "wordpress" ]; diff --git a/machines/web01/linkal/default.nix b/machines/web01/linkal/default.nix new file mode 100644 index 0000000..4e0b99c --- /dev/null +++ b/machines/web01/linkal/default.nix @@ -0,0 +1,32 @@ +_: + +let + host = "linkal.dgnum.eu"; + + calendarGroups = { + luj-current = { + port = 8443; + calendars = { + "https://cloud.eleves.ens.fr/remote.php/dav/public-calendars/LLWm8qK9iC5YGrrR" = { + name = "Délégation Générale"; + short_name = "DG"; + }; + + "https://cloud.eleves.ens.fr/remote.php/dav/public-calendars/fRtjDkjrZyn6fxd8" = { + name = "K-Fêt"; + color = "#c63b52"; + default_location = "K-Fêt"; + }; + }; + }; + }; +in { + imports = [ ./module.nix ]; + + dgn-linkal = { + enable = true; + domain = host; + + inherit calendarGroups; + }; +} diff --git a/machines/web01/linkal/module.nix b/machines/web01/linkal/module.nix new file mode 100644 index 0000000..a584337 --- /dev/null +++ b/machines/web01/linkal/module.nix @@ -0,0 +1,71 @@ +{ 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; + }; + }; + }; +} diff --git a/npins/sources.json b/npins/sources.json index 955554b..473ca6a 100644 --- a/npins/sources.json +++ b/npins/sources.json @@ -1,5 +1,17 @@ { "pins": { + "linkal": { + "type": "Git", + "repository": { + "type": "GitHub", + "owner": "JulienMalka", + "repo": "Linkal" + }, + "branch": "main", + "revision": "8744b00eb819f181842f678bed6c1239f8210618", + "url": "https://github.com/JulienMalka/Linkal/archive/8744b00eb819f181842f678bed6c1239f8210618.tar.gz", + "hash": "03nk7x078bcvvv4i9xn29hpv041zxy62z2lfigxwdq1m8cnbwziw" + }, "agenix": { "type": "GitRelease", "repository": { @@ -98,4 +110,4 @@ } }, "version": 3 -} \ No newline at end of file +}