Skip to content

Commit

Permalink
Create an enable option for each module ✨
Browse files Browse the repository at this point in the history
Fixes #7
  • Loading branch information
danth committed Jul 25, 2022
1 parent cd7b686 commit a1c4e81
Show file tree
Hide file tree
Showing 18 changed files with 495 additions and 382 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
1 change: 1 addition & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
})
./stylix/fonts.nix
./stylix/pixel.nix
./stylix/target.nix
];
};
};
Expand Down
23 changes: 14 additions & 9 deletions modules/alacritty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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 ];
};
}];
}];
};
}
43 changes: 22 additions & 21 deletions modules/console.nix
Original file line number Diff line number Diff line change
@@ -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
];
}
51 changes: 28 additions & 23 deletions modules/dunst.nix
Original file line number Diff line number Diff line change
@@ -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_normal = {
background = base01;
foreground = base05;
frame_color = base0E;
};

urgency_critical = {
background = base01;
foreground = base05;
frame_color = base08;
urgency_critical = {
background = base01;
foreground = base05;
frame_color = base08;
};
};
};
}];
}];
};
}
13 changes: 7 additions & 6 deletions modules/feh.nix
Original file line number Diff line number Diff line change
@@ -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}";
}
15 changes: 10 additions & 5 deletions modules/fish.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, config, ... }:
{ pkgs, config, lib, ... }:

let
theme = config.lib.stylix.colors {
Expand All @@ -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;
}];
};
}
7 changes: 5 additions & 2 deletions modules/grub.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs, config, ... }:
{ pkgs, config, lib, ... }:

with config.lib.stylix;
with config.stylix.fonts;
Expand All @@ -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";
Expand Down
38 changes: 22 additions & 16 deletions modules/gtk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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;

home-manager.sharedModules = [{
gtk = {
enable = true;
inherit theme;
font = config.stylix.fonts.sansSerif;
};
}];
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);

config = lib.mkIf config.stylix.targets.gtk.enable {
# Required for Home Manager's GTK settings to work
programs.dconf.enable = true;

home-manager.sharedModules = [{
gtk = {
enable = true;
inherit theme;
font = config.stylix.fonts.sansSerif;
};
}];

services.xserver.displayManager.lightdm.greeters.gtk.theme = theme;
services.xserver.displayManager.lightdm.greeters.gtk.theme = theme;
};
}
19 changes: 12 additions & 7 deletions modules/helix.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ config, ... }:
{ config, lib, ... }:

with config.lib.stylix.colors.withHashtag;

Expand Down Expand Up @@ -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;
};
}];
};
}
79 changes: 42 additions & 37 deletions modules/kitty.nix
Original file line number Diff line number Diff line change
@@ -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;
};
};
};
}];
}];
};
}
8 changes: 6 additions & 2 deletions modules/lightdm.nix
Original file line number Diff line number Diff line change
@@ -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;
}
Loading

0 comments on commit a1c4e81

Please sign in to comment.