NixOS 22.05: Keycloak not working


I am trying to get keycloak working on 22.05. So far I ran into the issue that for some reason the keycloakPostgreSQLInit.service seems to fail, preventing the keycloak.service from coming up…

The service fails with an Error about “CREDENTIALS”.

When I log in as the postgres user, I can however simply run the script the keycloakPostgreSQLInit.service is trying to execute in order to create a database:

[root@keycloak:~]# sudo su postgres

[postgres@keycloak:/root]$ CREDENTIALS_DIRECTORY=/path/to/keycloak/credentials/directory /nix/store/...-unit-script-keycloakPostgreSQLInit-start/bin/keycloakPostgreSQLInit-start


Keycloak then still does not want to start because the service still fails, but I can’t seem to figure out why that is and I think removing the service as a dependency for the keycloak.service is probably not the right way to go about this…

My config looks like this:

  services.keycloak = {
    enable = true;
    settings = {
      hostname = "${service}.${fqdn}";
      httpPort = "10081";
    database = {
      passwordFile = "/path/to/keycloak/credentials/directory/passwordfile";


Has anyone run into the same issue?

1 Like

Could you provide more information from the journald logs? e.g. journalctl -u keycloakPostgreSQLInit.service

1 Like