sway: check config file validity

Helps avoid successful build but Sway failing to start.

To meaningfully test this, I had to actually use `pkgs.sway` in the
test rather than the stub, but left all other tests using the stub and
changed them to skipping the test.

We need to pass `--unsupported-gpu` as Sway checks for `nvidia` in
`/proc/modules`, and the Nix sandbox has `/proc/modules` available.
This commit is contained in:
Andrew Marshall 2023-11-09 13:19:45 -05:00 committed by Robert Helgesson
parent 95888b153c
commit 3a435342e2
No known key found for this signature in database
GPG key ID: 96E745BD17AA17ED
17 changed files with 46 additions and 5 deletions

View file

@ -258,12 +258,21 @@ let
variables = concatStringsSep " " cfg.systemd.variables;
extraCommands = concatStringsSep " && " cfg.systemd.extraCommands;
swayPackage = if cfg.package == null then pkgs.sway else cfg.package;
systemdActivation = ''
exec "${pkgs.dbus}/bin/dbus-update-activation-environment --systemd ${variables}; ${extraCommands}"'';
configFile = pkgs.writeTextFile {
name = "sway.conf";
text = (concatStringsSep "\n"
# Sway always does some init, see https://github.com/swaywm/sway/issues/4691
checkPhase = lib.optionalString cfg.checkConfig ''
export DBUS_SESSION_BUS_ADDRESS=/dev/null
export XDG_RUNTIME_DIR=$(mktemp -d)
${pkgs.xvfb-run}/bin/xvfb-run ${swayPackage}/bin/sway --config "$target" --validate --unsupported-gpu
'';
text = concatStringsSep "\n"
((optional (cfg.extraConfigEarly != "") cfg.extraConfigEarly)
++ (if cfg.config != null then
with cfg.config;
@ -319,7 +328,7 @@ let
else
[ ]) ++ (optional cfg.systemd.enable systemdActivation)
++ (optional (!cfg.xwayland) "xwayland disable")
++ [ cfg.extraConfig ]));
++ [ cfg.extraConfig ]);
};
defaultSwayPackage = pkgs.sway.override {
@ -469,6 +478,13 @@ in {
description = "Sway configuration options.";
};
checkConfig = mkOption {
type = types.bool;
default = true;
description =
"If enabled (the default), validates the generated config file.";
};
extraConfig = mkOption {
type = types.lines;
default = "";
@ -506,9 +522,7 @@ in {
home.packages = optional (cfg.package != null) cfg.package
++ optional cfg.xwayland pkgs.xwayland;
xdg.configFile."sway/config" = let
swayPackage = if cfg.package == null then pkgs.sway else cfg.package;
in {
xdg.configFile."sway/config" = {
source = configFile;
onChange = ''
swaySocket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep --uid $UID -x sway || true).sock"

View file

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

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";
config.bindkeysToCode = true;

View file

@ -0,0 +1,12 @@
{ config, lib, ... }:
lib.mkIf config.test.enableBig {
wayland.windowManager.sway = {
enable = true;
checkConfig = true;
};
nmt.script = ''
assertFileExists home-files/.config/sway/config
'';
}

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";
};

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
config = {
focus.followMouse = false;

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
config = {
focus.followMouse = "always";

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config = {
menu = "${pkgs.dmenu}/bin/dmenu_run";

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
config = null;
systemd.enable = false;
xwayland = false;

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
config = null;
systemd.enable = false;
};

View file

@ -9,6 +9,7 @@
wayland.windowManager.sway = {
enable = true;
package = null;
checkConfig = false;
config.menu = "${pkgs.dmenu}/bin/dmenu_run";
};

View file

@ -8,6 +8,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";
};

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";

View file

@ -6,6 +6,7 @@
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";
config.defaultWorkspace = "workspace number 9";

View file

@ -15,6 +15,7 @@ in {
wayland.windowManager.sway = {
enable = true;
package = config.lib.test.mkStubPackage { outPath = "@sway@"; };
checkConfig = false;
# overriding findutils causes issues
config.menu = "${pkgs.dmenu}/bin/dmenu_run";