Help with infinite recursion

Im trying to unify my darwin and nixos module for stylix but get infinite recursion when importing stylix modules:

{
  config,
  lib,
  pkgs,
  inputs,
  ...
}:
let
  cfg = config.modules.stylix;
  inherit (pkgs.stdenv) isDarwin;
in
{
  imports = [
    (if isDarwin then inputs.stylix.darwinModules.stylix else inputs.stylix.nixosModules.stylix)
    # inputs.stylix.nixosModules.stylix
  ];

  options.modules.stylix = {
    enable = lib.mkEnableOption "enable stylix module";
  };

  config = lib.mkIf cfg.enable {
    stylix = {

      ## temp untill 25.05 release of stylix
      # https://github.com/nix-community/stylix/issues/1277
      enableReleaseChecks = false;

      enable = true;
      autoEnable = true;
      polarity = "dark";
      base16Scheme = "${pkgs.base16-schemes}/share/themes/catppuccin-mocha.yaml";
      # image = ../../assets/wallpapers/1CA1273E-9951-440E-A4DB-3BFFB7EB4346.png;
      # image = "${inputs.wallpapers}/series/steven universe/barn.png";
      image = builtins.fetchurl {
        url = "https://gitlab.com/Felipe-Pinto/wallpapers/-/blob/e173091770ecf5a911f6f01f9b7dafc23081f4bc/series/steven%20universe/barn.png";
        sha256 = "sha256:0y9wx0qwfj0rcdwv6my0lvyxhxpj6rm9f4gw8mk27ap99hmry85c";
      };

      opacity = {
        applications = 0.9;
        desktop = 0.9;
        popups = 0.9;
        terminal = 0.9;
      };

      cursor = {
        package = pkgs.bibata-cursors;
        name = "Bibata-Modern-Classic";
        size = 24;
      };

      fonts = {
        sizes = {
          terminal = 20;
          desktop = 14;
          applications = 14;
          popups = 16;
        };
        # monospace = {
        #   package = pkgs.nerdfonts.override {fonts=["FiraCode"];};
        #   name = "FiraCode";
        # };
        sansSerif = {
          package = pkgs.source-sans;
          name = "SourceSans3";
        };
        serif = {
          package = pkgs.source-serif;
          name = "SourceSerif4";
        };
        monospace = {
          package = pkgs.nerd-fonts.fira-code;
          name = "FiraCode";
        };
      };

      targets = lib.genAttrs [ "nixvim" ] (_: {
        enable = false;
      });

    };
  };
}

You need to import both and then set stylix.enable = pkgs.hostPlatform.isDarwin in the darwin module, and repeat for nixos in the other. You can’t conditionally import by depending inputs to the modules.

sorry, Im having some trouble understanding, I intend to have this file active for both configurations.

Right and my point is that currently you have

enable = true

I am saying make that enable = <<expr depending on host platform>> therefore if you import both and enable them conditionally then in reality only one will be active at a time.

I have a similar snippet in my home manager config

{ sources, ... }:
let
  darwinTargets =
    { pkgs, ... }:
    {
      imports = [ (import sources.mac-app-util { }).homeManagerModules.default ];

      # This controls whether the import above is active.
      targets.darwin.mac-app-util.enable = pkgs.hostPlatform.isDarwin;
    };
  catppuccin = sources.catppuccin + "/modules/home-manager";
in
{
  home.packages = [
    darwinTargets
    catppuccin
  ];
}

Notice how I import the darwin specific module unconditionally but conditionally enable it? I run this file on both mac and linux no problem.

Well… im still confused, how bout an example?

On my darwin machine i want stylix enabled so i have on the configuration:

config.stylix.enable = true;

on my nixos machine i also want stylix enabled, so i have:

config.stylix.enable = true;

The way i see both cases are enabled. so independent o host platform i want this module enabled.

I see how you are using the enable on your config, but in your case you only want the mac-app-utill enabled on darwin systems… it differs on my case as both modules import options for stylix which i want enabled for both my darwin and nixos configs…

your example would only be usefull if we could somehow disable the specific stylix.nixosModules.stylix on a darwin machine…my knowledge in nix is limited, if you know how to do that, could you tell me?

I’m unfamiliar with stylix, others might be more able to help, but this: Tips and tricks - Stylix seems very promising.

1 Like

i will be looking onto it, thanks.
for now i settled with having the import on the definition of the system (similar on how the manual explains it), unfortunately systems that wont use stylix will still have this module imported even if its disabled, but i guess it would always have been the case. i guess this is a solution.