From 5256fd07baab0843ffce4d97a57654f6b89fcc7b Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sun, 21 Apr 2024 09:20:30 -0400 Subject: [PATCH] sway: make it possible to alter conf in preCheckConfig Some situations may require altering the config file itself to remove or adjust things. While this of course reduces the correctness of the check, it may be better to lose a little than be forced to disable the check altogether. --- modules/services/window-managers/i3-sway/sway.nix | 8 ++++++-- .../window-managers/sway/sway-check-config-precheck.nix | 5 ++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 1be02659..c6c5904a 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -269,8 +269,9 @@ let checkPhase = lib.optionalString cfg.checkConfig '' export DBUS_SESSION_BUS_ADDRESS=/dev/null export XDG_RUNTIME_DIR=$(mktemp -d) + cp "$target" sway.conf ${cfg.preCheckConfig} - ${pkgs.xvfb-run}/bin/xvfb-run ${swayPackage}/bin/sway --config "$target" --validate --unsupported-gpu + ${pkgs.xvfb-run}/bin/xvfb-run ${swayPackage}/bin/sway --config sway.conf --validate --unsupported-gpu ''; text = concatStringsSep "\n" @@ -483,12 +484,15 @@ in { type = types.lines; default = ""; example = '' + sed 's/foo/bar/g' -i sway.conf export HOME=$(mktemp -d) touch ~/background.png ''; description = '' Script to run before running `sway --validate` on the generated config - file. Only used if `checkConfig = true`. + file. The config file is available as `sway.conf`, and can be + manipulated without affecting the build output. Only used if + `checkConfig = true`. ''; }; diff --git a/tests/modules/services/window-managers/sway/sway-check-config-precheck.nix b/tests/modules/services/window-managers/sway/sway-check-config-precheck.nix index a7aeb1b9..77ae2f1d 100644 --- a/tests/modules/services/window-managers/sway/sway-check-config-precheck.nix +++ b/tests/modules/services/window-managers/sway/sway-check-config-precheck.nix @@ -6,12 +6,15 @@ lib.mkIf config.test.enableBig { checkConfig = true; preCheckConfig = '' export HOME=$(mktemp -d) - touch ~/mybg.png + sed 's/mybg/otherbg/g' -i sway.conf + touch ~/otherbg.png ''; config.output."*".background = "~/mybg.png fill"; }; nmt.script = '' assertFileExists home-files/.config/sway/config + assertFileRegex home-files/.config/sway/config 'mybg\.png' + assertFileNotRegex home-files/.config/sway/config 'otherbg\.png' ''; }