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

Using stylix with home.file #704

Open
henrispriet opened this issue Dec 28, 2024 · 2 comments
Open

Using stylix with home.file #704

henrispriet opened this issue Dec 28, 2024 · 2 comments

Comments

@henrispriet
Copy link

henrispriet commented Dec 28, 2024

Minimal Example

When using stylix with (flake standalone) home-manager I would like to do the following (example for lazygit):

# home.nix
{
  # ...
  programs.lazygit.enable = true;
  home.file.".config/lazygit/config.yml".source = ./dotfiles/.config/lazygit/config.yml;
  
  stylix = {
    enable = true;
    autoEnable = true;

    polarity = "dark";
    base16Scheme = "${pkgs.base16-schemes}/share/themes/gruvbox-dark-medium.yaml";
  }
  # ...
}
# dotfiles/.config/lazygit/config.yml
gui:
  border: single
notARepository: quit

HomeManager Error

But, I get this error from home-manager:

error:
       Failed assertions:
       - Conflicting managed target files: .config/lazygit/config.yml

       This may happen, for example, if you have a configuration similar to

           home.file = {
             conflict1 = { source = ./foo.nix; target = "baz"; };
             conflict2 = { source = ./bar.nix; target = "baz"; };
           }

Attempted Workarounds

1

-  programs.lazygit.enable = true;

I've tried leaving out the enable. Then, home-manager switch works, but the stylix config isn't applied, only that from the dotfiles (makes sense).

2

-  home.file.".config/lazygit/config.yml".source = ./dotfiles/.config/lazygit/config.yml;
+  home.file.".config/lazygit/config.yml".text = builtins.readFile ./dotfiles/.config/lazygit/config.yml;

I've also tried changing the home.file from source to textusing builtins.readFile, since nixos wiki mentions that

[...] "text" would add the text to the dot file that may also be affected in other places.

But, it gives the same error of Conflicting managed target files: .config/lazygit/config.yml.

Questions

  • Is there any way around this?
  • Is this a problem with stylix or with home-manager?
  • How can this be solved?
@trueNAHO
Copy link
Collaborator

  • Is this a problem with stylix or with home-manager?

It is an already acknowledged integration limitation between Stylix and Home Manager:

I wanted to override a few colors for Gnome (without recreating all the needed derivations), but it looks like that the template is hardcoded.

Ideally, we would upstream (NixOS, Home Manager, or nix-darwin) relevant options to seamlessly integrate Stylix into external Nix code.

There's this relevant thread: #159 about moving these templates out-of-tree. Would a PR for separating the mustache template to a different repo be acceptable here?

The future Vim highlight groups would allow us to get rid of mustache templates:

the roadmap eventually causes Stylix to implement all templates without relying on external dependencies

-- #567 (comment)

[...]

Are the patches really suitable for upstreaming though? It contains a lot of stylix-specific changes, like removing dark mode. The style sheet itself is also fairly opinionated and custom, which is not something I usually see upstream.

My idea was to move our string injection architecture

xdg.configFile."<MODULE>".text = "<KEY>=<VALUE>";

upstream, and then we only use its interface:

programs.<MODLE>.extraConfig."<KEY>" = "<VALUE>";

This centralizes the string injection upstream and hopefully gets rid of override issues:

the use of extraConfig might cause other potentially related issues. As discussed in #159 (comment), it makes it harder to override options, and as discussed in #388 (comment), it makes it easier to accidentally override Stylix options.

-- #395

-- NAHO, "Overriding Gnome template"

  • Is there any way around this?
  • How can this be solved?

Unless you copy-paste and slightly modify the current Stylix module implementation, I am unaware of a reliable solution before the previously mentioned limitations have been resolved. Depending on the configuration format, lib.mkAfter could be used.

This was referenced Dec 28, 2024
@danth
Copy link
Owner

danth commented Jan 6, 2025

Stylix uses the programs.lazygit.settings option:

programs.lazygit.settings.gui.theme = {

If you adapt your own configuration to also use this option, the two should merge together seamlessly.

Of course, this means you no longer have a configuration file in the original format to use outside of Home Manager.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants