Emacs theme not working with Emacs runs as a service

I’ve enabled the Emacs service through home-manager:

However when I open a new frame the color-theme isn’t working and I don’t really understand why.
The theme works fine I start Emacs normally (as in not as a service).
Does someone have a similar setup which is working?

How do you start the client?

With the .desktop file create by home-manager via Rofi.

How does that start Emacs?

Does it work properly when running emacsclient from a terminal?

I reckon it’s this one here:

I honestly don’t know where home-manager or even NixOS puts the .desktop files.
I found some when poking around but not all of them.

When starting emacsclient -c from the terminal it’s the same behaviour.

How are you setting your theme? Anything in the *Messages* buffer? Emacs has this feature where it will warn you that themes run arbitray lisp, and you need to interactively confirm that you’re ok with that. When using the daemon you might trigger that without being able to confirm it, which is usually how I lose my theme.

For what it’s worth, my config works with this: dotfiles/init.el at f47850e93ef32a29401d4f1cec5ba1c9dec3fe2d · TLATER/dotfiles · GitHub

Edit: Whoops, sorry. Was wondering what those links were after commenting. I’m very smart.

You disable theme loading when not in a graphical env:

(when (boundp 'enable-color-theme)
  (if (display-graphic-p)
    ;; load solarized color theme
    (use-package solarized-theme
        :ensure t
        :config
        (setq solarized-use-variable-pitch nil)
        (setq solarized-scale-org-headlines nil)
        (setq solarized-high-contrast-mode-line t)
        (set-face-inverse-video 'region nil)
        (load-theme 'solarized-light t))))

When the daemon starts, it’s not in a graphical env, so it doesn’t load the theme.

Ah okay I’ll try to modify that.
Can’t remember why I disabled the theme for the terminal in addition to the background.
Interestingly display-graphic-p shows true in the opened frame.

Yep, that function will refer to what the frame is operating on: https://www.gnu.org/software/emacs/manual/html_node/elisp/Display-Feature-Testing.html

Got it working with this commit:

Reverting this commit worked partially for the background in the terminal but that should be manageable:

I’m glad it was only an Emacs problem :slight_smile:

1 Like