From 6dc68b1d16c47031cf897eb0b0aa2fcce4178baf Mon Sep 17 00:00:00 2001 From: Nicolas Berbiche Date: Sun, 15 Nov 2020 17:58:55 -0500 Subject: [PATCH] i3: validate configuration at build time PR #1579 --- modules/services/window-managers/i3-sway/i3.nix | 17 ++++++++++++++++- .../window-managers/i3/i3-followmouse.nix | 4 +++- .../window-managers/i3/i3-keybindings.nix | 7 ++++--- 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix index 8cc01cd6..37f6e8bd 100644 --- a/modules/services/window-managers/i3-sway/i3.nix +++ b/modules/services/window-managers/i3-sway/i3.nix @@ -193,6 +193,21 @@ let else "") + "\n" + cfg.extraConfig); + # Validates the i3 configuration + checkI3Config = + pkgs.runCommandLocal "i3-config" { buildInputs = [ cfg.package ]; } '' + # We have to make sure the wrapper does not start a dbus session + export DBUS_SESSION_BUS_ADDRESS=1 + + # A zero exit code means i3 succesfully validated the configuration + i3 -c ${configFile} -C -d all || { + echo "i3 configuration validation failed" + echo "For a verbose log of the failure, run 'i3 -c ${configFile} -C -d all'" + exit 1 + }; + cp ${configFile} $out + ''; + in { options = { xsession.windowManager.i3 = { @@ -229,7 +244,7 @@ in { home.packages = [ cfg.package ]; xsession.windowManager.command = "${cfg.package}/bin/i3"; xdg.configFile."i3/config" = { - source = configFile; + source = checkI3Config; onChange = '' i3Socket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/i3/ipc-socket.* if [ -S $i3Socket ]; then diff --git a/tests/modules/services/window-managers/i3/i3-followmouse.nix b/tests/modules/services/window-managers/i3/i3-followmouse.nix index 8d51e348..43e15cda 100644 --- a/tests/modules/services/window-managers/i3/i3-followmouse.nix +++ b/tests/modules/services/window-managers/i3/i3-followmouse.nix @@ -14,7 +14,9 @@ with lib; (self: super: { dmenu = super.dmenu // { outPath = "@dmenu@"; }; - i3 = super.i3 // { outPath = "@i3@"; }; + i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; }; + + i3-gaps = super.writeScriptBin "i3" "" // { outPath = "@i3-gaps@"; }; i3status = super.i3status // { outPath = "@i3status@"; }; }) diff --git a/tests/modules/services/window-managers/i3/i3-keybindings.nix b/tests/modules/services/window-managers/i3/i3-keybindings.nix index 4f8515e6..0458b874 100644 --- a/tests/modules/services/window-managers/i3/i3-keybindings.nix +++ b/tests/modules/services/window-managers/i3/i3-keybindings.nix @@ -19,9 +19,10 @@ with lib; nixpkgs.overlays = [ (self: super: { dmenu = super.dmenu // { outPath = "@dmenu@"; }; - - i3 = super.i3 // { outPath = "@i3@"; }; - + i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; }; + i3-gaps = super.writeScriptBin "i3-gaps" "" // { + outPath = "@i3-gaps@"; + }; i3status = super.i3status // { outPath = "@i3status@"; }; }) ];