Commit 03ae7061 authored by Gutyina Gergő's avatar Gutyina Gergő Committed by Niklas Korz
Browse files

nixos/librechat: add log directory option instead of hardcoding it in the package

parent 0d96729e
Loading
Loading
Loading
Loading
+9 −0
Original line number Diff line number Diff line
@@ -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 = {
+0 −26
Original line number Diff line number Diff line
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
+10 −8
Original line number Diff line number Diff line
@@ -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