From d38eb6f154dd6e34999ffaaaa5f516f32e03c08e Mon Sep 17 00:00:00 2001 From: Andrew Marshall Date: Sat, 20 Apr 2024 12:51:15 -0400 Subject: [PATCH] sway: do not use `pkgs.sway` when `cfg.package = null` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Implicitly disable checkConfig when `cfg.package = null` as we don’t have any exe to use for the check - Implicitly disable `swaymsg reload` on activation, since we have no exe to use for running it See https://github.com/nix-community/home-manager/issues/5307 --- .../services/window-managers/i3-sway/sway.nix | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index 4280fcd1e..ea763e95a 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -258,7 +258,6 @@ 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}"''; @@ -269,7 +268,7 @@ let 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 + ${pkgs.xvfb-run}/bin/xvfb-run ${cfg.package}/bin/sway --config "$target" --validate --unsupported-gpu ''; text = concatStringsSep "\n" @@ -362,7 +361,8 @@ in { 'wrapperFeatures', 'extraSessionCommands', and 'extraOptions'. Set to `null` to not add any Sway package to your path. This should be done if you want to use the NixOS Sway - module to install Sway. + module to install Sway. Beware setting to `null` will also disable + reloading Sway when new config is activated. ''; }; @@ -478,9 +478,9 @@ in { checkConfig = mkOption { type = types.bool; - default = true; - description = - "If enabled (the default), validates the generated config file."; + default = cfg.package != null; + defaultText = literalExpression "cfg.package != null"; + description = "If enabled, validates the generated config file."; }; extraConfig = mkOption { @@ -515,6 +515,11 @@ in { assertions = [ (hm.assertions.assertPlatform "wayland.windowManager.sway" pkgs platforms.linux) + { + assertion = cfg.checkConfig -> cfg.package != null; + message = + "programs.sway.checkConfig requires non-null programs.sway.package"; + } ]; home.packages = optional (cfg.package != null) cfg.package @@ -522,10 +527,10 @@ in { xdg.configFile."sway/config" = { source = configFile; - onChange = '' + onChange = lib.optionalString (cfg.package != null) '' swaySocket="''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep --uid $UID -x sway || true).sock" if [ -S "$swaySocket" ]; then - ${swayPackage}/bin/swaymsg -s $swaySocket reload + ${cfg.package}/bin/swaymsg -s $swaySocket reload fi ''; };