Skip to content

{i3,sway}: export bar configuration through options#1502

Merged
trueNAHO merged 2 commits intonix-community:masterfrom
Flameopathic:export-configuration-through-options
Jul 8, 2025
Merged

{i3,sway}: export bar configuration through options#1502
trueNAHO merged 2 commits intonix-community:masterfrom
Flameopathic:export-configuration-through-options

Conversation

@Flameopathic
Copy link
Copy Markdown
Contributor

@Flameopathic Flameopathic commented Jun 14, 2025

Related: #1469

Possibly related: #415

Things done

Notify maintainers

@mightyiam @butzist @trueNAHO

@stylix-automation stylix-automation bot added the topic: home-manager Home Manager target label Jun 14, 2025
@Flameopathic Flameopathic force-pushed the export-configuration-through-options branch from 447f3b0 to 678da55 Compare June 14, 2025 19:07
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be desirable to generally expose every target's configuration? In that case, mkTarget would generate the option with a consistent description. Unsure whether the configuration should be declared in the option as:

options.stylix.targets.${name}.config = lib.mkOption {
  default = /* configuration */;
  readOnly = true;
};

config = config.stylix.targets.${name}.config;

or in the configuration as:

options.stylix.targets.${name}.config = lib.mkOption {
  readOnly = true;
};

config.stylix.targets.${name}.config = /* configuration */;

On a side note, once the mkTarget migration is complete, we could trivially allow end-users to extend mkTarget's configElements:

options.stylix.targets.${name}.extraConfig = lib.mkOption {
  type = /* mkTarget's configElements */;
  description = /* Provide a link to mkTarget's source code documentation */;
  default = [];
};

config = lib.mkIf (config.stylix.enable && cfg.enable) (
  lib.mkMerge (
    lib.optional (generalConfig != null) (mkConfig generalConfig)
    ++ map mkConditionalConfig (
      (lib.toList configElements) ++ (lib.toList cfg.extraConfig)
    )
  )
);

This would allow grouping styling-related declarations under the stylix namespace:

stylix = {
  enable = true;

  targets."<TARGET>".extraConfig =
    { colors }:
    { programs."<TARGET>".settings.background = lib.mkForce colors.base01; };
};

@Flameopathic
Copy link
Copy Markdown
Contributor Author

Would it be desirable to generally expose every target's configuration?

I don't think so; I can't think of a use case. These specific examples are solutions to somewhat uncommon problems, and they require a specific subset of the target's config output, rather than the whole thing.

Copy link
Copy Markdown
Member

@mightyiam mightyiam left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This exportedFoo, is there precedence for this in the ecosystem? I'm not opposed to it. Seems alright to me.

Comment thread modules/i3/hm.nix Outdated
Comment thread modules/i3/meta.nix Outdated
Comment thread modules/i3status-rust/hm.nix Outdated
Comment thread modules/neovim/nixvim.nix Outdated
@danth
Copy link
Copy Markdown
Member

danth commented Jun 15, 2025

I do question what makes these modules any different than Firefox and VSCode. For that reason, I'm not sure if I would say that this is a full formalization, as these targets need their configurations manually merged while Firefox and VSCode use an option to decide the attribute paths.

There's nothing fundamentally different - I think it's just that these modules are very old and haven't had a lot of attention since. It should be possible to make these modules work the way Firefox and VSCode do, or the other way around, to settle on a standard.

Would it be desirable to generally expose every target's configuration?

In most cases this is already available by reading the options we set, unless the user has overridden it. But in that case they would probably be interested in reading their overridden version anyway.

@Flameopathic Flameopathic force-pushed the export-configuration-through-options branch from 678da55 to 5711904 Compare June 15, 2025 21:17
@Flameopathic
Copy link
Copy Markdown
Contributor Author

This exportedFoo, is there precedence for this in the ecosystem? I'm not opposed to it. Seems alright to me.

No, this would be setting a precedent.


I do question what makes these modules any different than Firefox and VSCode. For that reason, I'm not sure if I would say that this is a full formalization, as these targets need their configurations manually merged while Firefox and VSCode use an option to decide the attribute paths.

There's nothing fundamentally different - I think it's just that these modules are very old and haven't had a lot of attention since. It should be possible to make these modules work the way Firefox and VSCode do, or the other way around, to settle on a standard.

Alright. In that case, I think that this NixVim option is still necessary because its use is slightly different than the others, but all of the other targets should be set up like VSCode and Firefox. To do that, though, it would probably be worth having some sort of abstraction for setting up warnings and/or options.

@Flameopathic Flameopathic marked this pull request as draft June 16, 2025 20:21
@Flameopathic Flameopathic marked this pull request as draft June 16, 2025 20:21
@Flameopathic Flameopathic marked this pull request as draft June 16, 2025 20:21
@0xda157
Copy link
Copy Markdown
Contributor

0xda157 commented Jun 16, 2025

the naming of this pr/commit/options doesn't make much sense, config already means something in the nix module system. Renaming the options to some else would be best, e.g. exportedModule for the nixvim module.

@trueNAHO
Copy link
Copy Markdown
Member

I do question what makes these modules any different than Firefox and VSCode. For that reason, I'm not sure if I would say that this is a full formalization, as these targets need their configurations manually merged while Firefox and VSCode use an option to decide the attribute paths.

There's nothing fundamentally different - I think it's just that these modules are very old and haven't had a lot of attention since. It should be possible to make these modules work the way Firefox and VSCode do, or the other way around, to settle on a standard.

Alright. In that case, I think that this NixVim option is still necessary because its use is slightly different than the others, but all of the other targets should be set up like VSCode and Firefox.

The NixVim config is exposed to support the standalone use case:

commit 0a4755b656c28043c52063384fc68bbb30913903
Author: Matt Sturgeon <matt@sturgeon.me.uk>
Date:   2024-06-05 03:10:32 +0100

    nixvim: expose config as read-only option

    Allow standalone nixvim users to take advantage of stylix by exposing
    the generated config as `config.lib.stylix.nixvim.config`.

    This can be passed to the nixvim derivation's `extend` function or used
    directly in a nixvim configuration.

The other modules touched in this PR expose sensible theming declarations to allow end-users to build upon them to write their own configuration. This pattern is inconsistent with declaring a sensible default configuration without any real customizing capabilities (aside from simply overriding it with lib.mkIf), as used in /modules/plymouth/theme-script.nix and potentially other (pending?) modules.

Should these declaration expositions and default configurations be handled differently or not? The /modules/plymouth/theme-script.nix case is inherently hard to generally extend to same extent the exposed Nix attribute sets are.

@Flameopathic
Copy link
Copy Markdown
Contributor Author

The other modules touched in this PR expose sensible theming declarations to allow end-users to build upon them to write their own configuration.

I was under the impression that this is not the primary goal of exporting the configuration and that the actual goal is to give the user a relatively simple way of applying theming to attributes with user-set paths (ex. wayland.windowManager.sway.config.bars.*).

This pattern is inconsistent with declaring a sensible default configuration without any real customizing capabilities (aside from simply overriding it with lib.mkIf), as used in /modules/plymouth/theme-script.nix and potentially other (pending?) modules.

Agreed. Do you mean lib.mkForce rather than lib.mkIf?

Should these declaration expositions and default configurations be handled differently or not? The /modules/plymouth/theme-script.nix case is inherently hard to generally extend to same extent the exposed Nix attribute sets are.

I believe that this is another good reason to make these targets function like Firefox and VSCode, which would mean they would behave more like regular targets.

@mightyiam
Copy link
Copy Markdown
Member

I was under the impression that this is not the primary goal of exporting the configuration and that the actual goal is to give the user a relatively simple way of applying theming to attributes with user-set paths

👍

Simply overriding with lib.mkForce is flexible enough I think.

Targets that can behave like Firefox probably should. All they need to know is some attribute name to apply to. It's the list case that can't quite work that way and forces us to provide a value for the user to wire up themselves.

@trueNAHO
Copy link
Copy Markdown
Member

The other modules touched in this PR expose sensible theming declarations to allow end-users to build upon them to write their own configuration.

I was under the impression that this is not the primary goal of exporting the configuration and that the actual goal is to give the user a relatively simple way of applying theming to attributes with user-set paths (ex. wayland.windowManager.sway.config.bars.*).

Either way, extending the Stylix configuration seems to be the end result.

This pattern is inconsistent with declaring a sensible default configuration without any real customizing capabilities (aside from simply overriding it with lib.mkIf), as used in /modules/plymouth/theme-script.nix and potentially other (pending?) modules.

Agreed. Do you mean lib.mkForce rather than lib.mkIf?

Yes, I meant lib.mkForce.

Should these declaration expositions and default configurations be handled differently or not? The /modules/plymouth/theme-script.nix case is inherently hard to generally extend to same extent the exposed Nix attribute sets are.

I believe that this is another good reason to make these targets function like Firefox and VSCode, which would mean they would behave more like regular targets.

What exactly do you mean by making the targets from this PR like Firefox and VSCode? Do you mean providing extraOptions to be merged inside our internal configElements declaration? In that case, should we just already implement the generic extraConfig option:

On a side note, once the mkTarget migration is complete, we could trivially allow end-users to extend mkTarget's configElements:

options.stylix.targets.${name}.extraConfig = lib.mkOption {
  type = /* mkTarget's configElements */;
  description = /* Provide a link to mkTarget's source code documentation */;
  default = [];
};

config = lib.mkIf (config.stylix.enable && cfg.enable) (
  lib.mkMerge (
    lib.optional (generalConfig != null) (mkConfig generalConfig)
    ++ map mkConditionalConfig (
      (lib.toList configElements) ++ (lib.toList cfg.extraConfig)
    )
  )
);

This would allow grouping styling-related declarations under the stylix namespace:

stylix = {
  enable = true;

  targets."<TARGET>".extraConfig =
    { colors }:
    { programs."<TARGET>".settings.background = lib.mkForce colors.base01; };
};

-- #1502 (review)

@Flameopathic
Copy link
Copy Markdown
Contributor Author

Should these declaration expositions and default configurations be handled differently or not? The /modules/plymouth/theme-script.nix case is inherently hard to generally extend to same extent the exposed Nix attribute sets are.

I believe that this is another good reason to make these targets function like Firefox and VSCode, which would mean they would behave more like regular targets.

What exactly do you mean by making the targets from this PR like Firefox and VSCode?

Firefox and VSCode use profileNames options to determine the options that they are supposed to be setting (programs.firefox.profiles.<<name>>) because otherwise Stylix would not know where to apply configuration. I believe that all of these targets (except for NixVim) are exporting their configuration so that the user can apply it to the appropriate attributes with arbitrary paths (xsession.windowManager.i3.config.bars.«name» in the case of i3's bar config export). These are two fundamentally different ways of accomplishing the same task, and I believe that we want to unify them.

@Flameopathic Flameopathic force-pushed the export-configuration-through-options branch 2 times, most recently from 6681108 to 2a8e5e6 Compare June 29, 2025 20:40
@Flameopathic Flameopathic changed the title treewide: export configuration through options {i3, sway}: export bar configuration through options Jun 29, 2025
@Flameopathic
Copy link
Copy Markdown
Contributor Author

It's the list case that can't quite work that way and forces us to provide a value for the user to wire up themselves.

I completely missed this detail. I hadn't realized the difference between something.* and something.<name>.

I have adjusted the scope of this PR to exclude i3status-rust (as its bar configurations are named and can be treated like Firefox) and nixvim (as I have already made the necessary change in #1535).

@Flameopathic Flameopathic marked this pull request as ready for review June 29, 2025 20:43
@mightyiam
Copy link
Copy Markdown
Member

I notice that this is marked as ready for review but just making sure by asking. Would it help if I tested this against my presonal usage at this point?

@Flameopathic
Copy link
Copy Markdown
Contributor Author

This is ready for review, but it no longer includes NixVim. If you use i3 or sway bars, though, it would help if you tested this.

@mightyiam
Copy link
Copy Markdown
Member

Ah, no, I don't use them, sorry. Thanks. Keep up the good work.

@trueNAHO trueNAHO changed the title {i3, sway}: export bar configuration through options {i3,sway}: export bar configuration through options Jul 5, 2025
@Flameopathic Flameopathic force-pushed the export-configuration-through-options branch from 2a8e5e6 to e7ce05c Compare July 5, 2025 15:27
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For reference, although I have opened #1601, this should not affect the scope of this PR. The scope of this PR is good as-is.

Comment thread modules/sway/hm.nix Outdated
Comment thread modules/sway/meta.nix Outdated
Comment thread modules/i3/meta.nix Outdated
Comment thread modules/i3/hm.nix Outdated
Comment thread modules/i3/hm.nix Outdated
Comment thread modules/sway/hm.nix
Comment thread modules/sway/hm.nix Outdated
Comment thread modules/i3/hm.nix
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Copy link
Copy Markdown
Member

@trueNAHO trueNAHO left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@trueNAHO trueNAHO merged commit a0e891b into nix-community:master Jul 8, 2025
5 checks passed
stylix-automation bot pushed a commit that referenced this pull request Jul 8, 2025
Link: #1502

Reviewed-by: Daniel Thwaites <danth@danth.me>
Reviewed-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
(cherry picked from commit a0e891b)
@stylix-automation
Copy link
Copy Markdown
Contributor

Successfully created backport PR for release-25.05:

trueNAHO added a commit that referenced this pull request Jul 8, 2025
Link: #1502

Reviewed-by: Daniel Thwaites <danth@danth.me>
Reviewed-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
(cherry picked from commit a0e891b)
trueNAHO added a commit to trueNAHO/stylix that referenced this pull request Jul 10, 2025
Fixes: a0e891b ("{i3,sway}: export bar configuration through options (nix-community#1502)")
LunaCOLON3 pushed a commit to LunaCOLON3/stylix that referenced this pull request Jul 14, 2025
Link: nix-community#1502

Reviewed-by: Daniel Thwaites <danth@danth.me>
Reviewed-by: Shahar "Dawn" Or <mightyiampresence@gmail.com>
Co-authored-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
Reviewed-by: NAHO <90870942+trueNAHO@users.noreply.github.com>
@Flameopathic Flameopathic deleted the export-configuration-through-options branch September 24, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

topic: home-manager Home Manager target

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants