restructure module config to objects with enable + extra options

This commit is contained in:
Damocles 2026-04-12 17:36:38 +02:00
parent 4109078a91
commit 55ab5bc4e7
9 changed files with 123 additions and 117 deletions

View file

@ -52,54 +52,65 @@ in
description = "nova-shell package to use.";
};
modules = lib.mkOption {
description = "Enable or disable individual bar modules.";
default = { };
type = lib.types.submodule {
options =
lib.genAttrs
[
"workspaces"
"tray"
"windowTitle"
"clock"
"notifications"
"mpris"
"volume"
"bluetooth"
"backlight"
"network"
"powerProfile"
"idleInhibitor"
"weather"
"temperature"
"cpu"
"memory"
"disk"
"battery"
"power"
]
(
name:
lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable the ${name} module.";
}
);
modules =
let
moduleOpt =
name: extra:
lib.mkOption {
default = { };
description = "Configuration for the ${name} module.";
type = lib.types.submodule {
options = {
enable = lib.mkOption {
type = lib.types.bool;
default = true;
description = "Enable the ${name} module.";
};
} // extra;
};
};
simpleModules = lib.genAttrs [
"workspaces"
"tray"
"windowTitle"
"clock"
"notifications"
"mpris"
"volume"
"bluetooth"
"network"
"powerProfile"
"idleInhibitor"
"temperature"
"cpu"
"memory"
"disk"
"battery"
"power"
] (name: moduleOpt name { });
in
simpleModules
// {
backlight = moduleOpt "backlight" {
step = lib.mkOption {
type = lib.types.int;
default = 5;
description = "Brightness adjustment step (%).";
};
};
weather = moduleOpt "weather" {
args = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "--nerd" ];
description = "Arguments passed to wttrbar.";
example = [
"--nerd"
"--location"
"Berlin"
];
};
};
};
};
weatherArgs = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [ "--nerd" ];
description = "Arguments passed to wttrbar.";
example = [
"--nerd"
"--location"
"Berlin"
];
};
theme = lib.mkOption {
type = lib.types.attrsOf lib.types.anything;
@ -131,11 +142,10 @@ in
self.packages.${pkgs.stdenv.hostPlatform.system}.nova-shell-cli
pkgs.nerd-fonts.symbols-only
]
++ lib.optional cfg.modules.weather pkgs.wttrbar;
++ lib.optional cfg.modules.weather.enable pkgs.wttrbar;
xdg.configFile."nova-shell/modules.json".source =
(pkgs.formats.json { }).generate "nova-shell-modules.json"
(cfg.modules // { weatherArgs = cfg.weatherArgs; });
(pkgs.formats.json { }).generate "nova-shell-modules.json" cfg.modules;
xdg.configFile."nova-shell/theme.json".source =
let