• Stars
    star
    402
  • Rank 103,644 (Top 3 %)
  • Language
    Nix
  • License
    GNU General Publi...
  • Created over 2 years ago
  • Updated about 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Modules and schemes to make theming with Nix awesome.

Nix Colors

About

This repo is designed to help with Nix(OS) theming.

At the core, we expose a nix attribute set with 220+ base16 schemes, as well as a home-manager module for globally setting your preferred one.

These schemes are not vendored in: they are directly fetch (and flake locked!) from base16-schemes, then converted using our (pure nix) schemeFromYAML function, which is also exposed for your convenience. This means you can easily make your own schemes, in either nix-colors (.nix) or base16 (.yaml) format, freely converting between the two.

The core portion of nix-colors is very unopinionated and should work with all possible workflows very easily, without any boilerplate code.

We also have some optional contrib functions for opinionated, common use cases (generating scheme from image, generating wallpaper, vim scheme, gtk theme).

Base16?

Base16 is a standard for defining palettes (schemes), and how each app should be themed (templates).

nix-colors focuses on delivering and helping you use the schemes, all in a Nix-friendly way.

Setup

The usual setup looks like this:

  • Either add the repo to your flake inputs, or add the channel on a legacy setup.
  • Import the home-manager module nix-colors.homeManagerModules.default
  • Set the option colorScheme to your preferred color scheme, such as nix-colors.colorSchemes.dracula (or create/convert your own)
  • Use config.colorScheme.colors.base0X to refer to any of the 16 colors from anywhere!

Importing

Flake

First add nix-colors to your flake inputs:

{
  inputs = {
    # ...
    nix-colors.url = "github:misterio77/nix-colors";
  };
}

Then, you need some way to pass this onwards to your home-manager configuration.

If you're using standalone home-manager, use extraSpecialArgs for this:

homeConfigurations = {
  "foo@bar" = home-manager.lib.homeManagerConfiguration {
    # ...
    extraSpecialArgs = { inherit nix-colors; };
  };
};

Or, if using it as a NixOS module, use specialArgs on your flake (and extraSpecialArgs wherever you import your home nix file):

nixosConfigurations = {
  bar = nixpkgs.lib.nixosSystem {
    # ...
    specialArgs = { inherit nix-colors; };
  };
};

Legacy (non-flake)

If you're not using flakes, the most convenient method is adding nix-colors to your channels:

nix-channel --add https://github.com/misterio77/nix-colors/archive/main.tar.gz nix-colors
nix-channel --update

Then, instead of adding nix-colors as a argument in your config file(s), use a let binding. For example:

{ pkgs, config, ... }: # Don't put 'nix-colors' here
let
  nix-colors = import <nix-colors> { };
in {
  import = [
    nix-colors.homeManagerModules.default
  ];

  colorScheme = nix-colors.colorSchemes.paraiso;

  # ...
}

Using

With that done, move on to your home manager configuration.

You should import the nix-colors.homeManagerModules.default, and set the option colorScheme to your preferred scheme, such as nix-colors.colorSchemes.dracula

Here's a quick example on how to use it with, say, a terminal emulator (kitty) and a browser (qutebrowser):

{ pkgs, config, nix-colors, ... }: {
  imports = [
    nix-colors.homeManagerModules.default
  ];

  colorScheme = nix-colors.colorSchemes.dracula;

  programs = {
    kitty = {
      enable = true;
      settings = {
        foreground = "#${config.colorScheme.colors.base05}";
        background = "#${config.colorScheme.colors.base00}";
        # ...
      };
    };
    qutebrowser = {
      enable = true;
      colors = {
        # Becomes either 'dark' or 'light', based on your colors!
        webppage.preferred_color_scheme = "${config.colorScheme.kind}";
        tabs.bar.bg = "#${config.colorScheme.colors.base00}";
        keyhint.fg = "#${config.colorScheme.colors.base05}";
        # ...
      };
    };
  };
}

If you change colorScheme for anything else (say, nix-colors.colorSchemes.nord), both qutebrowser and kitty will match the new scheme! Awesome!

You can, of course, specify (or generate somehow) your nix-colors scheme directly:

{
  colorScheme = {
    slug = "pasque";
    name = "Pasque";
    author = "Gabriel Fontes (https://github.com/Misterio77)";
    colors = {
      base00 = "#271C3A";
      base01 = "#100323";
      base02 = "#3E2D5C";
      base03 = "#5D5766";
      base04 = "#BEBCBF";
      base05 = "#DEDCDF";
      base06 = "#EDEAEF";
      base07 = "#BBAADD";
      base08 = "#A92258";
      base09 = "#918889";
      base0A = "#804ead";
      base0B = "#C6914B";
      base0C = "#7263AA";
      base0D = "#8E7DC6";
      base0E = "#953B9D";
      base0F = "#59325C";
    };
  };
}

This is it for basic usage! You're ready to nixify your colors. Read on if you're interested in converting schemes between our format and base16's, or want to check out our opinionated contrib functions.

Lib functions

Core

Our core functions do not require nixpkgs. Nix all the way down (at least until you get to nix-the-package-manager code) baby!

All of these are exposed at nix-colors.lib.

schemeFromYAML

This function is used internally to convert base16's schemes to nix-colors format, but is exposed so you can absolutely do the same.

Just grab (or create yours) a .yaml file, read it into a string (with readFile, for example) and you're golden:

{ nix-colors, ... }:
{
  colorScheme = nix-colors.lib.schemeFromYAML "cool-scheme" (builtins.readFile ./cool-scheme.yaml);
}

This path can come from wherever nix can read, even another repo! That's what we do to expose base16's schemes.

schemeToYAML

Maybe you took a liking to writting (or generating) colors in nix-colors sweet nix syntax, but want to contribute back to base16. No, no, don't write that YAML by hand!

We have a schemeToYAML for converting from nix-colors's .nix to base16's .yaml format.

Grab your nix-colors scheme, pass it to the function, and you get the YAML string (you can write it toFile if you want) in return. Here's an example with nix-repl:

$ nix repl
nix-repl> :lf .
nix-repl> bultins.toFile "pasque.yaml" (inputs.nix-colors.lib.schemeToYAML inputs.nix-colors.colorSchemes.pasque)

More soon(TM)

We plan on helping you turn existing base16 templates into nifty nix functions real soon, as well as converting colors between hex and decimal. Stay tuned!

Contributed functions

We also have a few opinionated functions for some common scheme usecases: such as generating schemes from an image, generating an image from a scheme... You get the idea.

These nifty pals are listed (and documented) at lib/contrib/default.nix. They are exposed at nix-colors.lib.contrib.

Do note these require nixpkgs, however. You should pass your pkgs instance to nix-colors.lib.contrib to use them. For example:

{ pkgs, nix-colors, ... }:

let
  nix-colors-lib = nix-colors.lib.contrib { inherit pkgs; };
in {
  colorScheme = nix-colors-lib.colorSchemeFromPicture {
    path = ./wallpapers/example.png;
    kind = "light";
  };
}

Upstreaming new schemes

Please please upstream nice schemes you have created!

It's pretty easy to do. Just open up a PR on base16-schemes, and once it's in it will be available here.

If it takes a while to be merged, you can temporarily put it together with your config and use schemeFromYAML to load it.

Alternatively, you can tell nix-colors to follow your base16-schemes fork.

In your flake inputs, add base16-schemes and override nix-colors.inputs.base16-schemes.follows:

{
  description = "Your cool config flake";
  inputs = {
    base16-schemes = "github:you/base16-schemes"; # Your base16-schemes fork

    nix-colors.url = "github:misterio77/nix-colors";
    nix-colors.inputs.base16-schemes.follows = "base16-schemes"; # Be sure to add this
    # ...
  };
  # ...
}

Thanks

Special thanks to rycee for most of this repo's inspiration, plus for the amazing home-manager.

Huge thanks for everyone involved with base16.

Gigantic thanks to arcnmx, for his pure-nix fromYAML function.

Extra special thanks for my folks at the NixOS Brasil Telegram group, for willing to try this out!

More Repositories

1

nix-starter-configs

Simple and documented config templates to help you get started with NixOS + home-manager + flakes. All the boilerplate you need!
Nix
1,677
star
2

nix-config

Personal nixos and home-manager configurations.
Nix
585
star
3

flavours

🎨💧 An easy to use base16 scheme manager that integrates with any workflow.
Rust
435
star
4

dotfiles

Dotfiles for my Arch setup.
Mustache
16
star
5

paste.misterio.me

Simple pasting service
Rust
12
star
6

disconic

Discord bot for interacting with subsonic music libraries
Rust
9
star
7

website

My personal website and blog
Liquid
6
star
8

base16-nebula-scheme

Blue and Green Base16 Scheme
6
star
9

minicava

A miniature cava sound visualizer, designed for running in status bars
Shell
5
star
10

aoc2022

My Haskell and Rust attempt on AoC 2022
Rust
5
star
11

base16-pasque-scheme

Purple and Gold Base16 Theme
4
star
12

Modpack

Meu modpackzinho
TOML
4
star
13

my-minecraft-server

My minecraft server, which is ran using docker compose
Shell
3
star
14

nixos-hyprland-example

Nix
3
star
15

BSI-SCC0560

Parte final do trabalho de IHC
HTML
3
star
16

nur-packages

My personal NUR repo
Nix
3
star
17

pokedex-pfpa

Projeto da disciplina de Programação Funcional Pura com Aplicações (2022)
Haskell
3
star
18

base16-spotify

Base16 for spotify (using spicetify)
HTML
2
star
19

yrmos

Protótipo para a disciplina de empreendedorismo
Rust
2
star
20

base16-catppuccin-scheme

Catppuccin base16 theme
2
star
21

BSI

Repositório arquivado, agora são vários repositórios em um projeto no SourceHut: https://hub.sr.ht/~misterio/BSI
TeX
2
star
22

sep0566

Listas e notas de introdução a economia
TeX
2
star
23

rgbdaemon

Simple script for interfacing with OpenRGB and CKB-next programmatically
Shell
2
star
24

minecraftd

Minecraft server daemon script, forked from Edenhofer. Now supports multiple servers at once.
Shell
2
star
25

base16-sakura-scheme

Light pink scheme for base16
2
star
26

shellcolord

Shell
2
star
27

drupal-12factor

drupal-12factor
PHP
2
star
28

base16-silk-scheme

Cyan/blueish theme for base16, with light and dark options
2
star
29

BMA-SME0230

Jogo da cobrinha muito bolado
C
2
star
30

BSI-SSC0510

Disciplina de Arquitetura de Computadores
1
star
31

IHC2021

Implementação de IHC
Rust
1
star
32

modpack-da-informacao

Modpack para o BSI, ICMC & amigos
1
star
33

RubensCrew

Trabalhos e projetos BSI 2020
C
1
star
34

T1-ICC2

Trabalho 1 da disciplina ICC 2
TeX
1
star
35

misterio77

Hey!
1
star
36

Trabalho-IDW

Projeto da disciplina Introdução ao Desenvolvimento Web
JavaScript
1
star
37

T2-ED2

C
1
star
38

sistemer-bot

Bot do BSI 020 para telegram
Rust
1
star
39

bsi-modpack

Modpack files
Shell
1
star
40

pass-wofi

A wofi graphical menu for pass
Shell
1
star
41

base16-spaceduck-scheme

Spaceduck scheme, packaged for use with base16
1
star
42

bungeecord-aur

Bungeecord AUR package and management script, forked from Edenhofer. Supports multiple servers.
Shell
1
star
43

pmis

CLI companion for paste.misterio.me
Rust
1
star
44

base16-uwunicorn-scheme

Pretty scheme
1
star
45

BSI-SCC0505-T1

Trabalho 1 de Introdução a Teoria Computacional
Rust
1
star
46

ModpackConfig

Just config files for my Modpack :D
1
star
47

aws-azure-login-action

GitHub action for aws-azure-login
TypeScript
1
star
48

T2-ED

Trabalho 2 de Estrutura de Dados
C
1
star
49

SCC0541-Lab-BD-Projeto

Projeto da disciplina de Laboratório de Bases de Dados (SCC0541) - 2022/1
SCSS
1
star