From 9b7a3295e609066d705eb62fbd40533713277392 Mon Sep 17 00:00:00 2001 From: Charles Hall Date: Tue, 6 Jun 2023 08:11:49 -0700 Subject: [PATCH] nixos/lemmy: only use env var when instructed Lemmy checks the environment variable before the configuration file; i.e. if the file is used to configure the database but the environment variable is set to anything, the connection will fail because it'll ignore the file. This was the previous behavior. Now, the environment variable will be unset unless the user explicitly chooses to set it, which makes the file-based configuration function correctly. It's also possible to manually set the environment variable, which has the major advantage of working around [this issue][0], which prevents certain setups from working. [0]: https://github.com/LemmyNet/lemmy/issues/2945 (cherry picked from commit 7621077224a013ded652582ce18f879c5d6aca86) --- nixos/modules/services/web-apps/lemmy.nix | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/nixos/modules/services/web-apps/lemmy.nix b/nixos/modules/services/web-apps/lemmy.nix index 755f09c48964..d6abe8e51085 100644 --- a/nixos/modules/services/web-apps/lemmy.nix +++ b/nixos/modules/services/web-apps/lemmy.nix @@ -26,7 +26,15 @@ in caddy.enable = mkEnableOption (lib.mdDoc "exposing lemmy with the caddy reverse proxy"); - database.createLocally = mkEnableOption (lib.mdDoc "creation of database on the instance"); + database = { + createLocally = mkEnableOption (lib.mdDoc "creation of database on the instance"); + + uri = mkOption { + type = with types; nullOr str; + default = null; + description = lib.mdDoc "The connection URI to use. Takes priority over the configuration file if set."; + }; + }; settings = mkOption { default = { }; @@ -154,9 +162,7 @@ in environment = { LEMMY_CONFIG_LOCATION = "/run/lemmy/config.hjson"; - - # Verify how this is used, and don't put the password in the nix store - LEMMY_DATABASE_URL = with cfg.settings.database;"postgres:///${database}?host=${host}"; + LEMMY_DATABASE_URL = mkIf (cfg.database.uri != null) cfg.database.uri; }; documentation = [