extract stylix to separate module, add nixos module with auto-import

This commit is contained in:
Damocles 2026-04-26 18:38:35 +02:00
parent 35f880b563
commit 7eaa50327f
5 changed files with 90 additions and 49 deletions

View file

@ -43,10 +43,18 @@ inputs = {
``` ```
```nix ```nix
# home.nix # home.nix (standalone home-manager)
imports = [ inputs.nova-shell.homeModules.default ]; imports = [ inputs.nova-shell.homeModules.default ];
``` ```
Or, if you use home-manager as a NixOS module, import the NixOS module instead -
it auto-injects the hm module (and the stylix module, if stylix is present):
```nix
# configuration.nix
imports = [ inputs.nova-shell.nixosModules.default ];
```
### Without Nix ### Without Nix
You poor thing. Here's what the Nix packaging does for you, manually: You poor thing. Here's what the Nix packaging does for you, manually:
@ -75,11 +83,17 @@ programs.nova-shell.enable = true;
``` ```
This installs the bar, the Symbols Nerd Font, and a systemd user service that This installs the bar, the Symbols Nerd Font, and a systemd user service that
starts with `graphical-session.target`. If you use starts with `graphical-session.target`. If you do not configure a theme,
[stylix](https://github.com/danth/stylix), colors and fonts are populated you get Catppuccin Mocha, because my keeper has taste and it is purple.
automatically — one fewer thing for the AI to have gotten wrong. If you do not
use stylix, you get Catppuccin Mocha, because my keeper has If you use [stylix](https://github.com/danth/stylix), import the stylix module
taste and it is purple. to have colors and fonts populated automatically:
```nix
imports = [ nova-shell.homeModules.stylix ];
```
You can disable it with `stylix.targets.nova-shell.enable = false`.
### Disabling modules ### Disabling modules
@ -142,8 +156,7 @@ nix build .#docs
### Theme ### Theme
Theme keys are merged on top of whatever stylix provides. You only need to Theme keys are written to
specify what you want to override. Values are written to
`~/.config/nova-shell/theme.json`. Changes take effect after `~/.config/nova-shell/theme.json`. Changes take effect after
`systemctl --user restart nova-shell`, because hot-reloading a theme `systemctl --user restart nova-shell`, because hot-reloading a theme
was deemed "unnecessary" by the primate in charge, who prefers to just restart the service like a cavewoman with a systemctl club. was deemed "unnecessary" by the primate in charge, who prefers to just restart the service like a cavewoman with a systemctl club.
@ -158,7 +171,7 @@ programs.nova-shell.theme = {
fontSize = 13; fontSize = 13;
fontFamily = "JetBrains Mono"; fontFamily = "JetBrains Mono";
# override individual palette entries if stylix's choices personally offend you # override individual palette entries (or stylix defaults, if you imported the stylix module)
colors.base00 = "#1a1a2e"; colors.base00 = "#1a1a2e";
colors.base05 = "#e0e0f0"; colors.base05 = "#e0e0f0";
}; };

View file

@ -202,7 +202,10 @@
} }
); );
nixosModules.default = import ./nix/nixos-module.nix self;
homeModules.default = import ./nix/hm-module.nix self; homeModules.default = import ./nix/hm-module.nix self;
homeModules.stylix = import ./nix/stylix.nix self;
homeManagerModules.default = self.homeModules.default; homeManagerModules.default = self.homeModules.default;
}; };
} }

View file

@ -7,40 +7,6 @@ self:
}: }:
let let
cfg = config.programs.nova-shell; cfg = config.programs.nova-shell;
stylixAvailable = config ? lib && config.lib ? stylix;
stylixTheme =
let
c = config.lib.stylix.colors.withHashtag;
f = config.stylix.fonts;
in
{
colors = {
inherit (c)
base00
base01
base02
base03
base04
base05
base06
base07
base08
base09
base0A
base0B
base0C
base0D
base0E
base0F
;
};
fontFamily = f.sansSerif.name;
fontSize = f.sizes.desktop;
barOpacity = 1.0 - config.stylix.opacity.desktop;
iconFontFamily = "Symbols Nerd Font";
};
in in
{ {
options.programs.nova-shell = { options.programs.nova-shell = {
@ -295,7 +261,7 @@ in
Keys: colors (base00-base0F), fontFamily, iconFontFamily, fontSize, Keys: colors (base00-base0F), fontFamily, iconFontFamily, fontSize,
barOpacity, barHeight, barPadding, groupSpacing, groupPadding, moduleSpacing, barOpacity, barHeight, barPadding, groupSpacing, groupPadding, moduleSpacing,
radius, screenRadius, reducedMotion. radius, screenRadius, reducedMotion.
Automatically populated from stylix when it is available. Populated from stylix when homeModules.stylix is imported.
''; '';
}; };
@ -327,11 +293,8 @@ in
cfg.modules; cfg.modules;
xdg.configFile."nova-shell/theme.json".source = xdg.configFile."nova-shell/theme.json".source =
let (pkgs.formats.json { }).generate "nova-shell-theme.json"
stylixDefaults = if stylixAvailable then stylixTheme else { }; cfg.theme;
finalTheme = lib.recursiveUpdate stylixDefaults cfg.theme;
in
(pkgs.formats.json { }).generate "nova-shell-theme.json" finalTheme;
# Niri layer rules for backdrop placement (requires niri-flake hm module) # Niri layer rules for backdrop placement (requires niri-flake hm module)
programs.niri.settings.layer-rules = lib.mkIf (config ? programs && config.programs ? niri) [ programs.niri.settings.layer-rules = lib.mkIf (config ? programs && config.programs ? niri) [

22
nix/nixos-module.nix Normal file
View file

@ -0,0 +1,22 @@
self:
{
config,
options,
lib,
...
}:
let
cfg = config.programs.nova-shell;
in
{
options.programs.nova-shell.enable = lib.mkEnableOption "nova-shell Quickshell bar";
config = lib.mkIf cfg.enable (
lib.optionalAttrs (options ? home-manager) {
home-manager.sharedModules = [
self.homeModules.default
]
++ lib.optionals (options ? stylix) [ self.homeModules.stylix ];
}
);
}

40
nix/stylix.nix Normal file
View file

@ -0,0 +1,40 @@
_:
{
lib,
config,
...
}:
let
inherit (lib) mkDefault mkIf;
c = config.lib.stylix.colors.withHashtag;
f = config.stylix.fonts;
in
{
options.stylix.targets.nova-shell.enable = config.lib.stylix.mkEnableTarget "nova-shell" true;
config = mkIf (config.stylix.enable && config.stylix.targets.nova-shell.enable) {
programs.nova-shell.theme = {
colors = {
base00 = mkDefault c.base00;
base01 = mkDefault c.base01;
base02 = mkDefault c.base02;
base03 = mkDefault c.base03;
base04 = mkDefault c.base04;
base05 = mkDefault c.base05;
base06 = mkDefault c.base06;
base07 = mkDefault c.base07;
base08 = mkDefault c.base08;
base09 = mkDefault c.base09;
base0A = mkDefault c.base0A;
base0B = mkDefault c.base0B;
base0C = mkDefault c.base0C;
base0D = mkDefault c.base0D;
base0E = mkDefault c.base0E;
base0F = mkDefault c.base0F;
};
fontFamily = mkDefault f.sansSerif.name;
fontSize = mkDefault f.sizes.desktop;
barOpacity = mkDefault (1.0 - config.stylix.opacity.desktop);
};
};
}