Skip to content
This repository was archived by the owner on Aug 18, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
From d3d782d7ffa0dfd15e7c872b46d3e1ead7e8dda1 Mon Sep 17 00:00:00 2001
From: OPNA2608 <opna2608@protonmail.com>
Date: Mon, 28 Jul 2025 21:38:28 +0200
Subject: [PATCH] src/redis/mcaptcha_redis: Allow redis module to not be first
in list

---
src/redis/mcaptcha_redis.rs | 10 +++-------
1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/src/redis/mcaptcha_redis.rs b/src/redis/mcaptcha_redis.rs
index 63eacd3..9d2adac 100644
--- a/src/redis/mcaptcha_redis.rs
+++ b/src/redis/mcaptcha_redis.rs
@@ -70,13 +70,9 @@ impl MCaptchaRedis {
impl MCaptchaRedisConnection {
async fn is_module_loaded(&self) -> CaptchaResult<()> {
if let Value::Bulk(s) = self.0.exec(redis::cmd("MODULE").arg("LIST")).await.unwrap() {
- if let Some(Value::Bulk(s)) = s.first() {
- match s.iter().find(|i| format!("{:?}", i).contains(MODULE_NAME)) {
- Some(_) => (),
- None => return Err(CaptchaError::MCaptchaRedisModuleIsNotLoaded),
- }
- } else {
- return Err(CaptchaError::MCaptchaRedisModuleIsNotLoaded);
+ match s.iter().find(|i| format!("{:?}", i).contains(MODULE_NAME)) {
+ Some(_) => (),
+ None => return Err(CaptchaError::MCaptchaRedisModuleIsNotLoaded),
}
}

--
2.50.0

17 changes: 16 additions & 1 deletion pkgs/by-name/mcaptcha/package.nix
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,19 @@ let
};
};
in
mcaptcha
# Temporary fix: libmcaptcha crashes when redis doesn't reply to a module listing request with the mcaptcha module as
# the first entry
# Until this is addressed upstream and has found its way into the version of libmcaptcha used in mcaptcha, add our patch
mcaptcha.overrideAttrs (oa: {
cargoDeps = oa.cargoDeps.overrideAttrs (oa2: {
buildCommand = oa2.buildCommand + ''
realdir="$(realpath $out/libmcaptcha-0.2.4)"
rm "$out/libmcaptcha-0.2.4"
cp -r --no-preserve=mode "$realdir" "$out/libmcaptcha-0.2.4"

pushd "$out/libmcaptcha-0.2.4"
patch -p1 < ${./1001-libmcaptcha-Allow-redis-module-to-not-be-first-in-list.patch}
popd
'';
});
})
4 changes: 3 additions & 1 deletion projects/mCaptcha/services/mcaptcha/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,11 @@ in

systemd.services.mcaptcha.environment.MCAPTCHA_CONFIG = builtins.toString configFile;
systemd.services.mcaptcha.after = [
"network-online.target"
"syslog.target"
]
++ lib.optionals cfg.database.createLocally [ "postgresql.service" ];
++ lib.optionals cfg.database.createLocally [ "postgresql.target" ]
++ lib.optionals cfg.redis.createLocally [ "redis-mcaptcha.service" ];
systemd.services.mcaptcha.bindsTo = lib.optionals cfg.database.createLocally [
"postgresql.service"
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ in
psql my_mcaptcha -c "ALTER USER my_mcaptcha WITH PASSWORD 'mcaptcha-db-secret'"
'';
services.postgresql.authentication = ''
#type database DBuser auth-method
host all all 0.0.0.0/0 md5
#type database DBuser host auth-method
host all all all md5
'';
services.redis.servers.mcaptcha.enable = true;
services.redis.servers.mcaptcha.port = 6379;
Expand All @@ -80,7 +80,9 @@ in

my_own_services.start()
my_own_services.wait_for_unit("redis-mcaptcha.service")
my_own_services.wait_for_unit("postgresql.service")
# Waiting for postgresql in multiple steps to avoid timeouts under load
my_own_services.wait_for_unit("postgresql.service") # startup
my_own_services.wait_for_unit("postgresql.target") # initial setup finished

mcaptcha.start()

Expand Down