stylix icon indicating copy to clipboard operation
stylix copied to clipboard

[Bug] infinite recursion after commit f060e40

Open LovingMelody opened this issue 1 year ago • 14 comments

My nix flake is not experiencing an infinite recursion, commit f060e40 seems to be the cause

Trace

Partial trace below, (full trace here)

error:
     … while calling the 'head' builtin
       at /nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/lib/attrsets.nix:1575:11:
       1574|         || pred here (elemAt values 1) (head values) then
       1575|           head values
           |           ^
       1576|         else

     … while evaluating the attribute 'value'
       at /nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/lib/modules.nix:809:9:
        808|     in warnDeprecation opt //
        809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
           |         ^
        810|         inherit (res.defsFinal') highestPrio;

     … while evaluating the option `system.build.toplevel':

     … while evaluating definitions from `/nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/nixos/modules/system/activation/top-level.nix':

     … while evaluating the option `warnings':

     … while evaluating definitions from `/nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/nixos/modules/system/boot/systemd.nix':

     … while evaluating the option `systemd.services.home-manager-melody.serviceConfig':

     … while evaluating definitions from `/nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/flake.nix':

     … while evaluating the option `home-manager.users.melody.home.file.".wallpaper".source':

     … while evaluating definitions from `/nix/store/jimcgzcwnwdgflawmmrw267g0cjazlhm-bfd1chlasivs4wjggk57w0lbnxd1598k-source/modules/home/defaults/default.nix':

     … while evaluating the option `home-manager.users.melody.stylix.image':

     … while evaluating the option `home-manager.users.melody.stylix.base16Scheme':

     … while evaluating definitions from `/nix/store/9b7a9wchrbx1z6hn8sdjffl4zd83wf8y-source/nixos/common.nix':

     (stack trace truncated; use '--show-trace' to show the full, detailed trace)

     error: infinite recursion encountered
     at /nix/store/g0vjsr7387fzxdd889iws0k1qdq2qyjn-source/lib/modules.nix:809:9:
        808|     in warnDeprecation opt //
        809|       { value = builtins.addErrorContext "while evaluating the option `${showOption loc}':" value;
           |         ^
        810|         inherit (res.defsFinal') highestPrio;

LovingMelody avatar Jun 17 '24 02:06 LovingMelody

Could you share a minimum working example or your Nix flake?

trueNAHO avatar Jun 17 '24 07:06 trueNAHO

It's likely this in my config: https://gitlab.com/LovingMelody/configsreborn/-/blob/main/modules/shared/styles/default.nix?ref_type=heads I apply a lut based on the base16 colors to the image, I can try seeing if I can create a flake with just that..

LovingMelody avatar Jun 17 '24 18:06 LovingMelody

Update on this: unable to create a minimal config, but I did trace it back to changes made in stylix/nixos/default.nix EDIT: disabling stylix.homeManagerIntegration.followSystem also fixes this issue

LovingMelody avatar Jun 20 '24 02:06 LovingMelody

I was able to create a somewhat minimal config: https://gist.github.com/LovingMelody/be5dff6bd91e0cdbbb3de9416d036690

LovingMelody avatar Jun 23 '24 00:06 LovingMelody

I was able to create a somewhat minimal config: https://gist.github.com/LovingMelody/be5dff6bd91e0cdbbb3de9416d036690

Thanks! That helps a lot.

It seems your editImage function causes the infinite recursion based on how it captures its img argument. The following patch shamelessly resolves the infinite recursion error:

From 3c51400137c2411e8844b432023ebe945cbb9a4f Mon Sep 17 00:00:00 2001
From: NAHO <[email protected]>
Date: Sun, 23 Jun 2024 16:43:19 +0200
Subject: [PATCH] fix: avoid infinite recursion in 'stylix.image'

---
 flake.nix | 13 +------------
 1 file changed, 1 insertion(+), 12 deletions(-)

diff --git a/flake.nix b/flake.nix
index 8d6a97c..1ad68e1 100644
--- a/flake.nix
+++ b/flake.nix
@@ -90,18 +90,7 @@
           config = {
             stylix = {
               enable = true;
-              image =
-                let
-                  editImage =
-                    img:
-                    let
-                      baseName = builtins.baseNameOf img;
-                    in
-                    pkgs.runCommand baseName { } ''
-                      ${pkgs.lutgen}/bin/lutgen apply '${img}' -o $out -- ${colors}
-                    '';
-                in
-                editImage "${pkgs.pantheon.elementary-wallpapers}/backgrounds/odin-dark.jpg";
+              image = "${pkgs.pantheon.elementary-wallpapers}/backgrounds/odin-dark.jpg";
               polarity = "dark";
               base16Scheme = "${schemes}/base16/catppuccin-mocha.yaml";
             };
--
2.44.0

Maybe the problem lies in the stylix.image usage, rather than Stylix itself?

However, the build process still fails for another seemingly unrelated reason:

$ nixos-rebuild build --flake .#Style
building the system configuration...
error: builder for '/nix/store/h0plyb8hqbqfw8pgl4p7zn0w3x3bk78h-stylix-kde-theme.drv' failed with exit code 1;
       last 1 log lines:
       > magick: unable to open image '/nix/store/jmdd8lsvr2b6r274hhhh7kfdyvjbric9-elementary-wallpapers-7.0.0/backgrounds/odin-dark.jpg': No such file or directory @ error/blob.c/OpenBlob/3596.
       For full logs, run 'nix log /nix/store/h0plyb8hqbqfw8pgl4p7zn0w3x3bk78h-stylix-kde-theme.drv'.
error: 1 dependencies of derivation '/nix/store/bzyplnbd887hhf8k7xl8fq2ax1j7mzwc-activation-script.drv' failed to build
error: 1 dependencies of derivation '/nix/store/qi5brq66kdfj9sy78iiqfd969c52clx3-home-manager-path.drv' failed to build
error: 1 dependencies of derivation '/nix/store/vc6kcfml8r2g7z5ad78jcfy7wid8f29x-home-manager-generation.drv' failed to build
error: 1 dependencies of derivation '/nix/store/v3pd62hq2n1bw1f5bhva6fi7b97vri6d-user-environment.drv' failed to build
error: 1 dependencies of derivation '/nix/store/nswr79v7y8115sip0282c6nir1c47kpf-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/fyks5ylsrkfqc6a5l8j27k1r6zd775mg-nixos-system-nixos-24.11.20240622.9693852.drv' failed to build

trueNAHO avatar Jun 23 '24 14:06 trueNAHO

The issue isn't present before the fromOS change, it works without issue and properly edits the image applying the color scheme. This is even mentioned in tips and tricks

The build failure is because I forgot to specify .src for the wallpaper package

LovingMelody avatar Jun 23 '24 14:06 LovingMelody

I have updated the gist fixing the image path, if you were to update the stylix input to stylix.url = "github:danth/stylix/daac8f591f28f89b0301a80bcbea643efa2007ef"; the issue goes away if you need a reference commit.

LovingMelody avatar Jun 23 '24 15:06 LovingMelody

@danth, do you have an idea how to resolve this?

trueNAHO avatar Jun 23 '24 15:06 trueNAHO

Could it somehow be referencing an automatically generated color scheme when you use ${colors}? Since that would depend on the final image.

danth avatar Jun 24 '24 13:06 danth

Looking back over this issue, my guess is it is from this line https://github.com/danth/stylix/blob/1ff9d37d27377bfe8994c24a8d6c6c1734ffa116/stylix/palette.nix#L110

It previously was a condition:

      default =
        if cfg.image != fromOs [ "image" ] null
          then generatedScheme
          else fromOs [ "base16Scheme" ] generatedScheme;

LovingMelody avatar Jul 04 '24 07:07 LovingMelody

While working on another feature, I noticed this which doesn't seem correct: https://github.com/danth/stylix/blob/f060e4059b408b2cc1891ce655d0f6bef4e21a5b/stylix/home-manager-integration.nix#L14-L17 The base16Scheme is not always linked to image, as the user is able to define the theme as well...

LovingMelody avatar Jul 19 '24 21:07 LovingMelody

That condition exists so that if you explicitly set a wallpaper in Home Manager, and it's different to the wallpaper used in NixOS, then it won't copy the color scheme over so that you're able to access the generated scheme from that new wallpaper, if you wanted to do so. The user has to explicitly set their chosen color scheme again in Home Manager for it to not do that.

This could probably be refined by changing the format of the options somehow

danth avatar Jul 20 '24 16:07 danth

This condition may be what's causing the infinite recursion as it's now referencing the generated color scheme (I believe?) when pulling the colors.

LovingMelody avatar Jul 20 '24 16:07 LovingMelody

I have the same issue.

Fixing stylix to the commit daac8f591f28f89b0301a80bcbea643efa2007ef (the parent of f060e40), seems to 'fix' the issue.

cgahr avatar Aug 26 '24 08:08 cgahr

is anyone still having this issue?

0xda157 avatar Apr 05 '25 22:04 0xda157

This issue is still present and can be easily recreated, see https://github.com/danth/stylix/issues/437#issuecomment-2184255931

LovingMelody avatar Apr 06 '25 02:04 LovingMelody