From b2dec35b86e8488831734ff7936589d710b47420 Mon Sep 17 00:00:00 2001 From: Michal Sojka Date: Fri, 7 May 2021 23:39:10 +0200 Subject: [PATCH] Fix eval errors when i3 or sway null configs are null (#1989) --- .../services/window-managers/i3-sway/i3.nix | 4 +- .../services/window-managers/i3-sway/sway.nix | 60 ++++++++++--------- .../services/window-managers/i3/default.nix | 1 + .../i3/i3-fonts-deprecated.nix | 12 +--- .../services/window-managers/i3/i3-fonts.nix | 12 +--- .../window-managers/i3/i3-keybindings.nix | 11 +--- .../window-managers/i3/i3-null-config.nix | 20 +++++++ .../window-managers/i3/i3-overlay.nix | 12 ++++ .../services/window-managers/sway/default.nix | 1 + .../window-managers/sway/sway-default.nix | 12 +--- .../sway/sway-followmouse-legacy.nix | 16 +---- .../window-managers/sway/sway-followmouse.nix | 13 +--- .../window-managers/sway/sway-modules.nix | 12 +--- .../window-managers/sway/sway-null-config.nix | 22 +++++++ .../sway/sway-null-package.nix | 12 +--- .../window-managers/sway/sway-overlay.nix | 17 ++++++ .../window-managers/sway/sway-post-2003.nix | 12 +--- 17 files changed, 116 insertions(+), 133 deletions(-) create mode 100644 tests/modules/services/window-managers/i3/i3-null-config.nix create mode 100644 tests/modules/services/window-managers/i3/i3-overlay.nix create mode 100644 tests/modules/services/window-managers/sway/sway-null-config.nix create mode 100644 tests/modules/services/window-managers/sway/sway-overlay.nix diff --git a/modules/services/window-managers/i3-sway/i3.nix b/modules/services/window-managers/i3-sway/i3.nix index b213635e2..635b74d7e 100644 --- a/modules/services/window-managers/i3-sway/i3.nix +++ b/modules/services/window-managers/i3-sway/i3.nix @@ -258,14 +258,14 @@ in { mkDefault (if (cfg.config.gaps != null) then pkgs.i3-gaps else pkgs.i3); }) - { + (mkIf (cfg.config != null) { warnings = (optional (isList cfg.config.fonts) "Specifying i3.config.fonts as a list is deprecated. Use the attrset version instead.") ++ flatten (map (b: optional (isList b.fonts) "Specifying i3.config.bars[].fonts as a list is deprecated. Use the attrset version instead.") cfg.config.bars); - } + }) (mkIf (cfg.config != null && (any (s: s.workspace != null) cfg.config.startup)) { diff --git a/modules/services/window-managers/i3-sway/sway.nix b/modules/services/window-managers/i3-sway/sway.nix index ff0531d0a..55672581f 100644 --- a/modules/services/window-managers/i3-sway/sway.nix +++ b/modules/services/window-managers/i3-sway/sway.nix @@ -410,34 +410,38 @@ in { }; }; - config = mkIf cfg.enable { - warnings = (optional (isList cfg.config.fonts) - "Specifying sway.config.fonts as a list is deprecated. Use the attrset version instead.") - ++ flatten (map (b: - optional (isList b.fonts) - "Specifying sway.config.bars[].fonts as a list is deprecated. Use the attrset version instead.") - cfg.config.bars); + config = mkIf cfg.enable (mkMerge [ + (mkIf (cfg.config != null) { + warnings = (optional (isList cfg.config.fonts) + "Specifying sway.config.fonts as a list is deprecated. Use the attrset version instead.") + ++ flatten (map (b: + optional (isList b.fonts) + "Specifying sway.config.bars[].fonts as a list is deprecated. Use the attrset version instead.") + cfg.config.bars); + }) - home.packages = optional (cfg.package != null) cfg.package - ++ optional cfg.xwayland pkgs.xwayland; - xdg.configFile."sway/config" = { - source = configFile; - onChange = '' - swaySocket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep -x sway || ${pkgs.coreutils}/bin/true).sock - if [ -S $swaySocket ]; then - echo "Reloading sway" - $DRY_RUN_CMD ${pkgs.sway}/bin/swaymsg -s $swaySocket reload - fi - ''; - }; - systemd.user.targets.sway-session = mkIf cfg.systemdIntegration { - Unit = { - Description = "sway compositor session"; - Documentation = [ "man:systemd.special(7)" ]; - BindsTo = [ "graphical-session.target" ]; - Wants = [ "graphical-session-pre.target" ]; - After = [ "graphical-session-pre.target" ]; + { + home.packages = optional (cfg.package != null) cfg.package + ++ optional cfg.xwayland pkgs.xwayland; + xdg.configFile."sway/config" = { + source = configFile; + onChange = '' + swaySocket=''${XDG_RUNTIME_DIR:-/run/user/$UID}/sway-ipc.$UID.$(${pkgs.procps}/bin/pgrep -x sway || ${pkgs.coreutils}/bin/true).sock + if [ -S $swaySocket ]; then + echo "Reloading sway" + $DRY_RUN_CMD ${pkgs.sway}/bin/swaymsg -s $swaySocket reload + fi + ''; }; - }; - }; + systemd.user.targets.sway-session = mkIf cfg.systemdIntegration { + Unit = { + Description = "sway compositor session"; + Documentation = [ "man:systemd.special(7)" ]; + BindsTo = [ "graphical-session.target" ]; + Wants = [ "graphical-session-pre.target" ]; + After = [ "graphical-session-pre.target" ]; + }; + }; + } + ]); } diff --git a/tests/modules/services/window-managers/i3/default.nix b/tests/modules/services/window-managers/i3/default.nix index af48aef45..ed63af781 100644 --- a/tests/modules/services/window-managers/i3/default.nix +++ b/tests/modules/services/window-managers/i3/default.nix @@ -3,4 +3,5 @@ i3-fonts = ./i3-fonts.nix; i3-fonts-deprecated = ./i3-fonts-deprecated.nix; i3-keybindings = ./i3-keybindings.nix; + i3-null-config = ./i3-null-config.nix; } diff --git a/tests/modules/services/window-managers/i3/i3-fonts-deprecated.nix b/tests/modules/services/window-managers/i3/i3-fonts-deprecated.nix index fd11ac51a..c5142ed45 100644 --- a/tests/modules/services/window-managers/i3/i3-fonts-deprecated.nix +++ b/tests/modules/services/window-managers/i3/i3-fonts-deprecated.nix @@ -13,17 +13,7 @@ with lib; }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = super.dmenu // { outPath = "@dmenu@"; }; - - i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; }; - - i3-gaps = super.writeScriptBin "i3" "" // { outPath = "@i3-gaps@"; }; - - i3status = super.i3status // { outPath = "@i3status@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/i3/config diff --git a/tests/modules/services/window-managers/i3/i3-fonts.nix b/tests/modules/services/window-managers/i3/i3-fonts.nix index e594f6363..20ea5cabe 100644 --- a/tests/modules/services/window-managers/i3/i3-fonts.nix +++ b/tests/modules/services/window-managers/i3/i3-fonts.nix @@ -22,17 +22,7 @@ with lib; }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = super.dmenu // { outPath = "@dmenu@"; }; - - i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; }; - - i3-gaps = super.writeScriptBin "i3" "" // { outPath = "@i3-gaps@"; }; - - i3status = super.i3status // { outPath = "@i3status@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/i3/config diff --git a/tests/modules/services/window-managers/i3/i3-keybindings.nix b/tests/modules/services/window-managers/i3/i3-keybindings.nix index 0458b8744..bc3cae6e0 100644 --- a/tests/modules/services/window-managers/i3/i3-keybindings.nix +++ b/tests/modules/services/window-managers/i3/i3-keybindings.nix @@ -16,16 +16,7 @@ with lib; }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = super.dmenu // { outPath = "@dmenu@"; }; - i3 = super.writeScriptBin "i3" "" // { outPath = "@i3@"; }; - i3-gaps = super.writeScriptBin "i3-gaps" "" // { - outPath = "@i3-gaps@"; - }; - i3status = super.i3status // { outPath = "@i3status@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/i3/config diff --git a/tests/modules/services/window-managers/i3/i3-null-config.nix b/tests/modules/services/window-managers/i3/i3-null-config.nix new file mode 100644 index 000000000..a9b378824 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-null-config.nix @@ -0,0 +1,20 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + xsession.windowManager.i3 = { + enable = true; + config = null; + }; + + nixpkgs.overlays = [ (import ./i3-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/i3/config + assertFileContent home-files/.config/i3/config \ + ${pkgs.writeText "expected" "\n"} + ''; + }; +} diff --git a/tests/modules/services/window-managers/i3/i3-overlay.nix b/tests/modules/services/window-managers/i3/i3-overlay.nix new file mode 100644 index 000000000..fead262f4 --- /dev/null +++ b/tests/modules/services/window-managers/i3/i3-overlay.nix @@ -0,0 +1,12 @@ +self: super: +# Avoid unnecessary downloads in CI jobs and/or make out paths +# constant, i.e., not containing hashes, version numbers etc. +{ + dmenu = super.dmenu // { outPath = "@dmenu@"; }; + + 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/sway/default.nix b/tests/modules/services/window-managers/sway/default.nix index f81b510fe..662f6357e 100644 --- a/tests/modules/services/window-managers/sway/default.nix +++ b/tests/modules/services/window-managers/sway/default.nix @@ -3,6 +3,7 @@ sway-post-2003 = ./sway-post-2003.nix; sway-followmouse = ./sway-followmouse.nix; sway-followmouse-legacy = ./sway-followmouse-legacy.nix; + sway-null-config = ./sway-null-config.nix; sway-null-package = ./sway-null-package.nix; sway-modules = ./sway-modules.nix; } diff --git a/tests/modules/services/window-managers/sway/sway-default.nix b/tests/modules/services/window-managers/sway/sway-default.nix index 0ccedbfda..141f6303e 100644 --- a/tests/modules/services/window-managers/sway/sway-default.nix +++ b/tests/modules/services/window-managers/sway/sway-default.nix @@ -15,17 +15,7 @@ in { config.menu = "${pkgs.dmenu}/bin/dmenu_run"; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - i3status = dummy-package // { outPath = "@i3status@"; }; - sway = dummy-package // { outPath = "@sway@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/sway/config diff --git a/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix index 9ed0ceaf0..b83c8d1ba 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix +++ b/tests/modules/services/window-managers/sway/sway-followmouse-legacy.nix @@ -19,21 +19,7 @@ in { }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - sway = dummy-package // { outPath = "@sway@"; }; - sway-unwrapped = dummy-package // { - outPath = "@sway-unwrapped@"; - version = "1"; - }; - swaybg = dummy-package // { outPath = "@swaybg@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/sway/config diff --git a/tests/modules/services/window-managers/sway/sway-followmouse.nix b/tests/modules/services/window-managers/sway/sway-followmouse.nix index 8d54eccf7..9d18b6913 100644 --- a/tests/modules/services/window-managers/sway/sway-followmouse.nix +++ b/tests/modules/services/window-managers/sway/sway-followmouse.nix @@ -19,18 +19,7 @@ in { }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - sway = dummy-package // { outPath = "@sway@"; }; - sway-unwrapped = dummy-package // { version = "1"; }; - swaybg = dummy-package // { outPath = "@swaybg@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/sway/config diff --git a/tests/modules/services/window-managers/sway/sway-modules.nix b/tests/modules/services/window-managers/sway/sway-modules.nix index bc0df9bda..fbe927f35 100644 --- a/tests/modules/services/window-managers/sway/sway-modules.nix +++ b/tests/modules/services/window-managers/sway/sway-modules.nix @@ -21,17 +21,7 @@ in { }; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - i3status = dummy-package // { outPath = "@i3status@"; }; - sway = dummy-package // { outPath = "@sway@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/sway/config diff --git a/tests/modules/services/window-managers/sway/sway-null-config.nix b/tests/modules/services/window-managers/sway/sway-null-config.nix new file mode 100644 index 000000000..fc01660cb --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-null-config.nix @@ -0,0 +1,22 @@ +{ config, lib, pkgs, ... }: + +with lib; + +{ + config = { + wayland.windowManager.sway = { + enable = true; + config = null; + systemdIntegration = false; + package = pkgs.sway; + }; + + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; + + nmt.script = '' + assertFileExists home-files/.config/sway/config + assertFileContent home-files/.config/sway/config \ + ${pkgs.writeText "expected" "\n"} + ''; + }; +} diff --git a/tests/modules/services/window-managers/sway/sway-null-package.nix b/tests/modules/services/window-managers/sway/sway-null-package.nix index cceebc2a1..3993d6389 100644 --- a/tests/modules/services/window-managers/sway/sway-null-package.nix +++ b/tests/modules/services/window-managers/sway/sway-null-package.nix @@ -17,17 +17,7 @@ in { config.menu = "${pkgs.dmenu}/bin/dmenu_run"; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - i3status = dummy-package // { outPath = "@i3status@"; }; - sway = dummy-package // { outPath = "@sway@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; assertions = [{ assertion = diff --git a/tests/modules/services/window-managers/sway/sway-overlay.nix b/tests/modules/services/window-managers/sway/sway-overlay.nix new file mode 100644 index 000000000..4edfb2055 --- /dev/null +++ b/tests/modules/services/window-managers/sway/sway-overlay.nix @@ -0,0 +1,17 @@ +self: super: +# Avoid unnecessary downloads in CI jobs. +let dummy-package = super.runCommandLocal "dummy-package" { } "mkdir $out"; +in { + dmenu = dummy-package // { outPath = "@dmenu@"; }; + rxvt-unicode-unwrapped = dummy-package // { + outPath = "@rxvt-unicode-unwrapped@"; + }; + i3status = dummy-package // { outPath = "@i3status@"; }; + sway = dummy-package // { outPath = "@sway@"; }; + sway-unwrapped = dummy-package // { + outPath = "@sway-unwrapped@"; + version = "1"; + }; + swaybg = dummy-package // { outPath = "@swaybg@"; }; + xwayland = dummy-package // { outPath = "@xwayland@"; }; +} diff --git a/tests/modules/services/window-managers/sway/sway-post-2003.nix b/tests/modules/services/window-managers/sway/sway-post-2003.nix index 740e7e526..ddcf2b234 100644 --- a/tests/modules/services/window-managers/sway/sway-post-2003.nix +++ b/tests/modules/services/window-managers/sway/sway-post-2003.nix @@ -17,17 +17,7 @@ in { config.menu = "${pkgs.dmenu}/bin/dmenu_run"; }; - nixpkgs.overlays = [ - (self: super: { - dmenu = dummy-package // { outPath = "@dmenu@"; }; - rxvt-unicode-unwrapped = dummy-package // { - outPath = "@rxvt-unicode-unwrapped@"; - }; - sway = dummy-package // { outPath = "@sway@"; }; - i3status = dummy-package // { outPath = "@i3status@"; }; - xwayland = dummy-package // { outPath = "@xwayland@"; }; - }) - ]; + nixpkgs.overlays = [ (import ./sway-overlay.nix) ]; nmt.script = '' assertFileExists home-files/.config/sway/config