From a1c4e8179bfe7345945b6c18998b5b0480e58bbd Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Mon, 25 Jul 2022 20:38:43 +0100 Subject: [PATCH] Create an enable option for each module :sparkles: Fixes #7 --- README.md | 12 ++ flake.nix | 1 + modules/alacritty.nix | 23 ++- modules/console.nix | 43 ++--- modules/dunst.nix | 51 +++--- modules/feh.nix | 13 +- modules/fish.nix | 15 +- modules/grub.nix | 7 +- modules/gtk.nix | 36 ++-- modules/helix.nix | 19 ++- modules/kitty.nix | 79 +++++---- modules/lightdm.nix | 8 +- modules/plymouth/default.nix | 7 +- modules/qutebrowser.nix | 323 ++++++++++++++++++----------------- modules/sway.nix | 127 +++++++------- modules/swaylock.nix | 69 ++++---- modules/vim.nix | 13 +- stylix/target.nix | 37 ++++ 18 files changed, 498 insertions(+), 385 deletions(-) create mode 100644 stylix/target.nix diff --git a/README.md b/README.md index 29626879..a0e2bcfc 100644 --- a/README.md +++ b/README.md @@ -91,3 +91,15 @@ a NixOS module; how to do this is shown in the example above. }; } ``` + +### Enabling and disabling module + +Each file in `modules/` corresponds to a single target, with the same name as +the file. A target is just something which can have styling applied to it. + +Each target has an option like `stylix.targets.«target».enable` to turn its +styling on or off. By default, styling is turned on automatically when the +target is installed. + +You can set `stylix.autoEnable = false` to opt out of this behaviour, in which +case you'll need to manually enable each target you want to be styled. diff --git a/flake.nix b/flake.nix index 5e3298d6..e79ea806 100644 --- a/flake.nix +++ b/flake.nix @@ -69,6 +69,7 @@ }) ./stylix/fonts.nix ./stylix/pixel.nix + ./stylix/target.nix ]; }; }; diff --git a/modules/alacritty.nix b/modules/alacritty.nix index 51794f1d..43892388 100644 --- a/modules/alacritty.nix +++ b/modules/alacritty.nix @@ -13,15 +13,20 @@ let }; in { - home-manager.sharedModules = [{ - programs.alacritty.settings = { - font = { - normal = { - family = monospace.name; - style = "Regular"; + options.stylix.targets.alacritty.enable = + config.lib.stylix.mkEnableTarget "Alacritty" true; + + config = lib.mkIf config.stylix.targets.alacritty.enable { + home-manager.sharedModules = [{ + programs.alacritty.settings = { + font = { + normal = { + family = monospace.name; + style = "Regular"; + }; }; + import = [ themeFile ]; }; - import = [ themeFile ]; - }; - }]; + }]; + }; } diff --git a/modules/console.nix b/modules/console.nix index e9f97d95..69229593 100644 --- a/modules/console.nix +++ b/modules/console.nix @@ -1,26 +1,27 @@ -{ config, ... }: +{ config, lib, ... }: with config.lib.stylix.colors; { - console = { - colors = [ - base00-hex - base08-hex - base0B-hex - base0A-hex - base0D-hex - base0E-hex - base0C-hex - base05-hex - base03-hex - base09-hex - base01-hex - base02-hex - base04-hex - base06-hex - base0F-hex - base07-hex - ]; - }; + options.stylix.targets.console.enable = + config.lib.stylix.mkEnableTarget "the Linux kernel console" true; + + config.console.colors = lib.mkIf config.stylix.targets.console.enable [ + base00-hex + base08-hex + base0B-hex + base0A-hex + base0D-hex + base0E-hex + base0C-hex + base05-hex + base03-hex + base09-hex + base01-hex + base02-hex + base04-hex + base06-hex + base0F-hex + base07-hex + ]; } diff --git a/modules/dunst.nix b/modules/dunst.nix index 063a3da8..ccd88655 100644 --- a/modules/dunst.nix +++ b/modules/dunst.nix @@ -1,33 +1,38 @@ -{ config, ... }: +{ config, lib, ... }: with config.lib.stylix.colors.withHashtag; with config.stylix.fonts; { - home-manager.sharedModules = [{ - services.dunst.settings = { - global = { - separator_color = base02; - font = sansSerif.name; - }; + options.stylix.targets.dunst.enable = + config.lib.stylix.mkEnableTarget "Dunst" true; - urgency_low = { - background = base01; - foreground = base05; - frame_color = base0B; - }; + config = lib.mkIf config.stylix.targets.dunst.enable { + home-manager.sharedModules = [{ + services.dunst.settings = { + global = { + separator_color = base02; + font = sansSerif.name; + }; - urgency_normal = { - background = base01; - foreground = base05; - frame_color = base0E; - }; + urgency_low = { + background = base01; + foreground = base05; + frame_color = base0B; + }; - urgency_critical = { - background = base01; - foreground = base05; - frame_color = base08; + urgency_normal = { + background = base01; + foreground = base05; + frame_color = base0E; + }; + + urgency_critical = { + background = base01; + foreground = base05; + frame_color = base08; + }; }; - }; - }]; + }]; + }; } diff --git a/modules/feh.nix b/modules/feh.nix index 40785765..63d351b5 100644 --- a/modules/feh.nix +++ b/modules/feh.nix @@ -1,11 +1,12 @@ { pkgs, config, lib, ... }: -with lib; +{ + options.stylix.targets.feh.enable = + config.lib.stylix.mkEnableTarget + "the desktop background using Feh" + (with config.services.xserver.windowManager; xmonad.enable || i3.enable); -with config.services.xserver.windowManager; -let enable = xmonad.enable || i3.enable; - -in { - services.xserver.displayManager.sessionCommands = mkIf enable + config.services.xserver.displayManager.sessionCommands = + lib.mkIf config.stylix.targets.feh.enable "${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.image}"; } diff --git a/modules/fish.nix b/modules/fish.nix index d9dd70dd..784b38b9 100644 --- a/modules/fish.nix +++ b/modules/fish.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ pkgs, config, lib, ... }: let theme = config.lib.stylix.colors { @@ -16,9 +16,14 @@ let ''; in { - programs.fish.promptInit = promptInit; + options.stylix.targets.fish.enable = + config.lib.stylix.mkEnableTarget "Fish" true; - home-manager.sharedModules = [{ - programs.fish.interactiveShellInit = promptInit; - }]; + config = lib.mkIf config.stylix.targets.fish.enable { + programs.fish.promptInit = promptInit; + + home-manager.sharedModules = [{ + programs.fish.interactiveShellInit = promptInit; + }]; + }; } diff --git a/modules/grub.nix b/modules/grub.nix index d8605936..e16537e8 100644 --- a/modules/grub.nix +++ b/modules/grub.nix @@ -1,4 +1,4 @@ -{ pkgs, config, ... }: +{ pkgs, config, lib, ... }: with config.lib.stylix; with config.stylix.fonts; @@ -23,7 +23,10 @@ let ''; in { - boot.loader.grub = { + options.stylix.targets.grub.enable = + config.lib.stylix.mkEnableTarget "GRUB" true; + + config.boot.loader.grub = lib.mkIf config.stylix.targets.grub.enable { backgroundColor = base00; # Need to override the NixOS splash, this will match the background splashImage = pixel "base00"; diff --git a/modules/gtk.nix b/modules/gtk.nix index fb7b6b96..11714313 100644 --- a/modules/gtk.nix +++ b/modules/gtk.nix @@ -140,21 +140,27 @@ let name = "Materia-compact"; }; -# GTK will probably be unused without Xorg / Wayland. -# There isn't a single option which covers all Wayload compositors, -# and many of them don't have NixOS modules at all. Therefore, we use -# OpenGL as the next best condition to detect that Wayland is enabled. -in lib.mkIf (config.services.xserver.enable || config.hardware.opengl.enable) { - # Required for Home Manager's GTK settings to work - programs.dconf.enable = true; +in { + options.stylix.targets.gtk.enable = + config.lib.stylix.mkEnableTarget "the GTK theme" + # GTK will probably be unused without Xorg / Wayland. + # There isn't a single option which covers all Wayload compositors, + # and many of them don't have NixOS modules at all. Therefore, we use + # OpenGL as the next best condition to detect that Wayland is enabled. + (config.services.xserver.enable || config.hardware.opengl.enable); - home-manager.sharedModules = [{ - gtk = { - enable = true; - inherit theme; - font = config.stylix.fonts.sansSerif; - }; - }]; + config = lib.mkIf config.stylix.targets.gtk.enable { + # Required for Home Manager's GTK settings to work + programs.dconf.enable = true; - services.xserver.displayManager.lightdm.greeters.gtk.theme = theme; + home-manager.sharedModules = [{ + gtk = { + enable = true; + inherit theme; + font = config.stylix.fonts.sansSerif; + }; + }]; + + services.xserver.displayManager.lightdm.greeters.gtk.theme = theme; + }; } diff --git a/modules/helix.nix b/modules/helix.nix index 82a34f19..20753d84 100644 --- a/modules/helix.nix +++ b/modules/helix.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, lib, ... }: with config.lib.stylix.colors.withHashtag; @@ -99,10 +99,15 @@ let theme = { }; in { - home-manager.sharedModules = [{ - programs.helix = { - settings.theme = "stylix"; - themes.stylix = theme; - }; - }]; + options.stylix.targets.helix.enable = + config.lib.stylix.mkEnableTarget "Helix" true; + + config = lib.mkIf config.stylix.targets.helix.enable { + home-manager.sharedModules = [{ + programs.helix = { + settings.theme = "stylix"; + themes.stylix = theme; + }; + }]; + }; } diff --git a/modules/kitty.nix b/modules/kitty.nix index 19857a46..192066c2 100644 --- a/modules/kitty.nix +++ b/modules/kitty.nix @@ -1,43 +1,48 @@ -{ config, ... }: +{ config, lib, ... }: { - home-manager.sharedModules = [{ - programs.kitty = { - font = config.stylix.fonts.monospace; + options.stylix.targets.kitty.enable = + config.lib.stylix.mkEnableTarget "Kitty" true; - settings = with config.lib.stylix.colors.withHashtag; { - # Based on https://github.com/kdrag0n/base16-kitty/ - active_border_color = base03; - active_tab_background = base00; - active_tab_foreground = base05; - background = base00; - cursor = base05; - foreground = base05; - inactive_border_color = base01; - inactive_tab_background = base01; - inactive_tab_foreground = base04; - selection_background = base05; - selection_foreground = base00; - tab_bar_background = base01; - url_color = base04; + config = lib.mkIf config.stylix.targets.kitty.enable { + home-manager.sharedModules = [{ + programs.kitty = { + font = config.stylix.fonts.monospace; - color0 = base00; - color1 = base08; - color2 = base0B; - color3 = base0A; - color4 = base0D; - color5 = base0E; - color6 = base0C; - color7 = base05; - color8 = base03; - color9 = base09; - color10 = base01; - color11 = base02; - color12 = base04; - color13 = base06; - color14 = base0F; - color15 = base07; + settings = with config.lib.stylix.colors.withHashtag; { + # Based on https://github.com/kdrag0n/base16-kitty/ + active_border_color = base03; + active_tab_background = base00; + active_tab_foreground = base05; + background = base00; + cursor = base05; + foreground = base05; + inactive_border_color = base01; + inactive_tab_background = base01; + inactive_tab_foreground = base04; + selection_background = base05; + selection_foreground = base00; + tab_bar_background = base01; + url_color = base04; + + color0 = base00; + color1 = base08; + color2 = base0B; + color3 = base0A; + color4 = base0D; + color5 = base0E; + color6 = base0C; + color7 = base05; + color8 = base03; + color9 = base09; + color10 = base01; + color11 = base02; + color12 = base04; + color13 = base06; + color14 = base0F; + color15 = base07; + }; }; - }; - }]; + }]; + }; } diff --git a/modules/lightdm.nix b/modules/lightdm.nix index 3cf693ed..d19a8da9 100644 --- a/modules/lightdm.nix +++ b/modules/lightdm.nix @@ -1,5 +1,9 @@ -{ config, ... }: +{ config, lib, ... }: { - services.xserver.displayManager.lightdm.background = config.stylix.image; + options.stylix.targets.lightdm.enable = + config.lib.stylix.mkEnableTarget "LightDM" true; + + config.services.xserver.displayManager.lightdm.background = + lib.mkIf config.stylix.targets.lightdm.enable config.stylix.image; } diff --git a/modules/plymouth/default.nix b/modules/plymouth/default.nix index 14245163..1207c82e 100644 --- a/modules/plymouth/default.nix +++ b/modules/plymouth/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, ... }: +{ config, pkgs, lib, ... }: with config.lib.stylix.colors; @@ -26,7 +26,10 @@ let ''; in { - boot.plymouth = { + options.stylix.targets.plymouth.enable = + config.lib.stylix.mkEnableTarget "the Plymouth boot screen" true; + + config.boot.plymouth = lib.mkIf config.stylix.targets.plymouth.enable { theme = "stylix"; themePackages = [ theme ]; }; diff --git a/modules/qutebrowser.nix b/modules/qutebrowser.nix index daae5410..e22c94ce 100644 --- a/modules/qutebrowser.nix +++ b/modules/qutebrowser.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, lib, ... }: with config.stylix.fonts; with config.lib.stylix.colors.withHashtag; @@ -15,160 +15,175 @@ let error = base08; in { - home-manager.sharedModules = [{ - programs.qutebrowser.settings = { - hints.border = background; - colors = { - completion = { - fg = foreground; - odd.bg = secondary-background; - even.bg = background; - match.fg = info; - category = { - fg = info; - bg = background; - border.top = background; - border.bottom = background; - }; - item.selected = { + options.stylix.targets.qutebrowser.enable = + config.lib.stylix.mkEnableTarget "Qutebrowser" true; + + config = lib.mkIf config.stylix.targets.qutebrowser.enable { + home-manager.sharedModules = [{ + programs.qutebrowser.settings = { + hints.border = background; + colors = { + completion = { fg = foreground; - bg = selection-background; - border.top = selection-background; - border.bottom = selection-background; + odd.bg = secondary-background; + even.bg = background; + match.fg = info; + category = { + fg = info; + bg = background; + border.top = background; + border.bottom = background; + }; + item.selected = { + fg = foreground; + bg = selection-background; + border.top = selection-background; + border.bottom = selection-background; + }; + scrollbar = { + fg = foreground; + bg = background; + }; }; - scrollbar = { - fg = foreground; - bg = background; + contextmenu = { + disabled = { + fg = inverted-foreground; + bg = secondary-background; + }; + menu = { + bg = background; + fg = foreground; + }; + selected = { + bg = selection-background; + fg = foreground; + }; }; - }; - contextmenu = { - disabled = { - fg = inverted-foreground; - bg = secondary-background; + downloads = { + bar.bg = background; + start = { + fg = inverted-foreground; + bg = info; + }; + stop = { + fg = inverted-foreground; + bg = secondary-info; + }; + error = { + fg = inverted-foreground; + bg = error; + }; }; - menu = { - bg = background; - fg = foreground; - }; - selected = { - bg = selection-background; - fg = foreground; - }; - }; - downloads = { - bar.bg = background; - start = { - fg = inverted-foreground; - bg = info; - }; - stop = { - fg = inverted-foreground; - bg = secondary-info; - }; - error = { - fg = inverted-foreground; - bg = error; - }; - }; - hints = { - fg = foreground; - bg = secondary-background; - match.fg = info; - }; - keyhint = { - fg = foreground; - bg = background; - suffix.fg = foreground; - }; - messages = { - error = { - fg = inverted-foreground; - bg = error; - border = error; - }; - warning = { - fg = inverted-foreground; - bg = warning; - border = warning; - }; - info = { - fg = inverted-foreground; - bg = info; - border = info; - }; - }; - prompts = { - fg = foreground; - bg = background; - border = background; - selected.bg = secondary-background; - }; - statusbar = { - normal = { - fg = foreground; - bg = background; - }; - insert = { - fg = inverted-foreground; - bg = info; - }; - passthrough = { - fg = inverted-foreground; - bg = secondary-info; - }; - private = { + hints = { fg = foreground; bg = secondary-background; + match.fg = info; }; - command = { + keyhint = { fg = foreground; bg = background; + suffix.fg = foreground; + }; + messages = { + error = { + fg = inverted-foreground; + bg = error; + border = error; + }; + warning = { + fg = inverted-foreground; + bg = warning; + border = warning; + }; + info = { + fg = inverted-foreground; + bg = info; + border = info; + }; + }; + prompts = { + fg = foreground; + bg = background; + border = background; + selected.bg = secondary-background; + }; + statusbar = { + normal = { + fg = foreground; + bg = background; + }; + insert = { + fg = inverted-foreground; + bg = info; + }; + passthrough = { + fg = inverted-foreground; + bg = secondary-info; + }; private = { fg = foreground; bg = secondary-background; }; - }; - caret = { - fg = foreground; - bg = selection-background; - selection = { + command = { + fg = foreground; + bg = background; + private = { + fg = foreground; + bg = secondary-background; + }; + }; + caret = { fg = foreground; bg = selection-background; + selection = { + fg = foreground; + bg = selection-background; + }; + }; + progress.bg = info; + url = { + fg = foreground; + error.fg = error; + hover.fg = foreground; + success.http.fg = secondary-info; + success.https.fg = info; + warn.fg = warning; }; }; - progress.bg = info; - url = { - fg = foreground; - error.fg = error; - hover.fg = foreground; - success.http.fg = secondary-info; - success.https.fg = info; - warn.fg = warning; - }; - }; - tabs = { - bar.bg = background; - indicator = { - start = secondary-info; - stop = info; - error = error; - }; - odd = { - fg = foreground; - bg = background; - }; - even = { - fg = foreground; - bg = secondary-background; - }; - pinned = { - even = { - fg = inverted-foreground; - bg = info; + tabs = { + bar.bg = background; + indicator = { + start = secondary-info; + stop = info; + error = error; }; odd = { - fg = inverted-foreground; - bg = secondary-info; + fg = foreground; + bg = background; + }; + even = { + fg = foreground; + bg = secondary-background; + }; + pinned = { + even = { + fg = inverted-foreground; + bg = info; + }; + odd = { + fg = inverted-foreground; + bg = secondary-info; + }; + selected = { + even = { + fg = foreground; + bg = selection-background; + }; + odd = { + fg = foreground; + bg = selection-background; + }; + }; }; selected = { even = { @@ -181,30 +196,20 @@ in { }; }; }; - selected = { - even = { - fg = foreground; - bg = selection-background; - }; - odd = { - fg = foreground; - bg = selection-background; - }; + }; + + fonts = { + default_family = sansSerif.name; + web.family = { + cursive = serif.name; + fantasy = serif.name; + fixed = monospace.name; + sans_serif = sansSerif.name; + serif = serif.name; + standard = sansSerif.name; }; }; }; - - fonts = { - default_family = sansSerif.name; - web.family = { - cursive = serif.name; - fantasy = serif.name; - fixed = monospace.name; - sans_serif = sansSerif.name; - serif = serif.name; - standard = sansSerif.name; - }; - }; - }; - }]; + }]; + }; } diff --git a/modules/sway.nix b/modules/sway.nix index 912a7891..8f1ea0e5 100644 --- a/modules/sway.nix +++ b/modules/sway.nix @@ -1,4 +1,4 @@ -{ config, ... }: +{ config, lib, ... }: with config.lib.stylix.colors.withHashtag; @@ -14,77 +14,82 @@ let }; in { - home-manager.sharedModules = [{ - wayland.windowManager.sway.config = { + options.stylix.targets.sway.enable = + config.lib.stylix.mkEnableTarget "Sway" true; + + config = { + home-manager.sharedModules = lib.mkIf config.stylix.targets.sway.enable [{ + wayland.windowManager.sway.config = { + inherit fonts; + + colors = let + background = base00; + indicator = base0B; + in { + inherit background; + urgent = { + inherit background indicator text; + border = urgent; + childBorder = urgent; + }; + focused = { + inherit background indicator text; + border = focused; + childBorder = focused; + }; + focusedInactive = { + inherit background indicator text; + border = unfocused; + childBorder = unfocused; + }; + unfocused = { + inherit background indicator text; + border = unfocused; + childBorder = unfocused; + }; + placeholder = { + inherit background indicator text; + border = unfocused; + childBorder = unfocused; + }; + }; + + output."*".bg = "${config.stylix.image} fill"; + }; + }]; + + # Merge this with your bar configuration using //config.lib.stylix.sway.bar + lib.stylix.sway.bar = { inherit fonts; colors = let - background = base00; - indicator = base0B; + background = base01; + border = background; in { inherit background; - urgent = { - inherit background indicator text; - border = urgent; - childBorder = urgent; + statusline = text; + separator = base03; + focusedWorkspace = { + inherit text border; + background = focused; }; - focused = { - inherit background indicator text; - border = focused; - childBorder = focused; + activeWorkspace = { + inherit text border; + background = unfocused; }; - focusedInactive = { - inherit background indicator text; - border = unfocused; - childBorder = unfocused; + inactiveWorkspace = { + inherit text border; + background = unfocused; }; - unfocused = { - inherit background indicator text; - border = unfocused; - childBorder = unfocused; + urgentWorkspace = { + inherit text border; + background = urgent; }; - placeholder = { - inherit background indicator text; - border = unfocused; - childBorder = unfocused; + bindingMode = { + inherit text border; + background = urgent; }; }; - - output."*".bg = "${config.stylix.image} fill"; - }; - }]; - - # Merge this with your bar configuration using //config.lib.stylix.sway.bar - lib.stylix.sway.bar = { - inherit fonts; - - colors = let - background = base01; - border = background; - in { - inherit background; - statusline = text; - separator = base03; - focusedWorkspace = { - inherit text border; - background = focused; - }; - activeWorkspace = { - inherit text border; - background = unfocused; - }; - inactiveWorkspace = { - inherit text border; - background = unfocused; - }; - urgentWorkspace = { - inherit text border; - background = urgent; - }; - bindingMode = { - inherit text border; - background = urgent; - }; }; }; } diff --git a/modules/swaylock.nix b/modules/swaylock.nix index 591f2f84..b2322e47 100644 --- a/modules/swaylock.nix +++ b/modules/swaylock.nix @@ -10,36 +10,41 @@ let negative = base08-hex; in { - home-manager.sharedModules = [( - { options, ... }: - { - # See https://github.com/danth/stylix/issues/8#issuecomment-1194484544 - # This check can be removed when programs.swaylock is in a stable release - programs.swaylock.settings = lib.mkIf (options.programs ? swaylock) { - image = config.stylix.image; - scaling = "fill"; - inside-color = inside; - inside-clear-color = inside; - inside-caps-lock-color = inside; - inside-ver-color = inside; - inside-wrong-color = inside; - key-hl-color = positive; - layout-bg-color = inside; - layout-border-color = ring; - layout-text-color = text; - line-uses-inside = true; - ring-color = ring; - ring-clear-color = negative; - ring-caps-lock-color = ring; - ring-ver-color = positive; - ring-wrong-color = negative; - separator-color = "00000000"; - text-color = text; - text-clear-color = text; - text-caps-lock-color = text; - text-ver-color = text; - text-wrong-color = text; - }; - } - )]; + options.stylix.targets.swaylock.enable = + config.lib.stylix.mkEnableTarget "Swaylock" true; + + config = lib.mkIf config.stylix.targets.swaylock.enable { + home-manager.sharedModules = [( + { options, ... }: + { + # See https://github.com/danth/stylix/issues/8#issuecomment-1194484544 + # This check can be removed when programs.swaylock is in a stable release + programs.swaylock.settings = lib.mkIf (options.programs ? swaylock) { + image = config.stylix.image; + scaling = "fill"; + inside-color = inside; + inside-clear-color = inside; + inside-caps-lock-color = inside; + inside-ver-color = inside; + inside-wrong-color = inside; + key-hl-color = positive; + layout-bg-color = inside; + layout-border-color = ring; + layout-text-color = text; + line-uses-inside = true; + ring-color = ring; + ring-clear-color = negative; + ring-caps-lock-color = ring; + ring-ver-color = positive; + ring-wrong-color = negative; + separator-color = "00000000"; + text-color = text; + text-clear-color = text; + text-caps-lock-color = text; + text-ver-color = text; + text-wrong-color = text; + }; + } + )]; + }; } diff --git a/modules/vim.nix b/modules/vim.nix index 01466134..d298d770 100644 --- a/modules/vim.nix +++ b/modules/vim.nix @@ -34,8 +34,13 @@ let }; in { - home-manager.sharedModules = [{ - programs.vim = vimOptions; - programs.neovim = vimOptions; - }]; + options.stylix.targets.vim.enable = + config.lib.stylix.mkEnableTarget "Vim and/or Neovim" true; + + config = lib.mkIf config.stylix.targets.vim.enable { + home-manager.sharedModules = [{ + programs.vim = vimOptions; + programs.neovim = vimOptions; + }]; + }; } diff --git a/stylix/target.nix b/stylix/target.nix new file mode 100644 index 00000000..7b63c3ec --- /dev/null +++ b/stylix/target.nix @@ -0,0 +1,37 @@ +{ config, lib, ... }@args: + +with lib; + +{ + options.stylix.autoEnable = mkOption { + description = "Whether to automatically enable styling for installed targets."; + type = types.bool; + default = true; + }; + + config.lib.stylix.mkEnableTarget = + humanName: + + # If the module only touches options under its target (programs.target.*) + # then this can simply be `true`, as those options are already gated by the + # upstream enable option. + # + # Otherwise, use `config` to check whether the target is enabled. + # + # If some manual setup is required, or the module leads to the target + # being installed if it wasn't already, set this to `false`. + autoEnable: + + mkOption { + description = "Whether to style ${humanName}."; + type = types.bool; + defaultText = '' + When stylix.autoEnable is true: + Enabled when ${humanName} is installed. + + When stylix.autoEnable is false: + Defaults to false. + ''; + default = config.stylix.autoEnable && autoEnable; + }; +}