danth / stylix

System-wide colorscheming and typography for NixOS
https://stylix.danth.me/
MIT License
902 stars 105 forks source link

[Bug] infinite recursion after commit f060e40 #437

Open LovingMelody opened 2 weeks ago

LovingMelody commented 2 weeks ago

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

Trace Partial trace below, ([full trace here](https://gist.github.com/LovingMelody/b3a5a03e75ec85acc080b88b274d1bc8)) ```nix 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; ```
trueNAHO commented 1 week ago

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

LovingMelody commented 1 week ago

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 commented 1 week ago

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 commented 1 week ago

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

trueNAHO commented 1 week ago

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 <90870942+trueNAHO@users.noreply.github.com>
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
LovingMelody commented 1 week ago

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 commented 1 week ago

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.

trueNAHO commented 1 week ago

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

danth commented 6 days ago

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