Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

nixos/discourse: fails to start #375168

Open
3 tasks done
kr-nn opened this issue Jan 19, 2025 · 0 comments
Open
3 tasks done

nixos/discourse: fails to start #375168

kr-nn opened this issue Jan 19, 2025 · 0 comments
Labels
0.kind: bug Something is broken 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS

Comments

@kr-nn
Copy link

kr-nn commented Jan 19, 2025

Nixpkgs version

  • Stable (24.11)

Describe the bug

databaseActuallyCreateLocally determines if we create discourse-postgresql.service but discourse.service still depends on it when host = null;

databaseActuallyCreateLocally = cfg.database.createLocally && cfg.database.host == null;
...

systemd.services.discourse-postgresql =
      let
        pgsql = config.services.postgresql;
      in
      lib.mkIf databaseActuallyCreateLocally {
        after = [ "postgresql.service" ];
        bindsTo = [ "postgresql.service" ];
        wantedBy = [ "discourse.service" ];
        partOf = [ "discourse.service" ];
        path = [
          pgsql.package
        ];
        script = ''
          set -o errexit -o pipefail -o nounset -o errtrace
          shopt -s inherit_errexit

          psql -tAc "SELECT 1 FROM pg_database WHERE datname = 'discourse'" | grep -q 1 || psql -tAc 'CREATE DATABASE "discourse" OWNER "discourse"'
          psql '${cfg.database.name}' -tAc "CREATE EXTENSION IF NOT EXISTS pg_trgm"
          psql '${cfg.database.name}' -tAc "CREATE EXTENSION IF NOT EXISTS hstore"
        '';

        serviceConfig = {
          User = pgsql.superUser;
          Type = "oneshot";
          RemainAfterExit = true;
        };
      };

...

systemd.services.discourse = {
      wantedBy = [ "multi-user.target" ];
      after = [
        "redis-discourse.service"
        "postgresql.service"
        "discourse-postgresql.service" # < This is here even when createLocally = false;
      ];

...

This causes an issue when we want to connect to a postgresql service by socket but not have it managed by services.discourse.database

Steps to reproduce

The below config is made so I can use discourse, but with my own postgres management
This is so I can get around the services.postgresql.ensureUsers.*.passwordFile issue: #326306
This is also in my opinion more secure since im not having to footgun a secret in a .drv

services.discourse.database = {
  # Note the lack of a host = "Discourse"; because we want to use a socket
  createLocally = false; # We want to manage the database with services.postgresql
};
services.postgresql = {
  enable = true;
  checkConfig = true;
  ensureDatabases = [ "discourse" ];
  ensureUsers = [
    { name = "discourse"; ensureClauses.login = true; ensureDBOwnership = true;}
  ];
  authentication = ''
    #type         database        DBuser          origin-address  auth-method
    local         all             discourse                       trust         # for database usage
    local         all             postgres                        trust         # for local superuser access
  ''
};

At runtime the discourse-progresql.service doesn't exist due to lib.mkIf databaseActuallyCreateLocally {...}

Expected behaviour

databaseActuallyCreateLocally should only handle the ensureDatabases = [ "discourse" ]; equivalent of the module.

Screenshots

service not started:
Image

Failing to start:
Image

Relevant log output

Additional context

No response

System metadata

Built with nixos-rebuild build-vm
Image

Notify maintainers


Note for maintainers: Please tag this issue in your pull request description. (i.e. Resolves #ISSUE.)

I assert that this issue is relevant for Nixpkgs

Is this issue important to you?

Add a 👍 reaction to issues you find important.

@kr-nn kr-nn added 0.kind: bug Something is broken 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Jan 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
Projects
None yet
Development

No branches or pull requests

1 participant