How to run Doom in daemon mode with a non-standard config?

As pointed out in a related question, my installation of Doom is customized so I can also run vanilla Emacs:

$ echo $DOOMDIR
/home/me/.config/doom

$ echo $EMACSDIR
/home/me/.doom

# Vanilla Emacs conf in ~/.config/emacs

With this config I can launch emacs (and run vanilla Emacs) or doom run (and run Doom).

The problem I can’t figure out is how to run Doom Emacs and run it as a daemon, so that I can connect to it with emacsclient.

This would allow me to also use the script org-capture that Doom provides

Currently: After I launch doom run if I launch emacsclient it start emacs --daemon but then opens vanilla Emacs.

Any suggestion? Thanks

When Doom starts, under doom-editor.el it checks for the environment variable $EMACS_SERVER_NAME to set the name of the server allowing you to connect to different instances by name.

Before you launch Doom, you can set $EMACS_SERVER_NAME to a name of your choice.

Then, emacsclient can be told to use that server name by setting the environment variable $EMACS_SOCKET_NAME prior, or by using its command line argument -s and providing the name.

Depending on your use of emacsclient, like running Doom’s provided org-capture script, without editing that script to add the arguments, it may be better to use the environment variable method. Otherwise, you’ll have to develop your own scripts/methods of managing these considerations.

Additionally, emacsclient supports the alternate editor (-a) argument which if left blank launches the default (Emacs) configuration in daemon mode if one isn’t already started. Or, you can have it run an instance of Doom (doom run) in your alternate location which would also accomplish the same. Just some food for thought, good luck.

P.S. I’ve tested the above and it does work as expected. You’ll just have to configure it for your use.