sway: add preCheckConfig to customize check environment

See e.g. https://github.com/nix-community/home-manager/issues/5311
This commit is contained in:
Andrew Marshall 2024-04-21 09:19:48 -04:00
parent 4cec20dbf5
commit 66a558e507
3 changed files with 32 additions and 0 deletions

View file

@ -269,6 +269,7 @@ let
checkPhase = lib.optionalString cfg.checkConfig '' checkPhase = lib.optionalString cfg.checkConfig ''
export DBUS_SESSION_BUS_ADDRESS=/dev/null export DBUS_SESSION_BUS_ADDRESS=/dev/null
export XDG_RUNTIME_DIR=$(mktemp -d) export XDG_RUNTIME_DIR=$(mktemp -d)
${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 "$target" --validate --unsupported-gpu
''; '';
@ -478,6 +479,19 @@ in {
description = "Sway configuration options."; description = "Sway configuration options.";
}; };
preCheckConfig = mkOption {
type = types.lines;
default = "";
example = ''
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`.
'';
};
checkConfig = mkOption { checkConfig = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;

View file

@ -6,6 +6,7 @@
sway-followmouse = ./sway-followmouse.nix; sway-followmouse = ./sway-followmouse.nix;
sway-followmouse-legacy = ./sway-followmouse-legacy.nix; sway-followmouse-legacy = ./sway-followmouse-legacy.nix;
sway-check-config = ./sway-check-config.nix; sway-check-config = ./sway-check-config.nix;
sway-check-config-precheck = ./sway-check-config-precheck.nix;
sway-modules = ./sway-modules.nix; sway-modules = ./sway-modules.nix;
sway-no-xwayland = ./sway-no-xwayland.nix; sway-no-xwayland = ./sway-no-xwayland.nix;
sway-null-config = ./sway-null-config.nix; sway-null-config = ./sway-null-config.nix;

View file

@ -0,0 +1,17 @@
{ config, lib, ... }:
lib.mkIf config.test.enableBig {
wayland.windowManager.sway = {
enable = true;
checkConfig = true;
preCheckConfig = ''
export HOME=$(mktemp -d)
touch ~/mybg.png
'';
config.output."*".background = "~/mybg.png fill";
};
nmt.script = ''
assertFileExists home-files/.config/sway/config
'';
}