tony / oxwm

Merge pull request #156 from Pascal0577/home-manager-activation-check Browse files
Add Home Manager configuration validation
Tony, btw. committed 2026-02-19 parents e9c4933 994c4bb commit 3205bfc1d251545bda5a4ae0ad56b5bc1648a56d
Showing 1 changed file with 75 additions and 61 deletions. UnifiedSplit
+75 −61 hm.nix
@@ -7,6 +7,7 @@
7 7 inherit (lib) mkEnableOption mkOption mkIf types concatMapStringsSep concatStringsSep concatMapStrings boolToString optional;
8 8 inherit (lib.strings) escapeNixString;
9 9 cfg = config.programs.oxwm.settings;
10 + pkg = config.programs.oxwm.package;
10 11
11 12 # Converts a nix submodule into a single oxwm bar block
12 13 blockToLua = block: let
@@ -60,9 +61,81 @@
60 61 ++ optional (rule.floating != null) ''floating = ${boolToString rule.floating}''
61 62 ++ optional (rule.tag != null) ''tag = ${toString rule.tag}''
62 63 ++ optional (rule.fullscreen != null) ''fullscreen = ${boolToString rule.fullscreen}''
63 - ++ optional (rule.focus != null) ''focus = ${boolToString rule.fullscreen}''
64 + ++ optional (rule.focus != null) ''focus = ${boolToString rule.focus}''
64 65 );
65 66 in "oxwm.rule.add({ ${fields} })";
67 +
68 + configText = ''
69 + -- @meta
70 + -- @module 'oxwm'
71 +
72 + oxwm.set_terminal("${cfg.terminal}")
73 + oxwm.set_modkey("${cfg.modkey}")
74 + oxwm.set_tags({${concatMapStringsSep ", " escapeNixString cfg.tags}})
75 +
76 + local blocks = {
77 + ${concatMapStringsSep ",\n" blockToLua cfg.bar.blocks}
78 + };
79 + oxwm.bar.set_blocks(blocks)
80 + oxwm.bar.set_font("${cfg.bar.font}")
81 + oxwm.bar.set_scheme_normal(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.unoccupiedScheme})
82 + oxwm.bar.set_scheme_occupied(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.occupiedScheme})
83 + oxwm.bar.set_scheme_selected(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.selectedScheme})
84 + oxwm.bar.set_scheme_urgent(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.urgentScheme})
85 + oxwm.bar.set_hide_vacant_tags(${boolToString cfg.bar.hideVacantTags})
86 +
87 + oxwm.border.set_width(${toString cfg.border.width})
88 + oxwm.border.set_focused_color("#${cfg.border.focusedColor}")
89 + oxwm.border.set_unfocused_color("#${cfg.border.unfocusedColor}")
90 +
91 + oxwm.gaps.set_smart(${cfg.gaps.smart})
92 + oxwm.gaps.set_inner(${concatMapStringsSep ", " toString cfg.gaps.inner})
93 + oxwm.gaps.set_outer(${concatMapStringsSep ", " toString cfg.gaps.outer})
94 +
95 + oxwm.set_layout_symbol("tiling", "${cfg.layoutSymbol.tiling}")
96 + oxwm.set_layout_symbol("normie", "${cfg.layoutSymbol.normie}")
97 + oxwm.set_layout_symbol("tabbed", "${cfg.layoutSymbol.tabbed}")
98 +
99 + ${
100 + concatMapStrings (cmd: ''
101 + oxwm.autostart("${cmd}")
102 + '')
103 + cfg.autostart
104 + }
105 + ${
106 + concatMapStrings (bind: ''
107 + oxwm.key.bind({ ${concatMapStringsSep ", " escapeNixString bind.mods} }, "${bind.key}", ${bind.action})
108 + '')
109 + cfg.binds
110 + }
111 + ${
112 + concatMapStrings (chord: ''
113 + oxwm.key.chord({
114 + ${concatMapStringsSep ",\n " (note: ''{ { ${concatMapStringsSep ", " escapeNixString note.mods} }, "${note.key}" }'') chord.notes}
115 + }, ${chord.action})
116 + '')
117 + cfg.chords
118 + }
119 + ${
120 + concatMapStrings (rule: ''
121 + ${ruleToLua rule}
122 + '')
123 + cfg.rules
124 + }
125 +
126 + ${cfg.extraConfig}
127 + '';
128 +
129 + validatedConfig = pkgs.runCommand "config.lua" {
130 + config = configText;
131 + passAsFile = [ "config" ];
132 + buildInputs = [ pkg ];
133 + } ''
134 + mkdir -p $TMPDIR/oxwm
135 + cp $configPath $TMPDIR/oxwm/config.lua
136 + XDG_CONFIG_HOME=$TMPDIR ${lib.getExe pkg} --validate
137 + cp $configPath $out
138 + '';
66 139 in {
67 140 options.programs.oxwm = {
68 141 enable = mkEnableOption "oxwm window manager";
@@ -401,65 +474,6 @@ in {
401 474 };
402 475
403 476 config = mkIf config.programs.oxwm.enable {
404 - xdg.configFile."oxwm/config.lua".text = ''
405 - -- @meta
406 - -- @module 'oxwm'
407 -
408 - oxwm.set_terminal("${cfg.terminal}")
409 - oxwm.set_modkey("${cfg.modkey}")
410 - oxwm.set_tags({${concatMapStringsSep ", " escapeNixString cfg.tags}})
411 -
412 - local blocks = {
413 - ${concatMapStringsSep ",\n" blockToLua cfg.bar.blocks}
414 - };
415 - oxwm.bar.set_blocks(blocks)
416 - oxwm.bar.set_font("${cfg.bar.font}")
417 - oxwm.bar.set_scheme_normal(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.unoccupiedScheme})
418 - oxwm.bar.set_scheme_occupied(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.occupiedScheme})
419 - oxwm.bar.set_scheme_selected(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.selectedScheme})
420 - oxwm.bar.set_scheme_urgent(${concatMapStringsSep ", " (c: ''"#${c}"'') cfg.bar.urgentScheme})
421 - oxwm.bar.set_hide_vacant_tags(${boolToString cfg.bar.hideVacantTags})
422 -
423 - oxwm.border.set_width(${toString cfg.border.width})
424 - oxwm.border.set_focused_color("#${cfg.border.focusedColor}")
425 - oxwm.border.set_unfocused_color("#${cfg.border.unfocusedColor}")
426 -
427 - oxwm.gaps.set_smart(${cfg.gaps.smart})
428 - oxwm.gaps.set_inner(${concatMapStringsSep ", " toString cfg.gaps.inner})
429 - oxwm.gaps.set_outer(${concatMapStringsSep ", " toString cfg.gaps.outer})
430 -
431 - oxwm.set_layout_symbol("tiling", "${cfg.layoutSymbol.tiling}")
432 - oxwm.set_layout_symbol("normie", "${cfg.layoutSymbol.normie}")
433 - oxwm.set_layout_symbol("tabbed", "${cfg.layoutSymbol.tabbed}")
434 -
435 - ${
436 - concatMapStrings (cmd: ''
437 - oxwm.autostart("${cmd}")
438 - '')
439 - cfg.autostart
440 - }
441 - ${
442 - concatMapStrings (bind: ''
443 - oxwm.key.bind({ ${concatMapStringsSep ", " escapeNixString bind.mods} }, "${bind.key}", ${bind.action})
444 - '')
445 - cfg.binds
446 - }
447 - ${
448 - concatMapStrings (chord: ''
449 - oxwm.key.chord({
450 - ${concatMapStringsSep ",\n " (note: ''{ { ${concatMapStringsSep ", " escapeNixString note.mods} }, "${note.key}" }'') chord.notes}
451 - }, ${chord.action})
452 - '')
453 - cfg.chords
454 - }
455 - ${
456 - concatMapStrings (rule: ''
457 - ${ruleToLua rule}
458 - '')
459 - cfg.rules
460 - }
461 -
462 - ${cfg.extraConfig}
463 - '';
477 + xdg.configFile."oxwm/config.lua".source = validatedConfig;
464 478 };
465 479 }