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

nixvim: support standalone config as read-only option #795

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 93 additions & 75 deletions modules/nixvim/nixvim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,26 @@ in
main = lib.mkEnableOption "background transparency for the main NeoVim window";
signColumn = lib.mkEnableOption "background transparency for the NeoVim sign column";
};
config = lib.mkOption {

Choose a reason for hiding this comment

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

In #415, the consensus seemed to be that we should assign the nixvim config to config.lib.stylix.nixvim.config.

Doing that is incompatible with declaring an option, though. So it would be more difficult to document.

type = with lib.types; attrsOf anything;
readOnly = true;

description = ''
The stylix configuration, generated for nixvim.
If nixvim is installed via nixos, darwin, or home-manager then this will be **automatically**
assigned to `programs.nixvim`. If you're using a "standalone" build of nixvim, then that's
not possible. Instead, you should pass this config to the `extend` function.
For example:
```nix
{ config, ... }: {
environment.systemPackages = [
(inputs.<your-nixvim-input>.<your-system>.default.extend config.stylix.targets.nixvim.config)
];
}
```
See nixvim's docs on [extending a standalone configuration](https://nix-community.github.io/nixvim/platforms/standalone.html?highlight=extend#extending-an-existing-configuration).

Choose a reason for hiding this comment

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

Suggested change
See nixvim's docs on [extending a standalone configuration](https://nix-community.github.io/nixvim/platforms/standalone.html?highlight=extend#extending-an-existing-configuration).
See nixvim's docs on [extending a standalone configuration](https://nix-community.github.io/nixvim/platforms/standalone.html#extending-an-existing-configuration).

Probably better without the highlight?

'';
};
};

imports = [
Expand Down Expand Up @@ -63,80 +83,78 @@ in
})
];

config =
lib.mkIf (config.stylix.enable && cfg.enable && (config.programs ? nixvim))
(
lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) (
lib.mkMerge [
(lib.mkIf (cfg.plugin == "base16-nvim") {
programs.nixvim.colorschemes.base16 = {
enable = true;
config = lib.mkIf (config.stylix.enable && cfg.enable) {
stylix.targets.nixvim.config = lib.mkMerge [
Comment on lines +86 to +87

Choose a reason for hiding this comment

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

This option def shouldn't need to be conditional.

Rather, only the programs definition below should be conditional.

For comparison, my impl looks like:

config = {
  programs = lib.mkIf (config.stylix.enable && cfg.enable) (
    lib.optionalAttrs (options.programs ? nixvim) {
      nixvim = config.lib.stylix.nixvim.config;
    }
  );
  lib.stylix.nixvim.config = lib.mkMerge [

(lib.mkIf (cfg.plugin == "base16-nvim") {
colorschemes.base16 = {
enable = true;
colorscheme = {
inherit (config.lib.stylix.colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
})
(lib.mkIf (cfg.plugin == "mini.base16") {
plugins.mini = {
enable = true;
modules.base16.palette = {
inherit (config.lib.stylix.colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
})
{
highlight =
let
transparent = {
bg = "none";
ctermbg = "none";
};
in
{
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
};
}
];

colorscheme = {
inherit (config.lib.stylix.colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
})
(lib.mkIf (cfg.plugin == "mini.base16") {
programs.nixvim.plugins.mini = {
enable = true;

modules.base16.palette = {
inherit (config.lib.stylix.colors.withHashtag)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
};
})
{
programs.nixvim = {
highlight =
let
transparent = {
bg = "none";
ctermbg = "none";
};
in
{
Normal = lib.mkIf cfg.transparentBackground.main transparent;
NonText = lib.mkIf cfg.transparentBackground.main transparent;
SignColumn = lib.mkIf cfg.transparentBackground.signColumn transparent;
};
};
}
]
)
);
programs = lib.optionalAttrs (builtins.hasAttr "nixvim" options.programs) (
lib.mkIf config.stylix.targets.nixvim.enable {
nixvim = config.stylix.targets.nixvim.config;
}
);
};
}
Loading