From 9d78bf0470be1dfa51bc5613d49fde5a302cb3fa Mon Sep 17 00:00:00 2001 From: chn Date: Sat, 26 Aug 2023 14:07:57 +0800 Subject: [PATCH] misskey proxy allow multiple instances --- flake.nix | 2 +- modules/services/misskey.nix | 33 +++++++++++++++++++++------------ 2 files changed, 22 insertions(+), 13 deletions(-) diff --git a/flake.nix b/flake.nix index 4f74a2bb..c092f110 100644 --- a/flake.nix +++ b/flake.nix @@ -248,7 +248,7 @@ }; }; }; - misskey-proxy = { enable = true; hostname = "xn--qbtm095lrg0bfka60z.chn.moe"; }; + misskey-proxy."xn--qbtm095lrg0bfka60z.chn.moe" = {}; }; boot = { diff --git a/modules/services/misskey.nix b/modules/services/misskey.nix index 0fbd64b1..ff367e29 100644 --- a/modules/services/misskey.nix +++ b/modules/services/misskey.nix @@ -8,16 +8,19 @@ inputs: port = mkOption { type = types.ints.unsigned; default = 9726; }; hostname = mkOption { type = types.str; default = "misskey.chn.moe"; }; }; - misskey-proxy = + misskey-proxy = mkOption { - enable = mkOption { type = types.bool; default = false; }; - hostname = mkOption { type = types.str; default = "misskey.chn.moe"; }; + type = types.attrsOf (types.submodule (submoduleInputs: { options = + { + hostname = mkOption { type = types.str; default = submoduleInputs.config._module.args.name; }; + };})); + default = {}; }; }; config = let inherit (inputs.config.nixos.services) misskey misskey-proxy; - inherit (inputs.localLib) stripeTabs; + inherit (inputs.localLib) stripeTabs attrsToList; inherit (inputs.lib) mkIf mkMerge; inherit (builtins) map listToAttrs toString replaceStrings; in mkMerge @@ -132,18 +135,24 @@ inputs: meilisearch.instances.misskey = { user = inputs.config.users.users.misskey.name; port = 7700; }; }; }) - (mkIf misskey-proxy.enable + (mkIf (misskey-proxy != {}) { nixos.services.nginx = { enable = true; - httpProxy."${misskey-proxy.hostname}" = - { - upstream = "https://direct.${misskey-proxy.hostname}"; - websocket = true; - setHeaders.Host = "direct.${misskey-proxy.hostname}"; - addAuth = true; - }; + httpProxy = listToAttrs (map + (proxy: + { + name = proxy.value.hostname; + value = + { + upstream = "https://direct.${proxy.value.hostname}"; + websocket = true; + setHeaders.Host = "direct.${proxy.value.hostname}"; + addAuth = true; + }; + }) + (attrsToList misskey-proxy)); }; }) ];