diff --git a/nixos/modules/services/web-apps/librechat.nix b/nixos/modules/services/web-apps/librechat.nix index 120d6d092268..7313779305d8 100644 --- a/nixos/modules/services/web-apps/librechat.nix +++ b/nixos/modules/services/web-apps/librechat.nix @@ -85,6 +85,15 @@ in example = 2309; description = "The value that will be passed to the PORT environment variable, telling LibreChat what to listen on."; }; + LIBRECHAT_LOG_DIR = lib.mkOption { + type = lib.types.str; + default = "${cfg.dataDir}/logs"; + defaultText = lib.literalExpression "/var/lib/librechat/logs"; + description = '' + Logs will be saved into this directory. + By default it is relative to `services.librechat.dataDir`. + ''; + }; }; }; example = { diff --git a/pkgs/by-name/li/librechat/0002-logs.patch b/pkgs/by-name/li/librechat/0002-logs.patch deleted file mode 100644 index dab413703655..000000000000 --- a/pkgs/by-name/li/librechat/0002-logs.patch +++ /dev/null @@ -1,26 +0,0 @@ -diff --git a/api/config/meiliLogger.js b/api/config/meiliLogger.js -index 398672da5..fcd6864f8 100644 ---- a/api/config/meiliLogger.js -+++ b/api/config/meiliLogger.js -@@ -26,7 +26,7 @@ const getLogDir = () => { - } - - // Local development: use api/logs relative to this file -- return path.join(__dirname, '..', 'logs'); -+ return path.join('.', 'logs'); - }; - - const logDir = getLogDir(); -diff --git a/api/config/winston.js b/api/config/winston.js -index 93b84f7c4..4276bd6c2 100644 ---- a/api/config/winston.js -+++ b/api/config/winston.js -@@ -27,7 +27,7 @@ const getLogDir = () => { - } - - // Local development: use api/logs relative to this file -- return path.join(__dirname, '..', 'logs'); -+ return path.join('.', 'logs'); - }; - - const logDir = getLogDir(); \ No newline at end of file diff --git a/pkgs/by-name/li/librechat/0003-upload-paths.patch b/pkgs/by-name/li/librechat/0002-upload-paths.patch similarity index 100% rename from pkgs/by-name/li/librechat/0003-upload-paths.patch rename to pkgs/by-name/li/librechat/0002-upload-paths.patch diff --git a/pkgs/by-name/li/librechat/package.nix b/pkgs/by-name/li/librechat/package.nix index 021a6a216d81..6a09ac2d8aa5 100644 --- a/pkgs/by-name/li/librechat/package.nix +++ b/pkgs/by-name/li/librechat/package.nix @@ -29,14 +29,9 @@ buildNpmPackage (finalAttrs: { # Also, we set the `bin` property to the server script to benefit from the # auto-generated wrapper. ./0001-npm-pack.patch - # LibreChat tries writing logs to the package directory, which is immutable - # in our case. We patch the log directory to target the current working directory - # instead, which in case of NixOS will be the service's data directory. - ./0002-logs.patch - # Similarly to the logs, user uploads are by default written to the package - # directory as well. Again, we patch this to be relative to the current working - # directory instead. - ./0003-upload-paths.patch + # User uploads are by default written to the package directory as well. + # We patch this to be relative to the current working directory instead. + ./0002-upload-paths.patch ]; npmDepsFetcherVersion = 2; @@ -57,6 +52,13 @@ buildNpmPackage (finalAttrs: { npmBuildScript = "frontend"; npmPruneFlags = [ "--production" ]; + makeWrapperArgs = [ + # Upstream defaults to the immutable package directory. + # As a functioning default, we set this to the current working directory (through a relative logs path), + # but make it easy for the module to override. + "--set-default LIBRECHAT_LOG_DIR ./logs" + ]; + # npmConfigHook only patches the root node_modules postConfigure = '' patchShebangs client/node_modules