Separate NixOS and home-manager code 🔀

This commit is contained in:
Daniel Thwaites 2023-02-13 19:53:16 +00:00 committed by GitHub
commit 7e2d318e6a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
52 changed files with 1131 additions and 862 deletions

124
README.md
View file

@ -1,46 +1,49 @@
# Stylix
Stylix is a NixOS module which applies the same color scheme, font and
wallpaper to a wide range of applications and desktop environments.
In some cases, theming can be activated as early as the bootloader!
It also exports utilities for you to apply the theming to custom parts of your
configuration.
wallpaper to a wide range of applications and desktop environments. It also
exports utilities for you to use the theme in custom parts of your configuration.
Stylix is built using [base16.nix](https://github.com/SenchoPens/base16.nix#readme),
a library which handles the generation of config files from templates provided by
the [base16](https://github.com/chriskempson/base16#readme) project.
a library which processes themes created for
[base16](https://github.com/chriskempson/base16#readme) or
[Tinted Theming](https://github.com/tinted-theming).
## Installation
You can install Stylix using [Flakes](https://nixos.wiki/wiki/Flakes),
for example:
You can install Stylix into your NixOS configuration using
[Flakes](https://nixos.wiki/wiki/Flakes), for example:
```nix
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
home-manager = {
url = "github:nix-community/home-manager";
inputs.nixpkgs.follows = "nixpkgs";
};
stylix.url = "github:danth/stylix";
};
outputs = { self, nixpkgs, home-manager, stylix }: {
nixosConfigurations."<hostname>" = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
home-manager.nixosModules.home-manager
stylix.nixosModules.stylix
];
modules = [ stylix.nixosModules.stylix ];
};
};
}
```
Stylix relies on [Home Manager](https://github.com/nix-community/home-manager)
for a lot of its work, so that needs to be imported too.
If [Home Manager](https://github.com/nix-community/home-manager) is available,
Stylix will use it to configure apps which don't support system wide settings.
The majority of apps are that way, so
[setting up Home Manager as a NixOS module](https://nix-community.github.io/home-manager/index.html#sec-install-nixos-module)
is highly recommended if you don't use it already.
If you prefer using Home Manager separately from NixOS, you can import
`homeManagerModules.stylix` into your Home Manager configuration instead. In
this case, you will need to copy the settings described later into both your
NixOS and Home Manager configurations, as they will not be able to follow each
other automatically.
It's also possible to use either NixOS or Home Manager without the other,
however that would make some features unavailable.
## Wallpaper
@ -60,48 +63,36 @@ stylix.image = pkgs.fetchurl {
};
```
The wallpaper is the only option which is required!
At this point you should be able to rebuild and have a reasonable theme
generated based on the image you chose.
## Color scheme
### Automatic color schemes
If you only set a wallpaper, Stylix will use a
[genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm)
to choose a color scheme based on it. The quality of these automatically
generated schemes can vary, but more colorful images tend to have better
results.
If you only set a wallpaper, Stylix will use a [genetic
algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm) to generate a color
scheme. The quality of these automatically generated schemes can vary, but more
colorful images tend to have better results.
You can force a light or dark theme using the polarity option:
You can force the generation of a light or dark theme using the polarity
option:
```nix
stylix.polarity = "dark";
```
The generated scheme can be viewed in a web browser at
`file:///etc/stylix/palette.html`.
### Mixed color schemes
You can override part of the scheme by hand, perhaps to select background
and text colors manually while keeping the generated accent colors:
```nix
stylix.palette = {
base00 = "000000";
# ...
base07 = "ffffff";
};
```
The `baseXX` names correspond to
[this table](https://github.com/chriskempson/base16/blob/main/styling.md#styling-guidelines).
After rebuilding, the full theme can be previewed at
`file:///etc/stylix/palette.html` in a web browser.
### Manual color schemes
Alternatively, you can choose a pre-made colorscheme from
[the Tinted Theming repository](https://github.com/tinted-theming/base16-schemes).
Either add the repository to your Flake inputs, or fetch it as follows:
If you would prefer to choose a theme, you can use anything from
[the Tinted Theming repository](https://github.com/tinted-theming/base16-schemes),
or another file following that format.
To use Tinted Theming, either add their repository to your Flake inputs, or
fetch it as follows:
```nix
let base16-schemes = pkgs.fetchFromGitHub {
@ -112,16 +103,14 @@ let base16-schemes = pkgs.fetchFromGitHub {
};
```
Then you can choose which file you would like to use:
Then set the following option to the path of the theme you would like to use:
```nix
stylix.base16Scheme = "${base16-schemes}/gruvbox-dark-hard.yaml";
```
If you want to do anything more complex - such as running your own program to
generate the colour scheme - `base16Scheme` can accept any argument which
[`mkSchemeAttrs`](https://github.com/SenchoPens/base16.nix/blob/main/DOCUMENTATION.md#mkschemeattrs)
supports.
`base16Scheme` can also accept other formats as supported by
[`mkSchemeAttrs`](https://github.com/SenchoPens/base16.nix/blob/main/DOCUMENTATION.md#mkschemeattrs).
## Fonts
@ -153,13 +142,14 @@ stylix.fonts = {
These can be changed as you like.
To make things more uniform, you can replace the serif font with sans-serif:
To make things look more uniform, you could replace the serif font with
the sans-serif font:
```nix
stylix.fonts.serif = config.stylix.fonts.sansSerif;
```
Or even use monospace for everything:
Or even choose monospace for everything:
```nix
stylix.fonts = {
@ -169,6 +159,29 @@ stylix.fonts = {
};
```
## Multi-user configurations
For those apps which are configured through Home Manager, Stylix allows you to
choose a different theme for each user. This can be done by setting the theme
within Home Manager for that user rather than at the system level.
By default, all users follow the system theme. This can be turned off by
setting `stylix.homeManagerIntegration.followSystem = false`, in which case you
must explicitly set a theme for each user. Setting that option is not required
just to be able to override an individual theme.
If you would like to disable all Home Manager activity for a user, you can set
`stylix.homeManagerIntegration.autoImport = false`, then manually import the
Home Manager module for the users for which it should be enabled.
Note that if the wallpaper image for a user is different to the rest of the
system, a separate theme will always be generated for them, even though their
`base16Scheme` option has not been overridden. If you want that user to follow
the system theme while having a different wallpaper, you will need to manually
copy the system theme into their configuration. (This behaviour is necessary as
otherwise it would be impossible to use a generated theme for a user while
having a manually created theme for the rest of the system.)
## Turning targets on and off
In Stylix terms, a target is anything which can have colors, fonts or a
@ -180,3 +193,6 @@ styling on or off. Normally, it's 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.
Targets are different between Home Manager and NixOS, and sometimes available
in both cases. If both are available, it is always correct to enable both.

View file

@ -9,7 +9,8 @@
<h1>Stylix</h1>
<nav>
<a href="">Home</a>
<a href="options.html">Options list</a>
<a href="options.html">NixOS options</a>
<a href="options-hm.html">Home Manager options</a>
<a href="haddock/doc-index.html">Haskell internals</a>
<a href="https://github.com/danth/stylix">GitHub repository</a>
</nav>
@ -25,22 +26,52 @@
tail -n+2 ${../README.md} >$out
'';
}
{
path = "options.html";
title = "NixOS Options";
title = "NixOS options";
body.docbook =
let
nixosSystem = pkgsLib.nixosSystem {
configuration = pkgsLib.nixosSystem {
inherit (pkgs) system;
modules = [
inputs.home-manager.nixosModules.home-manager
inputs.self.nixosModules.stylix
./settings.nix
{ _module.check = false; }
];
};
in
coricamuLib.makeOptionsDocBook {
inherit (nixosSystem) options;
inherit (configuration) options;
customFilter = option: builtins.elemAt option.loc 0 == "stylix";
};
}
{
path = "options-hm.html";
title = "Home Manager options";
body.docbook =
let
configuration = inputs.home-manager.lib.homeManagerConfiguration {
inherit pkgs;
modules = [
inputs.self.homeManagerModules.stylix
./settings.nix
{
home = {
homeDirectory = "/home/docs";
stateVersion = "22.11";
username = "docs";
};
}
];
check = false;
};
in
coricamuLib.makeOptionsDocBook {
inherit (configuration) options;
customFilter = option: builtins.elemAt option.loc 0 == "stylix";
};
}

26
docs/settings.nix Normal file
View file

@ -0,0 +1,26 @@
# Dummy values to avoid errors when generating the documentation.
{
stylix = {
image = "/a/b/c";
base16Scheme = {
base00 = "ffffff";
base01 = "ffffff";
base02 = "ffffff";
base03 = "ffffff";
base04 = "ffffff";
base05 = "ffffff";
base06 = "ffffff";
base07 = "ffffff";
base08 = "ffffff";
base09 = "ffffff";
base0A = "ffffff";
base0B = "ffffff";
base0C = "ffffff";
base0D = "ffffff";
base0E = "ffffff";
base0F = "ffffff";
};
};
}

View file

@ -59,36 +59,20 @@
nixosModules.stylix = { pkgs, ... }@args: {
imports = [
./modules/alacritty.nix
./modules/bemenu.nix
./modules/chromium.nix
./modules/console.nix
./modules/dunst.nix
./modules/feh.nix
./modules/fish.nix
./modules/gedit
./modules/gnome
./modules/grub.nix
./modules/gtk
./modules/helix.nix
./modules/i3.nix
./modules/k9s.nix
./modules/kitty.nix
./modules/lightdm.nix
./modules/mako.nix
./modules/plymouth
./modules/qutebrowser.nix
./modules/sway.nix
./modules/swaylock.nix
./modules/vim.nix
./modules/vscode/default.nix
(import ./stylix/palette.nix {
(import ./stylix/nixos {
inherit (self.packages.${pkgs.system}) palette-generator;
base16 = base16.lib args;
homeManagerModule = self.homeManagerModules.stylix;
})
];
};
homeManagerModules.stylix = { pkgs, ... }@args: {
imports = [
(import ./stylix/hm {
inherit (self.packages.${pkgs.system}) palette-generator;
base16 = base16.lib args;
})
./stylix/fonts.nix
./stylix/pixel.nix
./stylix/target.nix
];
};
};

View file

@ -17,16 +17,14 @@ in
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";
};
programs.alacritty.settings = {
font = {
normal = {
family = monospace.name;
style = "Regular";
};
import = [ themeFile ];
};
}];
import = [ themeFile ];
};
};
}

View file

@ -12,7 +12,7 @@ with config.stylix.fonts;
alternate = lib.mkOption { type = lib.types.bool; default = false; };
};
config.home-manager.sharedModules = lib.mkIf config.stylix.targets.bemenu.enable [{
config = lib.mkIf config.stylix.targets.bemenu.enable {
home.sessionVariables.BEMENU_OPTS = with config.stylix.targets.bemenu; builtins.concatStringsSep " " [
# Inspired from https://git.sr.ht/~h4n1/base16-bemenu_opts
"--tb '${base01}'"
@ -33,5 +33,5 @@ with config.stylix.fonts;
"--fn '${sansSerif.name} ${lib.optionalString (fontSize != null) (builtins.toString fontSize)}'"
];
}];
};
}

View file

@ -1,38 +0,0 @@
{ config, lib, ... }:
with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
{
options.stylix.targets.dunst.enable =
config.lib.stylix.mkEnableTarget "Dunst" true;
config = lib.mkIf config.stylix.targets.dunst.enable {
home-manager.sharedModules = [{
services.dunst.settings = {
global = {
separator_color = base02;
font = sansSerif.name;
};
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;
};
};
}];
};
}

36
modules/dunst/hm.nix Normal file
View file

@ -0,0 +1,36 @@
{ config, lib, ... }:
with config.lib.stylix.colors.withHashtag;
with config.stylix.fonts;
{
options.stylix.targets.dunst.enable =
config.lib.stylix.mkEnableTarget "Dunst" true;
config = lib.mkIf config.stylix.targets.dunst.enable {
services.dunst.settings = {
global = {
separator_color = base02;
font = sansSerif.name;
};
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;
};
};
};
}

16
modules/feh/hm.nix Normal file
View file

@ -0,0 +1,16 @@
{ pkgs, config, lib, ... }:
{
options.stylix.targets.feh.enable =
config.lib.stylix.mkEnableTarget
"the desktop background using Feh"
(with config.xsession.windowManager; bspwm.enable
|| herbsflutwm.enable
|| i3.enable
|| spectrwm.enable
|| xmonad.enable);
config.xsession.initExtra =
lib.mkIf config.stylix.targets.feh.enable
"${pkgs.feh}/bin/feh --no-fehbg --bg-scale ${config.stylix.image}";
}

View file

@ -1,29 +0,0 @@
{ pkgs, config, lib, ... }:
let
theme = config.lib.stylix.colors {
templateRepo = pkgs.fetchFromGitHub {
owner = "tomyun";
repo = "base16-fish";
rev = "7f647967fddedaf803191bc9113b13d2071dc3cf";
sha256 = "IGUbLjsmmAvB9UKGkR7oqdpjeVEfzt83GpyBkrZf2O4=";
};
};
promptInit = ''
source ${theme}
base16-${config.lib.stylix.colors.slug}
'';
in {
options.stylix.targets.fish.enable =
config.lib.stylix.mkEnableTarget "Fish" true;
config = lib.mkIf config.stylix.targets.fish.enable {
programs.fish.promptInit = promptInit;
home-manager.sharedModules = [{
programs.fish.interactiveShellInit = promptInit;
}];
};
}

10
modules/fish/hm.nix Normal file
View file

@ -0,0 +1,10 @@
{ pkgs, config, lib, ... }:
{
options.stylix.targets.fish.enable =
config.lib.stylix.mkEnableTarget "Fish" true;
config = lib.mkIf config.stylix.targets.fish.enable {
programs.fish.interactiveShellInit = import ./prompt.nix { inherit pkgs config; };
};
}

10
modules/fish/nixos.nix Normal file
View file

@ -0,0 +1,10 @@
{ pkgs, config, lib, ... }:
{
options.stylix.targets.fish.enable =
config.lib.stylix.mkEnableTarget "Fish" true;
config = lib.mkIf config.stylix.targets.fish.enable {
programs.fish.promptInit = import ./prompt.nix { inherit pkgs config; };
};
}

15
modules/fish/prompt.nix Normal file
View file

@ -0,0 +1,15 @@
{ pkgs, config }:
let
theme = config.lib.stylix.colors {
templateRepo = pkgs.fetchFromGitHub {
owner = "tomyun";
repo = "base16-fish";
rev = "7f647967fddedaf803191bc9113b13d2071dc3cf";
sha256 = "IGUbLjsmmAvB9UKGkR7oqdpjeVEfzt83GpyBkrZf2O4=";
};
};
in ''
source ${theme}
base16-${config.lib.stylix.colors.slug}
''

View file

@ -11,10 +11,8 @@ in {
config.lib.stylix.mkEnableTarget "GEdit" true;
config = lib.mkIf config.stylix.targets.gedit.enable {
home-manager.sharedModules = [{
xdg.dataFile = {
"gedit/styles/stylix.xml".source = style;
};
}];
xdg.dataFile = {
"gedit/styles/stylix.xml".source = style;
};
};
}

View file

@ -1,56 +0,0 @@
{ pkgs, config, lib, ... }:
with lib;
{
options.stylix.targets.gnome.enable =
config.lib.stylix.mkEnableTarget "GNOME" config.services.xserver.desktopManager.gnome.enable;
config = mkIf config.stylix.targets.gnome.enable {
home-manager.sharedModules = [({ lib, ... }: {
dconf.settings = {
"org/gnome/desktop/background" = {
color-shading-type = "solid";
picture-options = "zoom";
picture-uri = "file://${config.stylix.image}";
picture-uri-dark = "file://${config.stylix.image}";
};
# We show the same colours regardless of this setting, and the quick
# settings tile is removed. The value is still used by Epiphany to
# request dark mode for websites which support it.
"org/gnome/desktop/interface".color-scheme =
if config.stylix.polarity == "dark"
then "prefer-dark"
else "default";
};
})];
# As Stylix is controlling the wallpaper, there is no need for this
# pack of default wallpapers to be installed.
# If you want to use one, you can set stylix.image to something like
# "${pkgs.gnome.gnome-backgrounds}/path/to/your/preferred/background"
# which will then download the pack regardless of its exclusion below.
environment.gnome.excludePackages = [ pkgs.gnome.gnome-backgrounds ];
nixpkgs.overlays = [(self: super: {
gnome = super.gnome.overrideScope' (gnomeSelf: gnomeSuper: {
gnome-shell = gnomeSuper.gnome-shell.overrideAttrs (oldAttrs: {
postPatch = let
colors = config.lib.stylix.colors {
template = builtins.readFile ./colors.mustache;
extension = "scss";
};
in (oldAttrs.postPatch or "") + ''
rm data/theme/gnome-shell-sass/{_colors.scss,_palette.scss}
cp ${colors} data/theme/gnome-shell-sass/_colors.scss
'';
patches = (oldAttrs.patches or []) ++ [
./shell_colors.patch
./shell_remove_dark_mode.patch
];
});
});
})];
};
}

41
modules/gnome/hm.nix Normal file
View file

@ -0,0 +1,41 @@
{ pkgs, config, lib, ... }:
with lib;
{
options.stylix.targets.gnome.enable =
config.lib.stylix.mkEnableTarget "GNOME" true;
config = mkIf config.stylix.targets.gnome.enable {
dconf.settings = {
"org/gnome/desktop/background" = {
color-shading-type = "solid";
picture-options = "zoom";
picture-uri = "file://${config.stylix.image}";
picture-uri-dark = "file://${config.stylix.image}";
};
# We show the same colours regardless of this setting, and the quick
# settings tile is removed. The value is still used by Epiphany to
# request dark mode for websites which support it.
"org/gnome/desktop/interface".color-scheme =
if config.stylix.polarity == "dark"
then "prefer-dark"
else "default";
"org/gnome/shell/extensions/user-theme".name = "Stylix";
};
xdg.dataFile."themes/Stylix/gnome-shell/gnome-shell.css" = {
source =
let theme = import ./theme.nix { inherit pkgs config; };
in "${theme}/share/gnome-shell/gnome-shell.css";
onChange = ''
if [ -x "$(command -v gnome-extensions)" ]; then
gnome-extensions disable user-theme@gnome-shell-extensions.gcampax.github.com
gnome-extensions enable user-theme@gnome-shell-extensions.gcampax.github.com
fi
'';
};
};
}

33
modules/gnome/nixos.nix Normal file
View file

@ -0,0 +1,33 @@
{ pkgs, config, lib, ... }:
with lib;
{
options.stylix.targets.gnome.enable =
config.lib.stylix.mkEnableTarget "GNOME" config.services.xserver.desktopManager.gnome.enable;
config = mkIf config.stylix.targets.gnome.enable {
# As Stylix is controlling the wallpaper, there is no need for this
# pack of default wallpapers to be installed.
# If you want to use one, you can set stylix.image to something like
# "${pkgs.gnome.gnome-backgrounds}/path/to/your/preferred/background"
# which will then download the pack regardless of its exclusion below.
environment.gnome.excludePackages = [ pkgs.gnome.gnome-backgrounds ];
nixpkgs.overlays = [(self: super: {
gnome = super.gnome.overrideScope' (gnomeSelf: gnomeSuper: {
gnome-shell = gnomeSuper.gnome-shell.overrideAttrs (oldAttrs: {
postFixup =
let theme = import ./theme.nix { inherit pkgs config; };
in ''
cp ${theme}/share/gnome-shell/gnome-shell-theme.gresource \
$out/share/gnome-shell/gnome-shell-theme.gresource
'';
patches = (oldAttrs.patches or []) ++ [
./shell_remove_dark_mode.patch
];
});
});
})];
};
}

34
modules/gnome/theme.nix Normal file
View file

@ -0,0 +1,34 @@
{ pkgs, config }:
let
colors = config.lib.stylix.colors {
template = builtins.readFile ./colors.mustache;
extension = "scss";
};
in pkgs.stdenv.mkDerivation {
name = "stylix-gnome-shell-theme";
src = pkgs.fetchurl {
url = "mirror://gnome/sources/gnome-shell/43/gnome-shell-43.2.tar.xz";
sha256 = "52/UvpNCQQ7p+9zday2Bxv8GDnyMxaDxyuanq6JdGGA=";
};
patches = [ ./shell_colors.patch ];
postPatch = ''
rm data/theme/gnome-shell-sass/{_colors.scss,_palette.scss}
cp ${colors} data/theme/gnome-shell-sass/_colors.scss
'';
nativeBuildInputs = with pkgs; [ sass glib.dev ];
buildPhase = ''
sass data/theme/gnome-shell.scss >data/theme/gnome-shell.css
glib-compile-resources --sourcedir=data/theme data/gnome-shell-theme.gresource.xml
'';
installPhase = ''
mkdir -p $out/share/gnome-shell
mv data/theme/gnome-shell.css $out/share/gnome-shell/gnome-shell.css
mv data/gnome-shell-theme.gresource $out/share/gnome-shell/gnome-shell-theme.gresource
'';
}

View file

@ -1,33 +0,0 @@
{ pkgs, config, lib, ... }:
let
css = config.lib.stylix.colors {
template = builtins.readFile ./gtk.mustache;
extension = "css";
};
in {
options.stylix.targets.gtk.enable =
config.lib.stylix.mkEnableTarget "all GTK3, GTK4 and Libadwaita apps" true;
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;
font = config.stylix.fonts.sansSerif;
theme = {
package = pkgs.adw-gtk3;
name = "adw-gtk3";
};
};
xdg.configFile = {
"gtk-3.0/gtk.css".source = css;
"gtk-4.0/gtk.css".source = css;
};
}];
};
}

29
modules/gtk/hm.nix Normal file
View file

@ -0,0 +1,29 @@
{ pkgs, config, lib, ... }:
let
css = config.lib.stylix.colors {
template = builtins.readFile ./gtk.mustache;
extension = "css";
};
in {
options.stylix.targets.gtk.enable =
config.lib.stylix.mkEnableTarget "all GTK3, GTK4 and Libadwaita apps" true;
config = lib.mkIf config.stylix.targets.gtk.enable {
# programs.dconf.enable = true; required in system config
gtk = {
enable = true;
font = config.stylix.fonts.sansSerif;
theme = {
package = pkgs.adw-gtk3;
name = "adw-gtk3";
};
};
xdg.configFile = {
"gtk-3.0/gtk.css".source = css;
"gtk-4.0/gtk.css".source = css;
};
};
}

11
modules/gtk/nixos.nix Normal file
View file

@ -0,0 +1,11 @@
{ pkgs, config, lib, ... }:
{
options.stylix.targets.gtk.enable =
config.lib.stylix.mkEnableTarget "all GTK3, GTK4 and Libadwaita apps" true;
config = lib.mkIf config.stylix.targets.gtk.enable {
# Required for Home Manager's GTK settings to work
programs.dconf.enable = true;
};
}

View file

@ -103,11 +103,9 @@ in {
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;
};
}];
programs.helix = {
settings.theme = "stylix";
themes.stylix = theme;
};
};
}

View file

@ -16,8 +16,8 @@ in {
options.stylix.targets.i3.enable =
config.lib.stylix.mkEnableTarget "i3" true;
config = {
home-manager.sharedModules = lib.mkIf config.stylix.targets.i3.enable [{
config = lib.mkMerge [
(lib.mkIf config.stylix.targets.i3.enable {
xsession.windowManager.i3.config = {
inherit fonts;
@ -55,39 +55,41 @@ in {
# output."*".bg = "${config.stylix.image} fill";
};
}];
})
# Merge this with your bar configuration using //config.lib.stylix.i3.bar
lib.stylix.i3.bar = {
inherit fonts;
{
# Merge this with your bar configuration using //config.lib.stylix.i3.bar
lib.stylix.i3.bar = {
inherit fonts;
colors = let
background = base00;
border = background;
in {
inherit background;
statusline = text;
separator = base03;
focusedWorkspace = {
inherit text background;
border = focused;
};
activeWorkspace = {
inherit border background;
text = focused;
};
inactiveWorkspace = {
inherit text border background;
};
urgentWorkspace = {
inherit text background;
border = urgent;
};
bindingMode = {
inherit text border;
background = urgent;
colors = let
background = base00;
border = background;
in {
inherit background;
statusline = text;
separator = base03;
focusedWorkspace = {
inherit text background;
border = focused;
};
activeWorkspace = {
inherit border background;
text = focused;
};
inactiveWorkspace = {
inherit text border background;
};
urgentWorkspace = {
inherit text background;
border = urgent;
};
bindingMode = {
inherit text border;
background = urgent;
};
};
};
};
};
}
];
}

View file

@ -1,129 +0,0 @@
{ pkgs, config, lib, ... }:
with config.lib.stylix.colors.withHashtag;
{
options.stylix.targets.k9s.enable =
config.lib.stylix.mkEnableTarget "k9s" true;
config = lib.mkIf config.stylix.targets.k9s.enable {
home-manager.sharedModules = [{
programs.k9s.skin = {
k9s = {
body = {
fgColor = base05-hex;
bgColor = "default";
logoColor = base0C-hex;
};
prompt = {
fgColor = base05-hex;
bgColor = base00-hex;
suggestColor = base0A-hex;
};
info = {
fgColor = base0B-hex;
sectionColor = base05-hex;
};
dialog = {
fgColor = base05-hex;
bgColor = "default";
buttonFgColor = base05-hex;
buttonBgColor = base0C-hex;
buttonFocusFgColor = base0E-hex;
buttonFocusBgColor = base0B-hex;
labelFgColor = base0A-hex;
fieldFgColor = base05-hex;
};
frame = {
border = {
fgColor = base02-hex;
focusColor = base01-hex;
};
menu = {
fgColor = base05-hex;
keyColor = base0B-hex;
numKeyColor = base0B-hex;
};
crumbs = {
fgColor = base05-hex;
bgColor = base01-hex;
activeColor = base01-hex;
};
status = {
newColor = base08-hex;
modifyColor = base0C-hex;
addColor = base09-hex;
errorColor = base0D-hex;
highlightcolor = base0A-hex;
killColor = base03-hex;
completedColor = base03-hex;
};
title = {
fgColor = base05-hex;
bgColor = base01-hex;
highlightColor = base0A-hex;
counterColor = base0C-hex;
filterColor = base0B-hex;
};
};
views = {
charts = {
bgColor = "default";
defaultDialColors = [ base0C-hex base0D-hex ];
defaultChartColors = [ base0C-hex base0D-hex ];
};
table = {
fgColor = base05-hex;
bgColor = "default";
header = {
fgColor = base05-hex;
bgColor = "default";
sorterColor = base08-hex;
};
};
xray = {
fgColor = base05-hex;
bgColor = "default";
cursorColor = base01-hex;
graphicColor = base0C-hex;
showIcons = false;
};
yaml = {
keyColor = base0B-hex;
colonColor = base0C-hex;
valueColor = base05-hex;
};
logs = {
fgColor = base05-hex;
bgColor = "default";
indicator = {
fgColor = base05-hex;
bgColor = base0C-hex;
};
};
help = {
fgColor = base05-hex;
bgColor = base00-hex;
indicator.fgColor = base0D-hex;
};
};
};
};
}];
};
}

126
modules/k9s/hm.nix Normal file
View file

@ -0,0 +1,126 @@
{ pkgs, config, lib, ... }:
with config.lib.stylix.colors.withHashtag;
{
options.stylix.targets.k9s.enable =
config.lib.stylix.mkEnableTarget "k9s" true;
config = lib.mkIf config.stylix.targets.k9s.enable {
programs.k9s.skin = {
k9s = {
body = {
fgColor = base05-hex;
bgColor = "default";
logoColor = base0C-hex;
};
prompt = {
fgColor = base05-hex;
bgColor = base00-hex;
suggestColor = base0A-hex;
};
info = {
fgColor = base0B-hex;
sectionColor = base05-hex;
};
dialog = {
fgColor = base05-hex;
bgColor = "default";
buttonFgColor = base05-hex;
buttonBgColor = base0C-hex;
buttonFocusFgColor = base0E-hex;
buttonFocusBgColor = base0B-hex;
labelFgColor = base0A-hex;
fieldFgColor = base05-hex;
};
frame = {
border = {
fgColor = base02-hex;
focusColor = base01-hex;
};
menu = {
fgColor = base05-hex;
keyColor = base0B-hex;
numKeyColor = base0B-hex;
};
crumbs = {
fgColor = base05-hex;
bgColor = base01-hex;
activeColor = base01-hex;
};
status = {
newColor = base08-hex;
modifyColor = base0C-hex;
addColor = base09-hex;
errorColor = base0D-hex;
highlightcolor = base0A-hex;
killColor = base03-hex;
completedColor = base03-hex;
};
title = {
fgColor = base05-hex;
bgColor = base01-hex;
highlightColor = base0A-hex;
counterColor = base0C-hex;
filterColor = base0B-hex;
};
};
views = {
charts = {
bgColor = "default";
defaultDialColors = [ base0C-hex base0D-hex ];
defaultChartColors = [ base0C-hex base0D-hex ];
};
table = {
fgColor = base05-hex;
bgColor = "default";
header = {
fgColor = base05-hex;
bgColor = "default";
sorterColor = base08-hex;
};
};
xray = {
fgColor = base05-hex;
bgColor = "default";
cursorColor = base01-hex;
graphicColor = base0C-hex;
showIcons = false;
};
yaml = {
keyColor = base0B-hex;
colonColor = base0C-hex;
valueColor = base05-hex;
};
logs = {
fgColor = base05-hex;
bgColor = "default";
indicator = {
fgColor = base05-hex;
bgColor = base0C-hex;
};
};
help = {
fgColor = base05-hex;
bgColor = base00-hex;
indicator.fgColor = base0D-hex;
};
};
};
};
};
}

View file

@ -1,48 +0,0 @@
{ config, lib, ... }:
{
options.stylix.targets.kitty.enable =
config.lib.stylix.mkEnableTarget "Kitty" true;
config = lib.mkIf config.stylix.targets.kitty.enable {
home-manager.sharedModules = [{
programs.kitty = {
font = config.stylix.fonts.monospace;
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;
};
};
}];
};
}

46
modules/kitty/hm.nix Normal file
View file

@ -0,0 +1,46 @@
{ config, lib, ... }:
{
options.stylix.targets.kitty.enable =
config.lib.stylix.mkEnableTarget "Kitty" true;
config = lib.mkIf config.stylix.targets.kitty.enable {
programs.kitty = {
font = config.stylix.fonts.monospace;
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;
};
};
};
}

View file

@ -7,7 +7,7 @@ with config.stylix.fonts;
config.lib.stylix.mkEnableTarget "Mako" true;
# Referenced https://github.com/stacyharper/base16-mako
config.home-manager.sharedModules = lib.mkIf config.stylix.targets.mako.enable [{
config = lib.mkIf config.stylix.targets.mako.enable {
programs.mako = {
backgroundColor = base00;
borderColor = base0D;
@ -27,5 +27,5 @@ with config.stylix.fonts;
text-color=${base08}
'';
};
}];
};
}

View file

@ -1,215 +0,0 @@
{ config, lib, ... }:
with config.stylix.fonts;
with config.lib.stylix.colors.withHashtag;
let
background = base00;
secondary-background = base01;
selection-background = base03;
foreground = base05;
inverted-foreground = base00;
info = base0B;
secondary-info = base0C;
warning = base0E;
error = base08;
in {
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;
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;
};
};
contextmenu = {
disabled = {
fg = inverted-foreground;
bg = secondary-background;
};
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 = {
fg = foreground;
bg = secondary-background;
};
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;
};
};
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;
};
odd = {
fg = inverted-foreground;
bg = secondary-info;
};
selected = {
even = {
fg = foreground;
bg = selection-background;
};
odd = {
fg = foreground;
bg = selection-background;
};
};
};
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;
};
};
};
}];
};
}

213
modules/qutebrowser/hm.nix Normal file
View file

@ -0,0 +1,213 @@
{ config, lib, ... }:
with config.stylix.fonts;
with config.lib.stylix.colors.withHashtag;
let
background = base00;
secondary-background = base01;
selection-background = base03;
foreground = base05;
inverted-foreground = base00;
info = base0B;
secondary-info = base0C;
warning = base0E;
error = base08;
in {
options.stylix.targets.qutebrowser.enable =
config.lib.stylix.mkEnableTarget "Qutebrowser" true;
config = lib.mkIf config.stylix.targets.qutebrowser.enable {
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 = {
fg = foreground;
bg = selection-background;
border.top = selection-background;
border.bottom = selection-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;
};
};
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 = {
fg = foreground;
bg = secondary-background;
};
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;
};
};
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;
};
odd = {
fg = inverted-foreground;
bg = secondary-info;
};
selected = {
even = {
fg = foreground;
bg = selection-background;
};
odd = {
fg = foreground;
bg = selection-background;
};
};
};
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;
};
};
};
};
}

View file

@ -17,8 +17,8 @@ in {
options.stylix.targets.sway.enable =
config.lib.stylix.mkEnableTarget "Sway" true;
config = {
home-manager.sharedModules = lib.mkIf config.stylix.targets.sway.enable [{
config = lib.mkMerge [
(lib.mkIf config.stylix.targets.sway.enable {
wayland.windowManager.sway.config = {
inherit fonts;
@ -56,40 +56,42 @@ in {
output."*".bg = "${config.stylix.image} fill";
};
}];
})
# Merge this with your bar configuration using //config.lib.stylix.sway.bar
lib.stylix.sway.bar = {
inherit fonts;
{
# 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;
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;
};
};
};
};
};
}
];
}

View file

@ -1,64 +0,0 @@
{ config, lib, ... }:
with config.lib.stylix.colors;
let
inside = base01-hex;
outside = base01-hex;
ring = base05-hex;
text = base05-hex;
positive = base0B-hex;
negative = base08-hex;
in {
options.stylix.targets.swaylock = {
enable = config.lib.stylix.mkEnableTarget "Swaylock" true;
useImage = lib.mkOption {
description = ''
Whether to use your wallpaper image for the Swaylock background.
If this is disabled, a plain color will be used instead.
'';
type = lib.types.bool;
default = 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
config = lib.optionalAttrs (options.programs ? swaylock) {
programs.swaylock.settings = {
color = outside;
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;
} // lib.optionalAttrs config.stylix.targets.swaylock.useImage {
image = "${config.stylix.image}";
};
};
}
)];
};
}

58
modules/swaylock/hm.nix Normal file
View file

@ -0,0 +1,58 @@
{ options, config, lib, ... }:
with config.lib.stylix.colors;
let
inside = base01-hex;
outside = base01-hex;
ring = base05-hex;
text = base05-hex;
positive = base0B-hex;
negative = base08-hex;
in {
options.stylix.targets.swaylock = {
enable = config.lib.stylix.mkEnableTarget "Swaylock" true;
useImage = lib.mkOption {
description = ''
Whether to use your wallpaper image for the Swaylock background.
If this is disabled, a plain color will be used instead.
'';
type = lib.types.bool;
default = true;
};
};
config = lib.mkIf config.stylix.targets.swaylock.enable
# See https://github.com/danth/stylix/issues/8#issuecomment-1194484544
# This check can be removed when programs.swaylock is in a stable release
(lib.optionalAttrs (options.programs ? swaylock) {
programs.swaylock.settings = {
color = outside;
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;
} // lib.optionalAttrs config.stylix.targets.swaylock.useImage {
image = "${config.stylix.image}";
};
});
}

View file

@ -38,9 +38,7 @@ in {
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;
}];
programs.vim = vimOptions;
programs.neovim = vimOptions;
};
}

View file

@ -37,12 +37,10 @@ in {
config.lib.stylix.mkEnableTarget "VSCode" true;
config = lib.mkIf config.stylix.targets.vscode.enable {
home-manager.sharedModules = [{
programs.vscode = {
extensions = [ themeExtension ];
userSettings."workbench.colorTheme" = "Stylix";
};
}];
programs.vscode = {
extensions = [ themeExtension ];
userSettings."workbench.colorTheme" = "Stylix";
};
};
}

14
stylix/autoload.nix Normal file
View file

@ -0,0 +1,14 @@
{ lib }:
# string -> [ path ]
# List include path for either nixos modules or hm modules
for:
builtins.concatLists
(lib.mapAttrsToList
(path: kind:
if kind == "directory"
then let
file = "${../modules}/${path}/${for}.nix";
in (if builtins.pathExists file then [ file ] else [ ])
else [ ])
(builtins.readDir ../modules))

View file

@ -1,9 +1,10 @@
{ pkgs, config, lib, ... }:
{ pkgs, config, lib, ... } @ args:
with lib;
let
cfg = config.stylix.fonts;
fromOs = import ./fromos.nix { inherit lib args; };
fontType = types.submodule {
options = {
@ -24,7 +25,7 @@ in {
serif = mkOption {
description = "Serif font.";
type = fontType;
default = {
default = fromOs [ "fonts" "serif" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Serif";
};
@ -33,7 +34,7 @@ in {
sansSerif = mkOption {
description = "Sans-serif font.";
type = fontType;
default = {
default = fromOs [ "fonts" "sansSerif" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Sans";
};
@ -42,7 +43,7 @@ in {
monospace = mkOption {
description = "Monospace font.";
type = fontType;
default = {
default = fromOs [ "fonts" "monospace" ] {
package = pkgs.dejavu_fonts;
name = "DejaVu Sans Mono";
};
@ -51,26 +52,10 @@ in {
emoji = mkOption {
description = "Emoji font.";
type = fontType;
default = {
default = fromOs [ "fonts" "emoji" ] {
package = pkgs.noto-fonts-emoji;
name = "Noto Color Emoji";
};
};
};
config.fonts = {
fonts = [
cfg.monospace.package
cfg.serif.package
cfg.sansSerif.package
cfg.emoji.package
];
fontconfig.defaultFonts = {
monospace = [ cfg.monospace.name ];
serif = [ cfg.serif.name ];
sansSerif = [ cfg.sansSerif.name ];
emoji = [ cfg.emoji.name ];
};
};
}

6
stylix/fromos.nix Normal file
View file

@ -0,0 +1,6 @@
{ lib, args }:
path: default:
if (args ? "osConfig" && args.osConfig.stylix.homeManagerIntegration.followSystem)
then lib.attrByPath path default args.osConfig.stylix
else default

13
stylix/hm/default.nix Normal file
View file

@ -0,0 +1,13 @@
{ palette-generator, base16 }:
{ config, lib, ... }:
let
autoload = import ../autoload.nix { inherit lib; } "hm";
in {
imports = [
../pixel.nix
../target.nix
./fonts.nix
(import ./palette.nix { inherit palette-generator base16; })
] ++ autoload;
}

16
stylix/hm/fonts.nix Normal file
View file

@ -0,0 +1,16 @@
{ config, ... }:
let
cfg = config.stylix.fonts;
in {
imports = [ ../fonts.nix ];
config = {
fonts.fontconfig.enable = true;
home.packages = [
cfg.monospace.package
cfg.serif.package
cfg.sansSerif.package
cfg.emoji.package
];
};
}

17
stylix/hm/palette.nix Normal file
View file

@ -0,0 +1,17 @@
args:
{ config, ... }:
{
imports = [ (import ../palette.nix args) ];
config = {
xdg.configFile = {
# See ../nixos/palette.nix for the rational behind these two options
"stylix/palette.json".source = config.stylix.generated.json;
"stylix/palette.html".source = config.lib.stylix.colors {
template = builtins.readFile ../palette.html.mustache;
extension = ".html";
};
};
};
}

46
stylix/nixos/default.nix Normal file
View file

@ -0,0 +1,46 @@
{ palette-generator, base16, homeManagerModule }:
{ options, config, lib, ... }:
let
hm = config.stylix.homeManagerIntegration;
autoload = import ../autoload.nix { inherit lib; } "nixos";
in {
imports = [
../pixel.nix
../target.nix
./fonts.nix
(import ./palette.nix { inherit palette-generator base16; })
] ++ autoload;
options.stylix.homeManagerIntegration = {
followSystem = lib.mkOption {
description = ''
When this option is <literal>true</literal>, Home Manager will follow
the system theme by default, rather than requiring a theme to be set.
This will only affect Home Manager configurations which are built
within the NixOS configuration.
'';
type = lib.types.bool;
default = true;
};
autoImport = lib.mkOption {
description = ''
Whether to enable Stylix automatically for every user.
This only applies to users for which Home Manager is set up within the
NixOS configuration.
'';
type = lib.types.bool;
default = options ? home-manager;
defaultText = lib.literalDocBook ''
<literal>true</literal> when Home Manager is present.
'';
};
};
config = lib.mkIf hm.autoImport {
home-manager.sharedModules = [ homeManagerModule ];
};
}

22
stylix/nixos/fonts.nix Normal file
View file

@ -0,0 +1,22 @@
{ config, ... }:
let
cfg = config.stylix.fonts;
in {
imports = [ ../fonts.nix ];
config.fonts = {
fonts = [
cfg.monospace.package
cfg.serif.package
cfg.sansSerif.package
cfg.emoji.package
];
fontconfig.defaultFonts = {
monospace = [ cfg.monospace.name ];
serif = [ cfg.serif.name ];
sansSerif = [ cfg.sansSerif.name ];
emoji = [ cfg.emoji.name ];
};
};
}

23
stylix/nixos/palette.nix Normal file
View file

@ -0,0 +1,23 @@
args:
{ config, ... }:
{
imports = [ (import ../palette.nix args) ];
config = {
environment.etc = {
# Making palette.json part of the system closure will protect it from
# garbage collection, so future configurations can be evaluated without
# having to generate the palette again. The generator is not kept, only
# the palette which came from it, so this uses very little disk space.
"stylix/palette.json".source = config.stylix.generated.json;
# We also provide a HTML version which is useful for viewing the colors
# during development.
"stylix/palette.html".source = config.lib.stylix.colors {
template = builtins.readFile ../palette.html.mustache;
extension = ".html";
};
};
};
}

View file

@ -1,9 +1,11 @@
{ palette-generator, base16 }:
{ pkgs, lib, config, ... }:
{ pkgs, lib, config, ... }@args:
with lib;
let
fromOs = import ./fromos.nix { inherit lib args; };
cfg = config.stylix;
paletteJSON = pkgs.runCommand "palette.json" { } ''
@ -11,17 +13,37 @@ let
'';
generatedPalette = importJSON paletteJSON;
generatedScheme = cfg.palette // {
generatedScheme = generatedPalette // {
author = "Stylix";
scheme = "Stylix";
slug = "stylix";
};
in {
# TODO link to doc on how to do instead
imports = [
(lib.mkRemovedOptionModule [ "stylix" "palette" "base00" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base01" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base02" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base03" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base04" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base05" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base06" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base07" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base08" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base09" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0A" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0B" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0C" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0D" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0E" ] "Using stylix.palette to override scheme is not supported anymore")
(lib.mkRemovedOptionModule [ "stylix" "palette" "base0F" ] "Using stylix.palette to override scheme is not supported anymore")
];
options.stylix = {
polarity = mkOption {
type = types.enum [ "either" "light" "dark" ];
default = "either";
default = fromOs [ "polarity" ] "either";
description = ''
Use this option to force a light or dark theme.
@ -39,28 +61,26 @@ in {
This is set as the background of your desktop environment, if possible,
and used to generate a colour scheme if you don't set one manually.
'';
default = fromOs [ "image" ] null;
};
palette = genAttrs [
"base00" "base01" "base02" "base03" "base04" "base05" "base06" "base07"
"base08" "base09" "base0A" "base0B" "base0C" "base0D" "base0E" "base0F"
] (base: mkOption {
description = ''
Hexadecimal color value for ${base}.
generated = {
json = mkOption {
type = types.path;
description = "The result of palette-generator.";
readOnly = true;
internal = true;
default = paletteJSON;
};
You can use this option to override single colors.
See <literal>stylix.base16Scheme</literal> if you want to import a
whole base16 scheme from a file.
You should not read from this option to access the chosen colors - use
<literal>lib.stylix.colors</literal> instead.
If <literal>stylix.base16Scheme</literal> is set to an external file,
those colors won't appear here.
'';
type = types.strMatching "[0-9a-fA-F]{6}";
default = generatedPalette.${base};
defaultText = literalDocBook "Automatically selected from the background image.";
});
palette = mkOption {
type = types.attrs;
description = "The imported json";
readOnly = true;
internal = true;
default = generatedPalette;
};
};
base16Scheme = mkOption {
description = ''
@ -69,9 +89,12 @@ in {
This can be a path to a file, a string of YAML, or an attribute set.
'';
type = with types; oneOf [ path lines attrs ];
default = generatedScheme;
default =
if args ? "osConfig" && cfg.image != args.osConfig.stylix.image
then generatedScheme
else fromOs [ "base16Scheme" ] generatedScheme;
defaultText = literalDocBook ''
The colors defined in <literal>stylix.palette</literal>.
The colors used in the theming.
Those are automatically selected from the background image by default,
but could be overridden manually.
@ -83,20 +106,5 @@ in {
# This attrset can be used like a function too, see
# https://github.com/SenchoPens/base16.nix#mktheme
lib.stylix.colors = base16.mkSchemeAttrs cfg.base16Scheme;
environment.etc = mkIf (cfg.base16Scheme == generatedScheme) {
# Making palette.json part of the system closure will protect it from
# garbage collection, so future configurations can be evaluated without
# having to generate the palette again. The generator is not kept, only
# the palette which came from it, so this uses very little disk space.
"stylix/palette.json".source = paletteJSON;
# We also provide a HTML version which is useful for viewing the colors
# during development.
"stylix/palette.html".source = config.lib.stylix.colors {
template = builtins.readFile ./palette.html.mustache;
extension = ".html";
};
};
};
}

View file

@ -2,11 +2,13 @@
with lib;
{
let
fromOs = import ./fromos.nix { inherit lib args; };
in {
options.stylix.autoEnable = mkOption {
description = "Whether to automatically enable styling for installed targets.";
type = types.bool;
default = true;
default = fromOs [ "autoEnable" ] true;
};
config.lib.stylix.mkEnableTarget =