fork/home-manager

git clone https://git.julia.blue/fork/home-manager

Robert HelgessonMerge PR #421575790441

master
3.4 KiB135 linesraw
1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6
7  cfg = config.xsession.windowManager.spectrwm;
8
9  renderedValue = val:
10    if isBool val then if val then "1" else "0" else toString val;
11
12  renderedSettings = settings:
13    mapAttrsToList (name: value: "${name} = ${renderedValue value}") settings;
14
15  renderedBindings = bindings:
16    mapAttrsToList (name: value: "bind[${name}] = ${value}") bindings;
17
18  renderedUnbindings = unbindings: map (value: "bind[] = ${value}") unbindings;
19
20  renderedPrograms = programs:
21    mapAttrsToList (name: value: "program[${name}] = ${value}") programs;
22
23  renderedQuirks = quirks:
24    mapAttrsToList (name: value: "quirk[${name}] = ${value}") quirks;
25
26  settingType = types.oneOf [ types.bool types.int types.str ];
27
28in {
29  meta.maintainers = [ hm.maintainers.loicreynier ];
30
31  options = {
32    xsession.windowManager.spectrwm = {
33      enable = mkEnableOption "Spectrwm window manager";
34
35      package = mkOption {
36        type = types.package;
37        default = pkgs.spectrwm;
38        defaultText = literalExpression "pkgs.spectrwm";
39        description = ''
40          Package providing the {command}`spectrwm` command.
41        '';
42      };
43
44      settings = mkOption {
45        type = types.attrsOf settingType;
46        default = { };
47        example = literalExpression ''
48          {
49            modkey = "Mod4";
50            workspace_limit = 5;
51            focus_mode = "manual";
52            focus_close = "next";
53          }
54        '';
55        description = "Spectrwm settings.";
56      };
57
58      bindings = mkOption {
59        type = types.attrsOf types.str;
60        default = { };
61        example = literalExpression ''
62          {
63            term = "Mod+Return";
64            restart = "Mod+Shift+r";
65            quit = "Mod+Shift+q";
66          }
67        '';
68        description = "Spectrwm keybindings.";
69      };
70
71      unbindings = mkOption {
72        type = types.listOf types.str;
73        default = [ ];
74        example = literalExpression ''
75          [
76            "MOD+e"
77            "MOD+f"
78            "MOD+m"
79            "MOD+s"
80            "MOD+u"
81            "MOD+t"
82          ]
83        '';
84        description = ''
85          List of keybindings to disable from default Spectrwm configuration.
86        '';
87      };
88
89      programs = mkOption {
90        type = types.attrsOf types.str;
91        default = { };
92        example = literalExpression ''
93          {
94            term = "alacritty";
95            search = "dmenu -ip -p 'Window name/id:';
96          }
97        '';
98        description = "Spectrwm programs variables.";
99      };
100
101      quirks = mkOption {
102        type = types.attrsOf types.str;
103        default = { };
104        example = literalExpression ''
105          {
106            Matplotlib = "FLOAT";
107            Pavucontrol = "FLOAT";
108          }
109        '';
110        description = "Spectrwm quicks (custom window rules).";
111      };
112    };
113  };
114
115  config = mkIf cfg.enable {
116    assertions = [
117      (hm.assertions.assertPlatform "xsession.windowManager.spectrwm" pkgs
118        platforms.linux)
119    ];
120
121    home.packages = [ cfg.package ];
122
123    xsession.windowManager.command = "${cfg.package}/bin/spectrwm";
124
125    xdg.configFile."spectrwm/spectrwm.conf".text = ''
126      # Generated by Home Manager
127      ${concatStringsSep "\n" ( # \
128        renderedSettings cfg.settings # \
129        ++ renderedPrograms cfg.programs # \
130        ++ renderedQuirks cfg.quirks # \
131        ++ renderedBindings cfg.bindings # \
132        ++ renderedUnbindings cfg.unbindings)}
133    '';
134  };
135}