Use specific base16 colours from stylix in configuration

I am trying to generalise my starship configuration by using the colours generated by stylix.
My current configuration is currently something like this:

programs.starship = {
  enable = true;
  settings = {
    format = lib.concatStrings [
      "[>] (bg:#${config.stylix.base16Scheme.base01} fg:#${config.stylix.base16Scheme.base02})"
    ];
  };
};

But this config results in the error

expected a set but found a path

How could I fix this correctly?

I have seen multiple configs do it in a similar way with rgb colors

"col.inactive_border" = lib.mkForce "rgb(${config.stylix.base16Scheme.base00})";

Please post the full error, without truncation.

This is the full error log

error:
       … while calling the 'head' builtin
         at /nix/store/sj9yrq21wbbfr5715hys3laa2qd6x471-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/sj9yrq21wbbfr5715hys3laa2qd6x471-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/sj9yrq21wbbfr5715hys3laa2qd6x471-source/nixos/modules/system/activation/top-level.nix':

       … while evaluating the option `home-manager.users.ryan.home.file':

       … while evaluating definitions from `/nix/store/hxhym8c5xz6dxkl3d9yppiwlnzk3khn7-source/modules/misc/xdg.nix':

       … while evaluating the option `home-manager.users.ryan.xdg.configFile':

       … while evaluating definitions from `/nix/store/hxhym8c5xz6dxkl3d9yppiwlnzk3khn7-source/modules/programs/starship.nix':

       … while evaluating the option `home-manager.users.ryan.programs.starship.settings':

       … while evaluating definitions from `/nix/store/96658vnddms3ywd0vj9bp0p2qpqpfk5z-178d5zpsvbvgp9w635xaddgyxc2mz9jq-source/modules/home/programs/starship/default.nix':

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

       error: expected a set but found a path: /nix/store/96658vnddms3ywd0vj9bp0p2qpqpfk5z-178d5zpsvbvgp9w635xaddgyxc2mz9jq-source/modules/home/programs/stylix/base16/catppuccin/mocha.yaml

In that case, I can only deduce that you set stylix.base16Scheme to be a path, instead of a set.

I can confirm

I get the same error because I define stylix.base16Scheme to be a path to a yaml file

code snippet:

# ./flake.nix
inputs = {
    stylix.url = "github:danth/stylix";
    vity-base24 = {
      url = "github:Alexdelia/vity-base24";
      flake = false;
    };
};
# ./some_module.nix
{
  inputs,
  ...
}: {
  stylix = {
    enable = true;

    base16Scheme = "${inputs.vity-base24}/vity.yaml";
  };
}

all settings apply correctly

but when I try to modify my kitty configuration (or any other) by manually referencing base16Scheme.base00 for the background:

# ./home/kitty/default.nix
{
  config,
  ...
}: {
  programs = {
    kitty = {
      enable = true;

      settings = {
        background = config.stylix.base16Scheme.base00;
      };
    };
  };

  stylix.targets.kitty.enable = false;
}

I get the error:

error: value is a string with context while a set was expected

builtins.trace config.stylix.base16Scheme gives:

trace: /nix/store/sc9...ch2-source/vity.yaml

(it is indeed the yaml file I expect)

which makes sense, but now I don’t know how to access the base00 color when I give a yaml file to base16Scheme


note that if base16Scheme is define as a nix set, this solution does work
see Goxore code:


I’m gonna try to find a solution to be able to access all color from the scheme when loaded from a yaml file

if/when I find the solution, you will probably be able to find it here:

very happy to say that I found the solution … kinda

after digging builtins.stylix

see output ```nix { autoEnable = true; base16Scheme = "/nix/store/sc94g74nm6lmdp8ybdjmafpzcbshbch2-source/vity.yaml"; cursor = { name = "Vimix-Cursors-White"; package = ; size = 32; }; enable = true; fonts = { emoji = ; monospace = { name = "SourceCodePro Nerd Font"; package = ; }; packages = ; sansSerif = { name = "RobotoMono Nerd Font"; package = ; }; serif = ; sizes = { applications = 14; desktop = 14; popups = ; terminal = 16; }; }; generated = { fileTree = { "stylix/generated.json" = {source = ;}; "stylix/palette.html" = {source = ;}; "stylix/palette.json" = {source = ;}; }; json = ; palette = ; }; image = "/nix/store/s2hf8gqpal4rmi0sdma3ybb3alp8a6mk-wallhaven-o31o2p.png"; imageScalingMode = ; opacity = ; override = {}; palette = ; polarity = ; targets = { alacritty = ; avizo = ; bat = ; bemenu = ; bspwm = ; btop = {enable = true;}; dunst = ; emacs = ; feh = ; firefox = ; fish = ; foot = ; fuzzel = ; fzf = ; gedit = {enable = true;}; gitui = ; gnome = {enable = true;}; gtk = { enable = true; extraCss = ; }; helix = {enable = true;}; hyprland = {enable = true;}; hyprpaper = {enable = true;}; i3 = ; k9s = ; kde = {enable = true;}; kitty = { enable = false; variant256Colors = ; }; lazygit = ; mako = ; mangohud = ; ncspot = ; neovim = { enable = true; transparentBackground = { main = false; signColumn = false; }; }; nixvim = ; nushell = ; qutebrowser = ; rofi = ; sway = ; swaylock = ; sxiv = {enable = true;}; tmux = ; tofi = ; vesktop = {enable = true;}; vim = ; vscode = {enable = false;}; waybar = ; wezterm = {enable = true;}; wofi = ; wpaperd = ; xfce = {enable = false;}; xresources = {enable = true;}; yazi = ; zathura = ; zellij = ; }; } ```

I found config.stylix.generated.palette

which evaluate (in my config) to:

config.stylix.generated.palette = {
  author = "Stylix";
  base00 = "1d1a19";
  base01 = "68393f";
  base02 = "4c6d93";
  base03 = "81a3b8";
  base04 = "d9b187";
  base05 = "d4e5ef";
  base06 = "ffefd0";
  base07 = "fef0cf";
  base08 = "878fa0";
  base09 = "88929a";
  base0A = "aa8b5f";
  base0B = "ac8a6b";
  base0C = "b18875";
  base0D = "7095af";
  base0E = "c97c5a";
  base0F = "bb855e";
  scheme = "Stylix";
  slug = "stylix";
}

which is perfect

well, that’s a lie, it uses the generated base16 from the stylix.image, not the one given in base16Scheme

so you can do:

# ./home/kitty/default.nix
{
  config,
  ...
}: {
  programs = {
    kitty = {
      enable = true;

      settings = {
        background = "#${config.stylix.generated.palette.base00}";
      };
    };
  };

  stylix.targets.kitty.enable = false;
}

but it won’t use the base16Scheme

gonna try to dig more…

made it work through the use of base16.nix (which is used by stylix)

here is the commit with just the change needed to make it work:

Sorry for the necro, but I found config.lib.stylix.colors.base00 which should be an easier way to achieve this.