From 9d433a6b1a44670ac1bf7e37e107a63ee04d32eb Mon Sep 17 00:00:00 2001 From: Daniel Thwaites Date: Mon, 24 Feb 2025 19:07:51 +0000 Subject: [PATCH] swaylock: attempt to avoid infinite recursion (#899) Although the initial pull request was approved [1], a conversation on Matrix suggests that infinite recursion is indeed possible in certain cases [2]. [1]: https://github.com/danth/stylix/pull/875 [2]: https://matrix.to/#/!FBhBUKKFkbUIElLvaF:danth.me/$yZz3nJYu9RgaN3736fxF1xY0BfzceGRSsvpiXSq6go4 --- modules/swaylock/hm.nix | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/modules/swaylock/hm.nix b/modules/swaylock/hm.nix index d03c0e9c..d9278e3a 100644 --- a/modules/swaylock/hm.nix +++ b/modules/swaylock/hm.nix @@ -37,7 +37,16 @@ in }) ]; options.stylix.targets.swaylock = { - enable = config.lib.stylix.mkEnableTarget "Swaylock" true; + enable = + config.lib.stylix.mkEnableTarget "Swaylock" + # When the state version is older than 23.05, Swaylock enables itself + # automatically if `settings != {}` [1]. Therefore, Swaylock theming + # shouldn't be enabled by default for such state versions, to avoid + # inadvertently installing Swaylock when it's not desired. + # + # [1]: https://github.com/nix-community/home-manager/blob/5cfbf5cc37a3bd1da07ae84eea1b828909c4456b/modules/programs/swaylock.nix#L12-L17 + (lib.versionAtLeast config.home.stateVersion "23.05"); + useWallpaper = config.lib.stylix.mkEnableWallpaper "Swaylock" true; }; @@ -47,13 +56,12 @@ in config.stylix.enable && config.stylix.targets.swaylock.enable && pkgs.stdenv.hostPlatform.isLinux - - # Avoid inadvertently installing the Swaylock package by preventing the - # Home Manager module from enabling itself when 'settings != {}' and the - # state version is older than 23.05 [1]. + # Adding `&& config.programs.swaylock.enable` here may lead to infinite + # recursion, due to the default value depending on `settings != {}` + # when the state version is older than 23.05 [1], and the content of + # this module affecting that default. # # [1]: https://github.com/nix-community/home-manager/blob/5cfbf5cc37a3bd1da07ae84eea1b828909c4456b/modules/programs/swaylock.nix#L12-L17 - && config.programs.swaylock.enable ) { programs.swaylock.settings =