feat(nix): add build-time configuration validation

Uses `pkgs.runCommand` in the home-manager module to parse and validate
the generated config file prior to deployment, preventing broken setups.
This commit is contained in:
Ananya Timalsina 2026-03-01 15:40:25 +01:00
parent 5396ec13c2
commit 1f8f4cc2f8

View file

@ -211,53 +211,63 @@ in
}; };
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable (
# Backwards compatibility warning for old string-based config let
warnings = lib.optional (builtins.isString cfg.settings) '' finalConfigText =
wayland.windowManager.mango.settings: Using a string for settings is deprecated. # Support old string-based config during transition period
Please migrate to the new structured attribute set format. (
See the module documentation for examples, or use the 'extraConfig' option for raw config strings. if builtins.isString cfg.settings then
The old string format will be removed in a future release. cfg.settings
''; else
lib.optionalString (cfg.settings != { }) (
selflib.toMango {
topCommandsPrefixes = cfg.topPrefixes;
bottomCommandsPrefixes = cfg.bottomPrefixes;
} cfg.settings
)
)
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig
+ lib.optionalString (cfg.autostart_sh != "") "\nexec-once=~/.config/mango/autostart.sh\n";
home.packages = [ cfg.package ]; validatedConfig = pkgs.runCommand "mango-config.conf" { } ''
xdg.configFile = { cp ${pkgs.writeText "mango-config.conf" finalConfigText} "$out"
"mango/config.conf" = ${cfg.package}/bin/mango -c "$out" -p || exit 1
lib.mkIf (cfg.settings != { } || cfg.extraConfig != "" || cfg.autostart_sh != "") '';
{ in
text = {
# Support old string-based config during transition period # Backwards compatibility warning for old string-based config
( warnings = lib.optional (builtins.isString cfg.settings) ''
if builtins.isString cfg.settings then wayland.windowManager.mango.settings: Using a string for settings is deprecated.
cfg.settings Please migrate to the new structured attribute set format.
else See the module documentation for examples, or use the 'extraConfig' option for raw config strings.
lib.optionalString (cfg.settings != { }) ( The old string format will be removed in a future release.
selflib.toMango { '';
topCommandsPrefixes = cfg.topPrefixes;
bottomCommandsPrefixes = cfg.bottomPrefixes; home.packages = [ cfg.package ];
} cfg.settings xdg.configFile = {
) "mango/config.conf" =
) lib.mkIf (cfg.settings != { } || cfg.extraConfig != "" || cfg.autostart_sh != "")
+ lib.optionalString (cfg.extraConfig != "") cfg.extraConfig {
+ lib.optionalString (cfg.autostart_sh != "") "\nexec-once=~/.config/mango/autostart.sh\n"; source = validatedConfig;
}; };
"mango/autostart.sh" = lib.mkIf (cfg.autostart_sh != "") { "mango/autostart.sh" = lib.mkIf (cfg.autostart_sh != "") {
source = autostart_sh; source = autostart_sh;
executable = true; executable = true;
};
}; };
}; systemd.user.targets.mango-session = lib.mkIf cfg.systemd.enable {
systemd.user.targets.mango-session = lib.mkIf cfg.systemd.enable { Unit = {
Unit = { Description = "mango compositor session";
Description = "mango compositor session"; Documentation = [ "man:systemd.special(7)" ];
Documentation = [ "man:systemd.special(7)" ]; BindsTo = [ "graphical-session.target" ];
BindsTo = [ "graphical-session.target" ]; Wants = [
Wants = [ "graphical-session-pre.target"
"graphical-session-pre.target" ]
] ++ lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";
++ lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; After = [ "graphical-session-pre.target" ];
After = [ "graphical-session-pre.target" ]; Before = lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target";
Before = lib.optional cfg.systemd.xdgAutostart "xdg-desktop-autostart.target"; };
}; };
}; }
}; );
} }