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

treewide: make stylix.image optional #717

Merged
merged 15 commits into from
Feb 24, 2025
Merged
Show file tree
Hide file tree
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
7 changes: 6 additions & 1 deletion .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,12 @@ jobs:
- uses: DeterminateSystems/nix-installer-action@v16
with:
extra-conf: |-
allow-import-from-derivation = false
allow-import-from-derivation = ${{
startsWith(matrix.check.key, 'testbed:') &&
contains(matrix.check.key, ':schemeless') &&
'true' ||
'false'
}}

- run: |
nix build --no-update-lock-file --print-build-logs \
Expand Down
85 changes: 42 additions & 43 deletions docs/src/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,53 +16,12 @@ To enable the Stylix module, declare:
> examples which don't include it. No other settings will take effect unless
> `stylix.enable` is set to `true`.

## Wallpaper

To start theming, you need to set a wallpaper image.

```nix
{
stylix.image = ./wallpaper.png;
}
```

The option accepts derivations as well as paths, so you can fetch an image
directly from the internet:

```nix
{
stylix.image = pkgs.fetchurl {
url = "https://www.pixelstalk.net/wp-content/uploads/2016/05/Epic-Anime-Awesome-Wallpapers.jpg";
sha256 = "enQo3wqhgf0FEPHj2coOCvo7DuZv+x5rL/WIo4qPI50=";
};
}
```

## Color scheme

### Generated schemes

If you only set a wallpaper, Stylix will use a
[genetic algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm)
to create a color scheme. The quality of these schemes can vary, but more
colorful images tend to have better results.

You can force a light or dark scheme using the polarity option:

```nix
{
stylix.polarity = "dark";
}
```

The current scheme can be previewed in a web browser at either
[`/etc/stylix/palette.html`](file:///etc/stylix/palette.html) for NixOS, or
`~/.config/stylix/palette.html` for Home Manager.

### Handmade schemes

If you prefer a handmade color scheme, you can choose anything from
[the Tinted Theming repository](https://github.com/tinted-theming/schemes):
To set a [Tinted Theming](https://github.com/tinted-theming/schemes) color
scheme, declare:

```nix
{
Expand Down Expand Up @@ -116,6 +75,46 @@ For more complex configurations you may find it simpler to use
See [base16.nix](https://github.com/SenchoPens/base16.nix) documentation for
usage examples.

## Wallpaper

To set a wallpaper, provide a path or an arbitrary derivation:

- ```nix
{
stylix.image = ./wallpaper.png;
}
```

- ```nix
{
stylix.image = pkgs.fetchurl {
url = "https://www.pixelstalk.net/wp-content/uploads/2016/05/Epic-Anime-Awesome-Wallpapers.jpg";
sha256 = "enQo3wqhgf0FEPHj2coOCvo7DuZv+x5rL/WIo4qPI50=";
};
}
```

If `stylix.base16Scheme` is undeclared, Stylix generates a color scheme based on
the wallpaper using a [genetic
algorithm](https://en.wikipedia.org/wiki/Genetic_algorithm). Note that more
colorful images tend to yield better results. The algorithm's polarity can be
schewed towards a dark or light theme with:

- ```nix
{
stylix.polarity = "dark";
}
```

- ```nix
{
stylix.polarity = "light";
}
```

The generated color scheme can be viewed at `/etc/stylix/palette.html` on NixOS,
or at `~/.config/stylix/palette.html` on Home Manager.

## Fonts

The default combination of fonts is:
Expand Down
13 changes: 9 additions & 4 deletions modules/feh/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
lib,
...
}:

let
cfg = config.stylix.targets.feh;
in
{
options.stylix.targets.feh.enable =
config.lib.stylix.mkEnableTarget "the desktop background using Feh" true;
options.stylix.targets.feh = {
enable = config.lib.stylix.mkEnableTarget "the desktop background using Feh" (
config.stylix.image != null
);
};

config.xsession.initExtra =
lib.mkIf
(
config.stylix.enable
&& config.stylix.targets.feh.enable
&& cfg.enable
&& (
with config.xsession.windowManager;
bspwm.enable
Expand Down
13 changes: 9 additions & 4 deletions modules/feh/nixos.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,21 @@
lib,
...
}:

let
cfg = config.stylix.targets.feh;
in
{
options.stylix.targets.feh.enable =
config.lib.stylix.mkEnableTarget "the desktop background using Feh" true;
options.stylix.targets.feh = {
enable = config.lib.stylix.mkEnableTarget "the desktop background using Feh" (
config.stylix.image != null
);
};

config.services.xserver.displayManager.sessionCommands =
lib.mkIf
(
config.stylix.enable
&& config.stylix.targets.feh.enable
&& cfg.enable
&& (with config.services.xserver.windowManager; xmonad.enable || i3.enable)
)
(
Expand Down
13 changes: 8 additions & 5 deletions modules/gnome/hm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let
inherit (config.stylix.fonts) sansSerif serif monospace;
fontSize = toString config.stylix.fonts.sizes.applications;
documentFontSize = toString (config.stylix.fonts.sizes.applications - 1);
cfg = config.stylix.targets.gnome;

activator = pkgs.writeShellApplication {
name = "stylix-activate-gnome";
Expand Down Expand Up @@ -42,10 +43,12 @@ let

in
{
options.stylix.targets.gnome.enable =
config.lib.stylix.mkEnableTarget "GNOME" true;
options.stylix.targets.gnome = {
enable = config.lib.stylix.mkEnableTarget "GNOME" true;
useWallpaper = config.lib.stylix.mkEnableWallpaper "GNOME" true;
};

config = lib.mkIf (config.stylix.enable && config.stylix.targets.gnome.enable) {
config = lib.mkIf (config.stylix.enable && cfg.enable) {
dconf.settings = {
"org/gnome/desktop/background" = {
color-shading-type = "solid";
Expand All @@ -64,8 +67,8 @@ in
# Seemingly no tile support... :(
else
"zoom";
picture-uri = "file://${config.stylix.image}";
picture-uri-dark = "file://${config.stylix.image}";
picture-uri = lib.mkIf cfg.useWallpaper "file://${config.stylix.image}";
picture-uri-dark = lib.mkIf cfg.useWallpaper "file://${config.stylix.image}";
};

"org/gnome/desktop/interface" = {
Expand Down
Loading