Skip to content

Commit

Permalink
nixos/lemmy: only use env var when instructed
Browse files Browse the repository at this point in the history
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]: LemmyNet/lemmy#2945
  • Loading branch information
CobaltCause committed Jun 14, 2023
1 parent ae76739 commit 7621077
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions nixos/modules/services/web-apps/lemmy.nix
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ in
caddy.enable = mkEnableOption (lib.mdDoc "exposing lemmy with the caddy reverse proxy");
nginx.enable = mkEnableOption (lib.mdDoc "exposing lemmy with the nginx 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 = { };
Expand Down Expand Up @@ -190,9 +198,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 = [
Expand Down

0 comments on commit 7621077

Please sign in to comment.