diff --git a/hosts/by-name/servo/services/lemmy.nix b/hosts/by-name/servo/services/lemmy.nix index 8dba11d1..43732102 100644 --- a/hosts/by-name/servo/services/lemmy.nix +++ b/hosts/by-name/servo/services/lemmy.nix @@ -12,6 +12,15 @@ in { settings.options.federation.enabled = true; settings.options.port = backendPort; # settings.database.host = "localhost"; + # defaults + # settings.database = { + # user = "lemmy"; + # host = "/run/postgresql"; + # # host = "localhost"; # fails with "fe_sendauth: no password supplied" + # port = 5432; + # database = "lemmy"; + # pool_size = 5; + # }; ui.port = uiPort; database.createLocally = true; }; @@ -21,7 +30,17 @@ in { DynamicUser = mkForce false; User = "lemmy"; Group = "lemmy"; - Environment = [ "RUST_BACKTRACE=full" ]; + # Environment = [ "RUST_BACKTRACE=full" "RUST_LOG=info" ]; + }; + systemd.services.lemmy.environment = { + RUST_BACKTRACE = "full"; + # upstream defaults LEMMY_DATABASE_URL = "postgres:///lemmy?host=/run/postgresql"; + # - Postgres complains that we didn't specify a user + # lemmy formats the url as: + # - postgres://{user}:{password}@{host}:{port}/{database} + # LEMMY_DATABASE_URL = "postgres://lemmy@/run/postgresql"; # connection to server on socket "/run/postgresql/.s.PGSQL.5432" failed: FATAL: database "run/postgresql" does not exist + # LEMMY_DATABASE_URL = "postgres://lemmy?host=/run/postgresql"; # no PostgreSQL user name specified in startup packet + LEMMY_DATABASE_URL = mkForce "postgres://lemmy@?host=/run/postgresql"; }; users.groups.lemmy = {}; users.users.lemmy = { diff --git a/overlays/pins.nix b/overlays/pins.nix index 29892b9c..627c8b41 100644 --- a/overlays/pins.nix +++ b/overlays/pins.nix @@ -28,30 +28,4 @@ # }) # ]; # }); - lemmy-server = prev.lemmy-server.overrideAttrs (upstream: { - patches = upstream.patches or [] ++ [ - # "thread 'main' panicked at 'Couldn't run DB Migrations: Failed to run 2022-07-07-182650_comment_ltrees with: permission denied: "RI_ConstraintTrigger_a_647340" is a system trigger', crates/db_schema/src/utils.rs:165:25" - (next.writeText "fix-db-migrations" '' - diff --git a/migrations/2022-07-07-182650_comment_ltrees/up.sql b/migrations/2022-07-07-182650_comment_ltrees/up.sql - index fde9e1b3..55b96dac 100644 - --- a/migrations/2022-07-07-182650_comment_ltrees/up.sql - +++ b/migrations/2022-07-07-182650_comment_ltrees/up.sql - @@ -60,7 +60,7 @@ ORDER BY - breadcrumb; - - -- Remove indexes and foreign key constraints, and disable triggers for faster updates - -alter table comment disable trigger all; - +-- alter table comment disable trigger all; - - alter table comment drop constraint if exists comment_creator_id_fkey; - alter table comment drop constraint if exists comment_parent_id_fkey; - @@ -115,4 +115,4 @@ create index idx_path_gist on comment using gist (path); - -- Drop the parent_id column - alter table comment drop column parent_id cascade; - - -alter table comment enable trigger all; - +-- alter table comment enable trigger all; - '') - ]; - }); }) diff --git a/pkgs/default.nix b/pkgs/default.nix index ceeb3175..91dffe8f 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -60,6 +60,8 @@ let # jackett doesn't allow customization of the bind address: this will probably always be here. jackett = callPackage ./patched/jackett { inherit (unpatched) jackett; }; + lemmy-server = callPackage ./patched/lemmy-server { inherit (unpatched) lemmy-server; }; + ### PYTHON PACKAGES pythonPackagesExtensions = (unpatched.pythonPackagesExtensions or []) ++ [ diff --git a/pkgs/patched/lemmy-server/default.nix b/pkgs/patched/lemmy-server/default.nix new file mode 100644 index 00000000..576b50ec --- /dev/null +++ b/pkgs/patched/lemmy-server/default.nix @@ -0,0 +1,9 @@ +{ lemmy-server }: + +lemmy-server.overrideAttrs (upstream: { + patches = upstream.patches or [] ++ [ + # "thread 'main' panicked at 'Couldn't run DB Migrations: Failed to run 2022-07-07-182650_comment_ltrees with: permission denied: "RI_ConstraintTrigger_a_647340" is a system trigger', crates/db_schema/src/utils.rs:165:25" + ./fix-db-migrations.patch + ./log-startup.patch + ]; +}) diff --git a/pkgs/patched/lemmy-server/fix-db-migrations.patch b/pkgs/patched/lemmy-server/fix-db-migrations.patch new file mode 100644 index 00000000..df4f210d --- /dev/null +++ b/pkgs/patched/lemmy-server/fix-db-migrations.patch @@ -0,0 +1,19 @@ +diff --git a/migrations/2022-07-07-182650_comment_ltrees/up.sql b/migrations/2022-07-07-182650_comment_ltrees/up.sql +index fde9e1b3..55b96dac 100644 +--- a/migrations/2022-07-07-182650_comment_ltrees/up.sql ++++ b/migrations/2022-07-07-182650_comment_ltrees/up.sql +@@ -60,7 +60,7 @@ ORDER BY + breadcrumb; + + -- Remove indexes and foreign key constraints, and disable triggers for faster updates +-alter table comment disable trigger all; ++-- alter table comment disable trigger all; + + alter table comment drop constraint if exists comment_creator_id_fkey; + alter table comment drop constraint if exists comment_parent_id_fkey; +@@ -115,4 +115,4 @@ create index idx_path_gist on comment using gist (path); + -- Drop the parent_id column + alter table comment drop column parent_id cascade; + +-alter table comment enable trigger all; ++-- alter table comment enable trigger all; diff --git a/pkgs/patched/lemmy-server/log-startup.patch b/pkgs/patched/lemmy-server/log-startup.patch new file mode 100644 index 00000000..ae32fb2c --- /dev/null +++ b/pkgs/patched/lemmy-server/log-startup.patch @@ -0,0 +1,56 @@ +diff --git a/crates/db_schema/src/utils.rs b/crates/db_schema/src/utils.rs +index acedab97..4b62b5bb 100644 +--- a/crates/db_schema/src/utils.rs ++++ b/crates/db_schema/src/utils.rs +@@ -134,9 +134,12 @@ pub fn diesel_option_overwrite_to_url_create( + } + + async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result { ++ println!("build_db_pool_settings_opt"); + let db_url = get_database_url(settings); ++ println!(" db_url: {db_url}"); + let pool_size = settings.map(|s| s.database.pool_size).unwrap_or(5); + let manager = AsyncDieselConnectionManager::::new(&db_url); ++ println!(" built manager"); + let pool = Pool::builder(manager) + .max_size(pool_size) + .wait_timeout(POOL_TIMEOUT) +@@ -144,12 +147,15 @@ async fn build_db_pool_settings_opt(settings: Option<&Settings>) -> Result Result<(), LemmyError> { ++ println!("run_advanced_migrations"); + let protocol_and_hostname = &settings.get_protocol_and_hostname(); ++ println!(" conn: {protocol_and_hostname}"); + user_updates_2020_04_02(pool, protocol_and_hostname).await?; + community_updates_2020_04_02(pool, protocol_and_hostname).await?; + post_updates_2020_04_03(pool, protocol_and_hostname).await?; +@@ -52,6 +54,8 @@ pub async fn run_advanced_migrations(pool: &DbPool, settings: &Settings) -> Resu + regenerate_public_keys_2022_07_05(pool).await?; + initialize_local_site_2022_10_10(pool, settings).await?; + ++ println!(" complete"); ++ + Ok(()) + } +