Skip to content

Commit 81c0629

Browse files
authored
fetch schemes from base16-project, reorganize lib
This is a major change, but the only breaking change is the lib function namespace. You can now use either nix-colors-style schemes, or base16 YAML schemes directly, using the new `schemeFromYAML` function. Opinionated functions have been moved into `lib-contrib`. base16 has moved to an org, so with that in mind we no longer need to vendor schemes here. Docs has been updated, and the repo was cleaned up from now-unneeded stuff. All occurences of "color(S|s)cheme(s)" have been normalized to "colorScheme(s)", with "colorscheme(s)" as aliases. Changelog: - Add `schemeFromYAML` and `schemeToYAML` functions. - These are pure nix, and allow us to finally use base16-project's `.yaml` schemes without requiring users to pass `pkgs` or specify `system`. - Use base16-project scheme repository. There is a scheme monorepo now, which makes our lives a lot easier - We no longer vendor schemes. - The schemes we previously had were upstreamed on tinted-theming/base16-schemes#1 - Move opinionated functions into `lib-contrib` - Update docs - Clean up repo
1 parent fe9fd38 commit 81c0629

File tree

341 files changed

+448
-8447
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

341 files changed

+448
-8447
lines changed

CONTRIBUTING.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

README.md

Lines changed: 148 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,31 +3,40 @@
33
# About
44
This repo is designed to help with Nix(OS) theming.
55

6-
At the core, we have an attribute set with 220+ base16 schemes, as well as a [home-manager](https://github.com/nix-community/home-manager) module for globally setting your preferred one.
6+
At the core, we expose a nix attribute set with 220+ base16 schemes, as well as
7+
a [home-manager](https://github.com/nix-community/home-manager) module for
8+
globally setting your preferred one.
79

8-
Plus some optional [functions](lib-usage.md) for common use cases (generating scheme from image, generating wallpaper, vim scheme, gtk theme).
10+
These schemes are not vendored in: they are directly fetch (and flake locked!)
11+
from [base16-schemes](https://github.com/base16-project/base16-schemes), then
12+
converted using our (pure nix) `schemeFromYAML` function, which is also exposed
13+
for your convenience. This means you can easily make your own schemes, in
14+
either nix-colors (`.nix`) or base16 (`.yaml`) format, freely converting
15+
between the two.
916

10-
## Base16?
11-
[Base16](https://github.com/chriskempson/base16) is a standard for defining palettes (schemes), and how each app should be themed (templates).
12-
13-
nix-colors focuses on delivering you just the schemes, while being easy to use, flexible, and unopinionated.
14-
15-
## Existing solutions?
16-
Nix is amazing and lets people do stuff their way, so people end up with lots of different (often incompatible) solutions to the same problem.
17+
The core portion of nix-colors is very unopinionated and should work with all
18+
possible workflows very easily, without any boilerplate code.
1719

18-
Theming is one of them. Based on [rycee's](https://gitlab.com/rycee/nur-expressions/-/tree/master/hm-modules/theme-base16), some of my experience with creating a [base16 theming workflow](https://github.com/misterio77/flavours), and a demand for a easy way to expose multiple schemes, i decided to create this.
20+
We also have some optional contrib functions for opinionated, common use cases
21+
(generating scheme from image, generating wallpaper, vim scheme, gtk theme).
1922

20-
Perhaps this could become a standard solution for a common problem.
23+
## Base16?
24+
[Base16](https://github.com/base16-project/base16) is a standard for defining
25+
palettes (schemes), and how each app should be themed (templates).
2126

22-
![relevant xkcd](https://imgs.xkcd.com/comics/standards.png)
27+
nix-colors focuses on delivering and helping you use the schemes, all in a
28+
Nix-friendly way.
2329

2430
# Setup
2531

2632
The usual setup looks like this:
27-
- Either add the repo to your flake inputs, or add the channel on a legacy setup.
33+
- Either add the repo to your flake inputs, or add the channel on a legacy
34+
setup.
2835
- Import the home-manager module `nix-colors.homeManagerModule`
29-
- Set the option `colorscheme` to your preferred color scheme (such as `nix-colors.colorSchemes.dracula`)
30-
- Use `config.colorscheme.colors.base0X` to refer to any of the 16 colors from anywhere!
36+
- Set the option `colorScheme` to your preferred color scheme, such as
37+
`nix-colors.colorSchemes.dracula` (or create/convert your own)
38+
- Use `config.colorScheme.colors.base0X` to refer to any of the 16 colors from
39+
anywhere!
3140

3241
## Importing
3342

@@ -42,7 +51,8 @@ First add `nix-colors` to your flake inputs:
4251
}
4352
```
4453

45-
Then, you need some way to pass this onwards to your `home-manager` configuration.
54+
Then, you need some way to pass this onwards to your `home-manager`
55+
configuration.
4656

4757
If you're using standalone home-manager, use `extraSpecialArgs` for this:
4858
```nix
@@ -54,7 +64,8 @@ homeConfigurations = {
5464
};
5565
```
5666

57-
Or, if using it as a NixOS module, use `specialArgs` on your flake (and `extraSpecialArgs` wherever you import your home nix file):
67+
Or, if using it as a NixOS module, use `specialArgs` on your flake (and
68+
`extraSpecialArgs` wherever you import your home nix file):
5869
```nix
5970
nixosConfigurations = {
6071
bar = nixpkgs.lib.nixosSystem {
@@ -66,64 +77,65 @@ nixosConfigurations = {
6677

6778

6879
### Legacy (non-flake)
69-
If you're not using flakes, the most convenient method is adding nix-colors to your channels:
80+
If you're not using flakes, the most convenient method is adding nix-colors to
81+
your channels:
7082
```
7183
nix-channel --add https://github.com/misterio77/nix-colors/archive/main.tar.gz nix-colors
7284
nix-channel --update
7385
```
7486

75-
Then, at the top of your config file(s) add `nix-colors ? <nix-colors>` as an argument (instead of just `nix-colors`).
87+
Then, at the top of your config file(s) add `nix-colors ? <nix-colors>` as an
88+
argument (instead of just `nix-colors`).
7689

7790
## Using
7891

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

81-
You should import the `nix-colors.homeManagerModule`, and set the option `colorscheme` to your preferred scheme, such as `nix-colors.colorSchemes.dracula`
94+
You should import the `nix-colors.homeManagerModule`, and set the option
95+
`colorScheme` to your preferred scheme, such as
96+
`nix-colors.colorSchemes.dracula`
8297

83-
Here's a quick example on how to use it with, say, a terminal emulator (kitty) and a browser (qutebrowser):
98+
Here's a quick example on how to use it with, say, a terminal emulator (kitty)
99+
and a browser (qutebrowser):
84100
```nix
85101
{ pkgs, config, nix-colors, ... }: {
86102
imports = [
87103
nix-colors.homeManagerModule
88104
];
89105
90-
colorscheme = nix-colors.colorSchemes.dracula;
106+
colorScheme = nix-colors.colorSchemes.dracula;
91107
92108
programs = {
93109
kitty = {
94110
enable = true;
95111
settings = {
96-
foreground = "#${config.colorscheme.colors.base05}";
97-
background = "#${config.colorscheme.colors.base00}";
112+
foreground = "#${config.colorScheme.colors.base05}";
113+
background = "#${config.colorScheme.colors.base00}";
98114
# ...
99115
};
100116
};
101117
qutebrowser = {
102118
enable = true;
103119
colors = {
104120
# Becomes either 'dark' or 'light', based on your colors!
105-
webppage.preferred_color_scheme = "${config.colorscheme.kind}";
106-
tabs.bar.bg = "#${config.colorscheme.colors.base00}";
107-
keyhint.fg = "#${config.colorscheme.colors.base05}";
121+
webppage.preferred_color_scheme = "${config.colorScheme.kind}";
122+
tabs.bar.bg = "#${config.colorScheme.colors.base00}";
123+
keyhint.fg = "#${config.colorScheme.colors.base05}";
108124
# ...
109125
};
110126
};
111127
};
112128
}
113129
```
114130

115-
If you change `colorscheme` for anything else (say, `nix-colors.colorSchemes.nord`), both qutebrowser and kitty will match the new scheme! Awesome!
116-
117-
# Lib functions
118-
[Moved to its own file](lib-usage.md)
119-
120-
# Advanced usage
131+
If you change `colorScheme` for anything else (say,
132+
`nix-colors.colorSchemes.nord`), both qutebrowser and kitty will match the new
133+
scheme! Awesome!
121134

122-
## Custom scheme
123-
Okay, we have a lot of schemes, but maybe you want to hardcode (or generate it somehow?) your own, no problem! You can just specify it directly:
135+
You can, of course, specify (or generate somehow) your nix-colors scheme directly:
124136
```nix
125137
{
126-
colorscheme = {
138+
colorScheme = {
127139
slug = "pasque";
128140
name = "Pasque";
129141
author = "Gabriel Fontes (https://github.com/Misterio77)";
@@ -149,22 +161,115 @@ Okay, we have a lot of schemes, but maybe you want to hardcode (or generate it s
149161
}
150162
```
151163

152-
## Listing all schemes (and registry usage)
153-
Maybe you're working on a cool graphical menu for choosing schemes? Or want to pick a random scheme when you press a button?
164+
This is it for basic usage! You're ready to `nix`ify your `colors`. Read on if
165+
you're interested in converting schemes between our format and base16's, or
166+
want to check out our opinionated contrib functions.
167+
168+
# Lib functions
169+
170+
## Core
171+
172+
Our core functions do not require nixpkgs. Nix all the way down (at least until
173+
you get to nix-the-package-manager code) baby!
174+
175+
All of these are exposed at `nix-colors.lib-core`.
176+
177+
### `schemeFromYAML`
178+
179+
This function is used internally to convert base16's schemes to nix-colors
180+
format, but is exposed so you can absolutely do the same.
181+
182+
Just grab (or create yours) a `.yaml` file, read it into a string (with
183+
`readFile`, for example) and you're golden:
184+
```nix
185+
{ nix-colors, ... }:
186+
{
187+
colorScheme = nix-colors.lib-core.schemeFromYAML (builtins.readFile ./cool-scheme.yaml);
188+
}
189+
```
190+
191+
This path can come from wherever nix can read, even another repo! That's what
192+
we do to expose base16's schemes.
193+
194+
### `schemeToYAML`
195+
196+
Maybe you took a liking to writting (or generating) colors in nix-colors sweet
197+
nix syntax, but want to contribute back to base16. No, no, don't write that
198+
YAML by hand!
199+
200+
We have a `schemeToYAML` for converting from nix-colors's `.nix` to
201+
base16's `.yaml` format.
154202

155-
No problem with `nix-colors`! The fact that we expose all schemes means you can easily use `nix eval` to list schemes (or even grab and print out their colors), for all your scripting needs.
203+
Grab your nix-colors scheme, pass it to the function, and you get the YAML
204+
string (you can write it `toFile` if you want) in return. Here's an example
205+
with nix-repl:
156206
```bash
157-
nix eval --raw nix-colors#colorSchemes --apply 's: builtins.concatStringsSep "\n" (builtins.attrNames s)'
207+
$ nix repl
208+
nix-repl> :lf .
209+
nix-repl> bultins.toFile "pasque.yaml" (inputs.nix-colors.lib-core.schemeToYAML inputs.nix-colors.colorSchemes.pasque)
158210
```
159211

160-
This assumes you have nix-colors set as a nix registry. You can easily do it by passing `nix-colors` from your flake to your system configuration, and using:
212+
### More soon(TM)
213+
214+
We plan on helping you turn existing base16 templates into nifty nix functions
215+
real soon, as well as converting colors between hex and decimal. Stay tuned!
216+
217+
## Contributed functions
218+
219+
We also have a few opinionated functions for some common scheme usecases: such
220+
as generating schemes from an image, generating an image from a scheme... You get
221+
the idea.
222+
223+
These nifty pals are listed (and documented) at `./lib/contrib/default.nix`.
224+
They are exposed at `nix-colors.lib-contrib`.
225+
226+
Do note these require `nixpkgs`, however. You should pass your `pkgs` instance
227+
to `nix-colors.lib-contrib` to use them. For example:
228+
```nix
229+
{ pkgs, nix-colors, ... }:
230+
231+
let
232+
nix-colors-lib = nix-colors.lib-contrib { inherit pkgs; };
233+
in {
234+
colorScheme = nix-colors-lib.colorSchemeFromPicture {
235+
path = ./wallpapers/example.png;
236+
kind = "light";
237+
};
238+
}
239+
```
240+
241+
# Upstreaming new schemes
242+
243+
Please please upstream nice schemes you have created!
244+
245+
It's pretty easy to do. Just open up a PR on
246+
[base16-schemes](https://github.com/base16-project/base16-schemes), and once
247+
it's in it will be available here.
248+
249+
If it takes a while to be merged, you can temporarily put it together with your
250+
config and use [`schemeFromYAML`](#schemeFromYAML) to load it.
251+
252+
Alternatively, you can tell nix-colors to follow your base16-schemes fork.
253+
There's two ways to do it.
254+
255+
- In your flake inputs, add `base16-schemes` and override
256+
`nix-colors.inputs.base16-schemes.follows`:
161257
```nix
162258
{
163-
nix.registry.nix-colors.flake = nix-colors;
259+
description = "Your cool config flake";
260+
inputs = {
261+
base16-schemes = "github:you/nix-colors"; # Your base16-schemes fork
262+
263+
nix-colors.url = "github:misterio77/nix-colors";
264+
nix-colors.inputs.base16-schemes.follows = "base16-schemes"; # Be sure to add this
265+
# ...
266+
};
267+
# ...
164268
}
165269
```
166270

167-
It is quite nice to add all your flake inputs as system registries, [here's an example on how to do it](https://github.com/Misterio77/nix-starter-config/blob/minimal/configuration.nix#L67).
271+
- Fork `nix-colors` and edit our `flake.nix` to point at your `base16-schemes`
272+
repo. Then update your flake config to use your `nix-colors` fork.
168273

169274
# Thanks
170275

@@ -173,8 +278,3 @@ Special thanks to rycee for most of this repo's inspiration, plus for the amazin
173278
Huge thanks for everyone involved with base16.
174279

175280
Extra special thanks for my folks at the NixOS Brasil Telegram group, for willing to try this out!
176-
177-
178-
# Roadmap
179-
- Add support for base24 (which is backwards compatible with base16)
180-
- Add more functions for pre-configured application theming (i'd love your help!)

default.nix

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,28 @@
1+
{ base16-schemes ? # If not defined (when not using flakes), download with fetchTarball (by lockfile info)
2+
let
3+
inherit (builtins) fromJSON readFile;
4+
inherit ((fromJSON (readFile ./flake.lock)).nodes.base16-schemes) locked;
5+
in
6+
fetchTarball {
7+
url = "https://github.com/${locked.owner}/${locked.repo}/archive/${locked.rev}.tar.gz";
8+
sha256 = locked.narHash;
9+
}
10+
, ...
11+
}:
112
rec {
213
lib = import ./lib;
3-
colorSchemes = import ./schemes;
4-
homeManagerModules.colorscheme = import ./module;
5-
homeManagerModule = homeManagerModules.colorscheme;
14+
lib-contrib = import ./lib/contrib;
15+
lib-core = import ./lib/core;
16+
17+
colorSchemes = import ./schemes.nix { inherit lib-core base16-schemes; };
18+
# Alias
19+
colorschemes = colorSchemes;
20+
21+
homeManagerModules = rec {
22+
colorScheme = import ./module;
23+
# Alias
24+
colorscheme = colorScheme;
25+
default = colorScheme;
26+
};
27+
homeManagerModule = homeManagerModules.colorScheme;
628
}

0 commit comments

Comments
 (0)