1
0
Fork 0
mirror of https://github.com/nix-community/home-manager.git synced 2025-11-08 11:36:05 +01:00
home-manager/modules/services/window-managers/spectrwm.nix
Austin Horstman 7419250703
treewide: convert package options to use mkPackageOption (#7116)
This commit converts `package = mkOption` declarations throughout the
codebase to use the more modern and consistent `lib.mkPackageOption`
function.

Key changes:
- Simple package options: `mkOption { type = types.package; default = pkgs.foo; }`
  becomes `lib.mkPackageOption pkgs "foo" { }`
- Package set options: Uses correct package set as first argument with
  `pkgsText` parameter (e.g., `lib.mkPackageOption pkgs.vimPlugins "plugin" { pkgsText = "pkgs.vimPlugins"; }`)
- Removes redundant descriptions that just restate the package name
- Preserves examples and extra context where meaningful
- Handles submodule plugin options properly with `null` defaults

This modernizes the option declarations and makes them more consistent
with current nixpkgs patterns while maintaining full backward compatibility.

Signed-off-by: Austin Horstman <khaneliman12@gmail.com>
2025-05-23 00:42:38 -05:00

140 lines
3.4 KiB
Nix

{
config,
lib,
pkgs,
...
}:
let
inherit (lib)
literalExpression
mapAttrsToList
mkOption
types
;
cfg = config.xsession.windowManager.spectrwm;
renderedValue = val: if lib.isBool val then if val then "1" else "0" else toString val;
renderedSettings =
settings: mapAttrsToList (name: value: "${name} = ${renderedValue value}") settings;
renderedBindings = bindings: mapAttrsToList (name: value: "bind[${name}] = ${value}") bindings;
renderedUnbindings = unbindings: map (value: "bind[] = ${value}") unbindings;
renderedPrograms = programs: mapAttrsToList (name: value: "program[${name}] = ${value}") programs;
renderedQuirks = quirks: mapAttrsToList (name: value: "quirk[${name}] = ${value}") quirks;
settingType = types.oneOf [
types.bool
types.int
types.str
];
in
{
meta.maintainers = [ lib.hm.maintainers.loicreynier ];
options = {
xsession.windowManager.spectrwm = {
enable = lib.mkEnableOption "Spectrwm window manager";
package = lib.mkPackageOption pkgs "spectrwm" {
extraDescription = "providing the spectrwm command";
};
settings = mkOption {
type = types.attrsOf settingType;
default = { };
example = literalExpression ''
{
modkey = "Mod4";
workspace_limit = 5;
focus_mode = "manual";
focus_close = "next";
}
'';
description = "Spectrwm settings.";
};
bindings = mkOption {
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
{
term = "Mod+Return";
restart = "Mod+Shift+r";
quit = "Mod+Shift+q";
}
'';
description = "Spectrwm keybindings.";
};
unbindings = mkOption {
type = types.listOf types.str;
default = [ ];
example = literalExpression ''
[
"MOD+e"
"MOD+f"
"MOD+m"
"MOD+s"
"MOD+u"
"MOD+t"
]
'';
description = ''
List of keybindings to disable from default Spectrwm configuration.
'';
};
programs = mkOption {
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
{
term = "alacritty";
search = "dmenu -ip -p 'Window name/id:';
}
'';
description = "Spectrwm programs variables.";
};
quirks = mkOption {
type = types.attrsOf types.str;
default = { };
example = literalExpression ''
{
Matplotlib = "FLOAT";
Pavucontrol = "FLOAT";
}
'';
description = "Spectrwm quicks (custom window rules).";
};
};
};
config = lib.mkIf cfg.enable {
assertions = [
(lib.hm.assertions.assertPlatform "xsession.windowManager.spectrwm" pkgs lib.platforms.linux)
];
home.packages = [ cfg.package ];
xsession.windowManager.command = "${cfg.package}/bin/spectrwm";
xdg.configFile."spectrwm/spectrwm.conf".text = ''
# Generated by Home Manager
${lib.concatStringsSep "\n" (
# \
renderedSettings cfg.settings # \
++ renderedPrograms cfg.programs # \
++ renderedQuirks cfg.quirks # \
++ renderedBindings cfg.bindings # \
++ renderedUnbindings cfg.unbindings
)}
'';
};
}