All Projects → SenchoPens → base16.nix

SenchoPens / base16.nix

Licence: MIT license
Quickly theme programs in your favourite base16 colorscheme

Programming Languages

Nix
1067 projects

Projects that are alternatives of or similar to base16.nix

nix-configs
My Nix{OS} configuration files
Stars: ✭ 54 (-11.48%)
Mutual labels:  nix, nixos, flake, home-manager, nix-flake
nyx
⚙️Nix[OS] Configuration
Stars: ✭ 50 (-18.03%)
Mutual labels:  nix, nixos, home-manager, nix-flake
digga
A flake utility library to craft shell-, home-, and hosts- environments.
Stars: ✭ 818 (+1240.98%)
Mutual labels:  nix, nixos, flake, nix-flake
dotfiles
NixOS system config & Home-Manager user config
Stars: ✭ 43 (-29.51%)
Mutual labels:  nix, nixos, flake, home-manager
nix-config
A collection of my system configs and dotfiles
Stars: ✭ 35 (-42.62%)
Mutual labels:  nix, nixos, home-manager, nix-flake
microvm.nix
NixOS MicroVMs
Stars: ✭ 136 (+122.95%)
Mutual labels:  nix, nixos, flake, nix-flake
nix-home
A Nix Home Manager setup. I've now moved to a new configuration system at hugoreeves/elemental
Stars: ✭ 60 (-1.64%)
Mutual labels:  nix, nixos, home-manager
flake-utils-plus
Use Nix flakes without any fluff.
Stars: ✭ 280 (+359.02%)
Mutual labels:  nix, nixos, nix-flake
dotfiles
Dotfiles
Stars: ✭ 25 (-59.02%)
Mutual labels:  nix, nixos, nix-flake
nixpkgs
My Nix system configs!
Stars: ✭ 143 (+134.43%)
Mutual labels:  nix, home-manager, nix-flake
nix-xdg
[WIP] Nix overlay for making programs xdg compliant
Stars: ✭ 18 (-70.49%)
Mutual labels:  nix, nixos, home-manager
dotnix
nix stuff
Stars: ✭ 27 (-55.74%)
Mutual labels:  nix, nixos, nix-flake
rc
Structured system configuration (I moved from NixOS to GuixSD)
Stars: ✭ 97 (+59.02%)
Mutual labels:  nix, nixos, flake
dotfiles
My NixOS configuration featuring awesome and neovim
Stars: ✭ 40 (-34.43%)
Mutual labels:  nix, nixos, flake
dconf2nix
🐾 Convert Dconf files (e.g. Gnome Shell) to Nix, as expected by Home Manager
Stars: ✭ 51 (-16.39%)
Mutual labels:  nix, nixos, home-manager
system
The system configuration of a professional yak shaver
Stars: ✭ 42 (-31.15%)
Mutual labels:  nix, nixos, nix-flake
nixvim
Configure Neovim with Nix!
Stars: ✭ 120 (+96.72%)
Mutual labels:  nix, nixos, nixos-module
elemental
Elemental, the component parts of a Nix/OS development system.
Stars: ✭ 44 (-27.87%)
Mutual labels:  nix, nixos, home-manager
dotfiles
🏠
Stars: ✭ 53 (-13.11%)
Mutual labels:  nix, nixos, nix-flake
dotnix
Shackled within an elaborate prison of my own design.
Stars: ✭ 35 (-42.62%)
Mutual labels:  nix, nixos, home-manager

logo

demo

What's base16 and base16.nix?

  • base16 is a theming standard by which hundreds of colorschemes and application configuration templates were made over the years.
  • base16.nix is a NixOS / home-manager module and a library that makes using base16 / base24 schemes and templates as simple as possible, while leaving the user full flexibility.

Features

With base16.nix, you can:

  • use existing schemes, override them, write a new one in YAML / nix;
  • theme any application with a base16 template in minimal amount of key strokes, or write a new template in mustache / nix.

Nonfeatures

  • base16.nix is simply a ultrasupermega convenient battle-tested nix-y base16 standard implementation, not a ricing engine — but if you want one, please check out every r/unixporn admin's dream — Stylix! built with base16.nix!
  • base16.nix neither aggregates nor vendors schemes / templates to keep data and logic separated.
  • No support for legacy template formats like Embedded Ruby and EJS.

👀 Module example (covers majority of use-cases)

In this example, we will use base16.nix as a NixOS module to theme zathura, neovim and alacritty to use the nord scheme (home-manager module works the same way).

Import and set the scheme (step 1/2)

In your NixOS configuration directory:

flake.nix

{ inputs = {
  # Add base16.nix, base16 schemes and
  # zathura and vim templates to the flake inputs.
  base16.url = github:SenchoPens/base16.nix;
  base16.inputs.nixpkgs.follows = "nixpkgs";

  base16-schemes = {
    url = github:base16-project/base16-schemes;
    flake = false;
  };

  base16-zathura = {
    url = github:haozeke/base16-zathura;
    flake = false;
  };

  base16-vim = {
    url = github:base16-project/base16-vim;
    flake = false;
  };
  ...
};
outputs = { self, ... } @ inputs {
  ...
    nixosSystem {
      modules = [
        # import the base16.nix module
        base16.nixosModule
        # set system's scheme to nord by setting `config.scheme`
        { scheme = "${inputs.base16-schemes}/nord.yaml"; }
        # import `theming.nix`, we will write it in the next, final, step
        ./theming.nix
        ...
      ];
      # so you can use `inputs` in config files
      specialArgs = {
        inherit inputs;
      };
      ...
    };
  ...
};
... }

Theme (step 2/2)

Now that config.scheme is set, we can use it like a function to create themes from templates.

theming.nix

{ config, pkgs, inputs, ... }:
{
  # Theme zathura
  home-manager.users.sencho.programs.zathura.extraConfig =
    builtins.readFile (config.scheme inputs.base16-zathura);

  # Theme `neovim` — more complex, but the principle is the same.
  home-manager.users.sencho.programs.neovim = {
    plugins = [ (pkgs.vimPlugins.base16-vim.overrideAttrs (old:
      let schemeFile = config.scheme inputs.base16-vim;
      in { patchPhase = ''cp ${schemeFile} colors/base16-scheme.vim''; }
    )) ];
    extraConfig = ''
      set termguicolors background=dark
      let base16colorspace=256
      colorscheme base16-scheme
    '';
  };

  # Theme `alacritty`. home-manager doesn't provide an `extraConfig`,
  # but gives us `settings.colors` option of attrs type to set colors. 
  # As alacritty expects colors to begin with `#`, we use an attribute `withHashtag`.
  # Notice that we now use `config.scheme` as an attrset, and that this attrset,
  # besides from having attributes `base00`...`base0F`, has mnemonic attributes (`red`, etc.) -
  # read more on that in the next section.
  home-manager.users.sencho.programs.alacritty.settings.colors =
    with config.scheme.withHashtag; let default = {
        black = base00; white = base07;
        inherit red green yellow blue cyan magenta;
      };
    in {
      primary = { background = base00; foreground = base07; };
      cursor = { text = base02; cursor = base07; };
      normal = default; bright = default; dim = default;
    };
}

That's all, we themed 3 applications!

The attentive reader will notice that after setting config.scheme to a string, we use it as a function (to theme zathura and neovim) and as an attrset (to theme alacritty) — that's base16.nix' magic! Read the Documentation section to see how it works.

🍳 How To

Import a scheme from a YAML file
config.scheme = "${inputs.base16-schemes}/nord.yaml";
Override a scheme

We need to explicitly use mkSchemeAttrs function to use the override field of the resulting scheme attrs:

config.scheme = (config.lib.base16.mkSchemeAttrs "${inputs.base16-schemes}/nord.yaml").override {
  scheme = "Now it's my scheme >:]";
  base00 = "000000";  # make background completely black
};
Declare a scheme in Nix
config.scheme = {
  slug = "balsoftheme"; scheme = "Theme by balsoft"; author = "balsoft";
  base00 = "000000"; base01 = "333333"; base02 = "666666"; base03 = "999999";
  base04 = "cccccc"; base05 = "ffffff"; base06 = "e6e6e6"; base07 = "e6e6e6";
  base08 = "bf4040"; base09 = "bf8040"; base0A = "bfbf40"; base0B = "80bf40";
  base0C = "40bfbf"; base0D = "407fbf"; base0E = "7f40bf"; base0F = "bf40bf";
};

source

Use multiple schemes simultaneously

Achieve this by theming without config.scheme — by calling mkSchemeAttrs:

home-manager.users.sencho.programs.zathura.extraConfig =
  builtins.readFile (config.lib.base16.mkSchemeAttrs inputs.base16-schemes inputs.base16-zathura);

Without importing base16.nix as a module at all:

home-manager.users.sencho.programs.zathura.extraConfig =
  builtins.readFile ((pkgs.callPackage inputs.base16.lib {}).mkSchemeAttrs inputs.base16-schemes inputs.base16-zathura);
Use template variation

Template repositories often define more than one template variation. For example, zathura template repository defines default.mustache (colors only the interface) and recolor.mustache (colors the interface and pdfs).

By default base16.nix uses default.mustache. To use another template, e.g. recolor.mustache:

home-manager.users.sencho.programs.zathura.extraConfig =
  builtins.readFile (config.scheme {
    templateRepo = inputs.base16-zathura; target = "recolor";
  });
Override a template

Sample use-case: suppose you like zathura's default.mustache template, but want to change the background (default-bg) from base00 to base01.

  1. Override the scheme only for zathura:
home-manager.users.sencho.programs.zathura.extraConfig =
  builtins.readFile ((config.scheme.override {
    base00 = config.scheme.base01;
  }) inputs.base16-zathura);

Keep in mind that by doing so you'll change not only default-bg color, but also inputbar-bg, notification-bg, etc.

  1. Copy-paste the template and modify it:
home-manager.users.sencho.programs.zathura.extraConfig =
  builtins.readFile (config.scheme { template = ''
    ... 
    set default-bg   "#{{base01-hex}}"  # <-- we changed this
    set default-fg   "#{{base01-hex}}"

    set statusbar-fg "#{{base04-hex}}"
    set statusbar-bg "#{{base02-hex}}"
    ...
  ''; });

📚 Documentation

Consult the DOCUMENTATION.md to learn about every feature in detail and see how base16.nix works underhood.

🤍 Repositories that use base16.nix

NixOS modules:

  • Stylix — System-wide colorscheming and typography for NixOS.
  • tmux-flake — a flake that configures tmux.

Configs by:

Please feel free to list your repository above, it will make my day :)

🎎 Alternatives

  • base16-nix by @atpotts and its forks, notably base16-nix by @AlukardBF and base16-nix by @lukebfox.

  • nix-colors by @misterio. Thanks for the competition spirit! :)) And for the nix-wallpaper function, with which the preview GIF was generated.

    differences:

    Roughly nix-colors can be viewed as an alternative to base16.nix + Stylix, without the mustache template support:

    base16.nix supports the existing ≥ 80 mustache templates, nix-colors does not — instead there are ≥ 4 contributed nix functions and planned (at the time of writing) support for translation from mustache templates to nix functions. Stylix has ≥ 10 Stylix theming nix functions.

    You can generate base16 scheme from a wallpaper — in nix-colors via flavours and in Stylix via home-made CIE-LAB colorspace Haskell genetic algorithm.

    Also, if you use nix-colors without it's nix functions, it does not depend on nixpkgs.

  • theme-base16 by @rycee.

☎️ Help

If you need any help, feel free to open an issue or contact me via email or telegram (my contacts are here).

💙 Acknowledgments

Thanks to:

👩‍💻 Contributing

See CONTRIBUTING.md

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].