Stylix colors in home.file

I have been trying for hours to get this working. I can get stylix working everywhere but neovim. I don’t configure neovim with nix, so I’m trying to create a lua file with the stylix colors in it. When I import this file into my home.nix I get the errors below it.

{ pkgs, config, ... }:
{
  target = "/home/dot/.config/nvim/lua/dot/plugins/mini.base16.lua";
  text = ''
    return {
      "nvim-mini/mini.base16",
      version = "*",
      config = {
        palette = {
          base00 = "#${config.lib.stylix.colors.base00}",
          base01 = "#${config.lib.stylix.colors.base01}",
          base02 = "#${config.lib.stylix.colors.base02}",
          base03 = "#${config.lib.stylix.colors.base03}",
          base04 = "#${config.lib.stylix.colors.base04}",
          base05 = "#${config.lib.stylix.colors.base05}",
          base06 = "#${config.lib.stylix.colors.base06}",
          base07 = "#${config.lib.stylix.colors.base07}",
          base08 = "#${config.lib.stylix.colors.base08}",
          base09 = "#${config.lib.stylix.colors.base09}",
          base0A = "#${config.lib.stylix.colors.base0A}",
          base0B = "#${config.lib.stylix.colors.base0B}",
          base0C = "#${config.lib.stylix.colors.base0C}",
          base0D = "#${config.lib.stylix.colors.base0D}",
          base0E = "#${config.lib.stylix.colors.base0E}",
          base0F = "#${config.lib.stylix.colors.base0F}",
        },
        use_cterm = true,
        plugins = { default = true },
      },
    }
  '';
}

here’s the end of the output from running sudo nixos-rebuild switch --flake . --show-trace

       … while evaluating the attribute 'value'
         at /nix/store/dij35qckkzfiqry7jrsq34qvc5xxp90q-source/lib/modules.nix:1083:7:
         1082|     // {
         1083|       value = addErrorContext "while evaluating the option `${showOption loc}':" value;
             |       ^
         1084|       inherit (res.defsFinal') highestPrio;

       … while evaluating the option `home-manager.users.dot.home.file.nvimColors.text':

       (10 duplicate frames omitted)

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

       … from call site
         at /nix/store/dij35qckkzfiqry7jrsq34qvc5xxp90q-source/lib/modules.nix:1109:80:
         1108|               }
         1109|           ) (addErrorContext "while evaluating definitions from `${m.file}':" (dischargeProperties m.value))
             |                                                                                ^
         1110|         ) defs;

       … while calling 'dischargeProperties'
         at /nix/store/dij35qckkzfiqry7jrsq34qvc5xxp90q-source/lib/modules.nix:1202:5:
         1201|   dischargeProperties =
         1202|     def:
             |     ^
         1203|     if def._type or "" == "merge" then

       … while evaluating a branch condition
         at /nix/store/dij35qckkzfiqry7jrsq34qvc5xxp90q-source/lib/modules.nix:1203:5:
         1202|     def:
         1203|     if def._type or "" == "merge" then
             |     ^
         1204|       concatMap dischargeProperties def.contents

       … while evaluating the attribute 'value'
         at /nix/store/dij35qckkzfiqry7jrsq34qvc5xxp90q-source/lib/modules.nix:770:21:
          769|             inherit (module) file;
          770|             inherit value;
             |                     ^
          771|           }) module.config

       error: attribute 'lib' missing
       at /nix/store/f6wdnqi6gjmf95yj3gcqirxcwyka4qvs-source/config/nvimColors.nix:10:24:
            9|         palette = {
           10|           base00 = "#${config.lib.stylix.colors.base00}",
             |                        ^
           11|           base01 = "#${config.lib.stylix.colors.base01}",

here’s my flake:

{
  description = "dottie's a flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay";
    home-manager.url = "github:nix-community/home-manager/release-25.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    sops-nix.url = "github:Mic92/sops-nix";
    stylix = {
      url = "github:nix-community/stylix/release-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{
    # self,
    nixpkgs,
    nixpkgs-unstable,
    nixos-hardware,
    home-manager,
    sops-nix,
    stylix,
    ...
    }: {
      nixosConfigurations.nixos =  nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = {
          inherit inputs;
          unstable = import nixpkgs-unstable {
            system = "x86_64-linux";
            config.allowUnfree = true;
            # config.allowUnfreePredicate = pkg: true;
          };
        };
        modules = [
          # Import the previous configuration.nix we used,
          # so the old configuration file still takes effect
          ./configuration.nix
          stylix.nixosModules.stylix
          nixos-hardware.nixosModules.framework-13th-gen-intel
          home-manager.nixosModules.home-manager
          sops-nix.nixosModules.sops
          {
            nixpkgs.config.allowUnfree = true;
            home-manager.sharedModules = [
              sops-nix.homeManagerModules.sops
              stylix.homeModules.stylix
            ];
            # home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.dot.imports = [
              ({ config, ... }: import ./home.nix {
              pkgs = import nixpkgs {
               system = "x86_64-linux";
               config.allowUnfree = true;
              };
              unstable = import nixpkgs-unstable {
               system = "x86_64-linux";
               config.allowUnfree = true;
              };
              inherit config inputs nixpkgs nixpkgs-unstable stylix;
              })
            ];
          }
        ];
      };
  };
}

1 Like

Try import lib

{ pkgs, lib, config, ... }:
{
  target = "/home/dot/.config/nvim/lua/dot/plugins/mini.base16.lua";
  text = ''
    return {
      "nvim-mini/mini.base16",
      version = "*",
      config = {
        palette = {
          base00 = "#${config.lib.stylix.colors.base00}",
          base01 = "#${config.lib.stylix.colors.base01}",
          base02 = "#${config.lib.stylix.colors.base02}",
          base03 = "#${config.lib.stylix.colors.base03}",
          base04 = "#${config.lib.stylix.colors.base04}",
          base05 = "#${config.lib.stylix.colors.base05}",
          base06 = "#${config.lib.stylix.colors.base06}",
          base07 = "#${config.lib.stylix.colors.base07}",
          base08 = "#${config.lib.stylix.colors.base08}",
          base09 = "#${config.lib.stylix.colors.base09}",
          base0A = "#${config.lib.stylix.colors.base0A}",
          base0B = "#${config.lib.stylix.colors.base0B}",
          base0C = "#${config.lib.stylix.colors.base0C}",
          base0D = "#${config.lib.stylix.colors.base0D}",
          base0E = "#${config.lib.stylix.colors.base0E}",
          base0F = "#${config.lib.stylix.colors.base0F}",
        },
        use_cterm = true,
        plugins = { default = true },
      },
    }
  '';
}

unfortunately I have tried that and it doeesn’t work. :confused: I just did it again anyway in case I’m going crazy, and it didn’t work, but I still might be going crazy lol

Can u provide me the error log when running sudo nixos-rebuild switch --flake . --show-trace?

thank you so much!! here’s the output: Sep 03 2:05 AM - Codeshare

inherit config is probably messing up the value that ends up in { config, ... }:.

3 Likes

Where did you get this “config.lib.stylix” pattern from? That looks wrong.

1 Like

It looked wrong to me as well but it is written in their docs: Configuration - Stylix

1 Like

thank you so much for the direction. removed ‘config’ from the ‘inherit’ line and got this error:

       error: function 'anonymous lambda' called without required argument 'config'
       at /nix/store/jry4cjaysi3xfa55gn5w44ws82fzh1w4-source/home.nix:1:1:
            1| { pkgs, nixpkgs-unstable, unstable, config, stylix, ... }:
             | ^
            2|

or is there a different solution to the problem you’re referring to?

home-manager.users.dot.imports = [
              ({ config, ... }: import ./home.nix {

This is wrong, see how the Home Manager manual does it.

You are importing ./home.nix instead of using extraSpecialArgs. home-manager.users.dot.imports should be just [ ./home.nix ].

3 Likes

Thank you for that clarity. Is this correct? It runs, but not if I import nvimColors.nix. I get the same error about lib.

{
  description = "dottie's a flake";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
    nixos-hardware.url = "github:NixOS/nixos-hardware/master";
    neovim-nightly-overlay.url = "github:nix-community/neovim-nightly-overlay";
    home-manager.url = "github:nix-community/home-manager/release-25.05";
    home-manager.inputs.nixpkgs.follows = "nixpkgs";
    sops-nix.url = "github:Mic92/sops-nix";
    stylix = {
      url = "github:nix-community/stylix/release-25.05";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  outputs = inputs@{
    # self,
    nixpkgs,
    nixpkgs-unstable,
    nixos-hardware,
    home-manager,
    sops-nix,
    stylix,
    ...
    }: {
      nixosConfigurations.nixos =  nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        specialArgs = {
          inherit inputs;
          unstable = import nixpkgs-unstable {
            system = "x86_64-linux";
            config.allowUnfree = true;
            # config.allowUnfreePredicate = pkg: true;
          };
        };
        modules = [
          # Import the previous configuration.nix we used,
          # so the old configuration file still takes effect
          ./configuration.nix
          stylix.nixosModules.stylix
          nixos-hardware.nixosModules.framework-13th-gen-intel
          home-manager.nixosModules.home-manager
          sops-nix.nixosModules.sops
          {
            home-manager.sharedModules = [
              sops-nix.homeManagerModules.sops
              stylix.homeModules.stylix
            ];
            # home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.dot = ./home.nix;
            home-manager.extraSpecialArgs = {
              pkgs = import nixpkgs {
               system = "x86_64-linux";
               config.allowUnfree = true;
              };
              unstable = import nixpkgs-unstable {
               system = "x86_64-linux";
               config.allowUnfree = true;
              };
              inherit nixpkgs-unstable;
              };
          }
        ];
      };
  };
}

What is this file and where are you using it?

1 Like

thank you for helping me with this. It’s the mini.base16 plugin import and config for neovim. the same file with the stylix colors replaced with hex colors works as intended, but calling the stylix colors (which is the whole point of this, so I can theme my whole system together) gets me that lib error

I’m still in the early stages of understanding nix, but maybe this will give some clarity?

 $ nix repl --file '<nixpkgs>'
Nix 2.28.4
Type :? for help.
Loading installable ''...
Added 24813 variables.
nix-repl> config.lib.stylix.colorsbase00
error: attribute 'lib' missing
       at «string»:1:1:
            1| config.lib.stylix.colorsbase00
             | ^

If I’m not completely mistaken this could do the trick:

Replace

by

home-manager.users.dot.imports = [
./home.nix
./nvimColors.nix
];

and your nvimColors.nix should look like:

{...}:{
home.files.".config/nvim/lua/dot/plugins/mini.base16.lua".text = ''
    return {
      "nvim-mini/mini.base16",
      version = "*",
      config = {
        palette = {
          base00 = "#${config.lib.stylix.colors.base00}",
          base01 = "#${config.lib.stylix.colors.base01}",
          base02 = "#${config.lib.stylix.colors.base02}",
          base03 = "#${config.lib.stylix.colors.base03}",
          base04 = "#${config.lib.stylix.colors.base04}",
          base05 = "#${config.lib.stylix.colors.base05}",
          base06 = "#${config.lib.stylix.colors.base06}",
          base07 = "#${config.lib.stylix.colors.base07}",
          base08 = "#${config.lib.stylix.colors.base08}",
          base09 = "#${config.lib.stylix.colors.base09}",
          base0A = "#${config.lib.stylix.colors.base0A}",
          base0B = "#${config.lib.stylix.colors.base0B}",
          base0C = "#${config.lib.stylix.colors.base0C}",
          base0D = "#${config.lib.stylix.colors.base0D}",
          base0E = "#${config.lib.stylix.colors.base0E}",
          base0F = "#${config.lib.stylix.colors.base0F}",
        },
        use_cterm = true,
        plugins = { default = true },
      },
    }
  '';
'';
}

Tbh. I have no idea if this works because I haven’t tested it, don’t use nvim and I assume that the nvim part is correct.

2 Likes

YEESSS. Thank you so much!! I just had to change the semi-colons to commas for the imports list and add config to the imports, and change “files” to “file” in nvimColors; for those who may come along later.

THANK YOU! What a mentsh!

EDIT: I POSTED TOO SOON it’s not creating the file. :frowning:

SECOND EDIT: I POSTED TOO SOON AGAIN it was a typo on my fault that kept the file from being made and now everything’s working as I desire. <3 <3 <3

1 Like