Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change upstream repository to tinted-theming/schemes, support base24, and some chores #58

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ a [home-manager](https://github.com/nix-community/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](https://github.com/base16-project/base16-schemes), then
from [tinted-schemes](https://github.com/tinted-theming/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
Expand All @@ -21,20 +21,23 @@ We also have some optional contrib functions for opinionated, common use cases
(generating scheme from image, generating wallpaper, vim scheme, gtk theme).

## Base16?
[Base16](https://github.com/base16-project/base16) is a standard for defining
[Base16](https://github.com/base16-project/base16) (now is [Tinted Theming](https://github.com/tinted-theming/home)) 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.

## `system` in color schemes?
This is the style of color schemes. There are two kinds of style supported currently: Base16 and Base24. See [Tinted Theming's readme](https://github.com/tinted-theming/home?tab=readme-ov-file#style) for more information.

# 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)
`nix-colors.colorSchemes.base16.dracula` (or create/convert your own)
- Use `config.colorScheme.palette.base0X` to refer to any of the 16 colors from
anywhere!

Expand Down Expand Up @@ -96,7 +99,7 @@ in {
nix-colors.homeManagerModules.default
];

colorScheme = nix-colors.colorSchemes.paraiso;
colorScheme = nix-colors.colorSchemes.base16.paraiso;

# ...
}
Expand All @@ -108,7 +111,7 @@ 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`
`nix-colors.colorSchemes.base16.dracula`

Here's a quick example on how to use it with, say, a terminal emulator (kitty)
and a browser (qutebrowser):
Expand All @@ -118,7 +121,7 @@ and a browser (qutebrowser):
nix-colors.homeManagerModules.default
];

colorScheme = nix-colors.colorSchemes.dracula;
colorScheme = nix-colors.colorSchemes.base16.dracula;

programs = {
kitty = {
Expand All @@ -144,13 +147,14 @@ and a browser (qutebrowser):
```

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

You can, of course, specify (or generate somehow) your nix-colors scheme directly:
```nix
{
colorScheme = {
system = "base16";
slug = "pasque";
name = "Pasque";
author = "Gabriel Fontes (https://github.com/Misterio77)";
Expand Down Expand Up @@ -238,27 +242,27 @@ in {

# Upstreaming new schemes

Please please upstream nice schemes you have created!
Please share nice schemes you have created to upstream!

It's pretty easy to do. Just open up a PR on
[base16-schemes](https://github.com/base16-project/base16-schemes), and once
[tinted-schemes](https://github.com/tinted-theming/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`](#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`:
In your flake inputs, add `schemes` and override
`nix-colors.inputs.schemes.follows`:
```nix
{
description = "Your cool config flake";
inputs = {
base16-schemes = "github:you/base16-schemes"; # Your base16-schemes fork
schemes = "github:you/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
nix-colors.inputs.schemes.follows = "schemes"; # Be sure to add this
# ...
};
# ...
Expand Down
6 changes: 3 additions & 3 deletions default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@ let

in
{ nixpkgs-lib ? import ((fromFlake "nixpkgs-lib") + "/lib")
, base16-schemes ? fromFlake "base16-schemes"
, schemes ? fromFlake "schemes"
, ...
}: rec {
lib-contrib = import ./lib/contrib;
lib-contrib = import ./lib/contrib { inherit nixpkgs-lib; };
lib-core = import ./lib/core { inherit nixpkgs-lib; };
lib = lib-core // { contrib = lib-contrib; };

tests = import ./lib/core/tests { inherit nixpkgs-lib; };

colorSchemes = import ./schemes.nix { inherit lib base16-schemes; };
colorSchemes = import ./schemes.nix { inherit lib schemes; };
# Alias
colorschemes = colorSchemes;

Expand Down
42 changes: 21 additions & 21 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
inputs = {
nixpkgs-lib.url = "github:nix-community/nixpkgs.lib";

# Upstream source of .yaml base16 schemes
base16-schemes.url = "github:tinted-theming/base16-schemes";
base16-schemes.flake = false;
# Upstream source of .yaml schemes
schemes.url = "github:tinted-theming/schemes";
schemes.flake = false;
};

outputs = { self, nixpkgs-lib, base16-schemes }:
outputs = { self, nixpkgs-lib, schemes }:
import ./. {
nixpkgs-lib = nixpkgs-lib.lib;
base16-schemes = base16-schemes.outPath;
schemes = schemes.outPath;
};
}
2 changes: 1 addition & 1 deletion lib/contrib/default.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{ pkgs ? (builtins.trace "nix-colors/lib-contrib: using <nixpkgs> as pkgs because the pkgs parameter was not provided" (import <nixpkgs> { })) }:
{ nixpkgs-lib, pkgs ? (builtins.trace "nix-colors/lib-contrib: using <nixpkgs> as pkgs because the pkgs parameter was not provided" (import <nixpkgs> { })) }:
rec {
# Takes a scheme, resulting wallpaper height and width, plus logo scale, and ouputs the generated wallpaper path
# Example:
Expand Down
15 changes: 14 additions & 1 deletion lib/contrib/from-picture.nix
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
{ pkgs }:
{ nixpkgs-lib, pkgs }:
{
path,
system ? "base16",
variant ? kind,
kind ? "light" # Older alias
}:
import (pkgs.stdenv.mkDerivation {
inherit (nixpkgs-lib) optional;
name = "generated-colorscheme";
buildInputs = with pkgs; [ flavours ];
unpackPhase = "true";
buildPhase = ''
template=$(cat <<-END
{
system = "${system}";
slug = "$(basename ${path} | cut -d '.' -f1)-${variant}";
name = "Generated";
author = "nix-colors";
Expand All @@ -31,6 +34,16 @@ import (pkgs.stdenv.mkDerivation {
base0D = "{{base0D-hex}}";
base0E = "{{base0E-hex}}";
base0F = "{{base0F-hex}}";
'' ++ optional system == "base24" ''
base10 = "{{base10-hex}}";
base11 = "{{base11-hex}}";
base12 = "{{base12-hex}}";
base13 = "{{base13-hex}}";
base14 = "{{base14-hex}}";
base15 = "{{base15-hex}}";
base16 = "{{base16-hex}}";
base17 = "{{base17-hex}}";
'' ++ ''
};
}
END
Expand Down
3 changes: 2 additions & 1 deletion lib/core/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
Example:
schemeFromYAML "pasque" (builtins.readFile ./pasque.yaml) =>
{
system = "base16";
author = "Gabriel Fontes (https://github.com/Misterio77)";
name = "Pasque";
slug = "pasque";
Expand All @@ -29,7 +30,7 @@
*/
schemeFromYAML = import ./schemeFromYAML.nix;

schemeToYAML = builtins.trace "nix-colors: schemeToYAML is deprecated and will be removed soon." (import ./schemeToYAML.nix);
schemeToYAML = import ./schemeToYAML.nix { inherit nixpkgs-lib; };

conversions = import ./conversions.nix { inherit nixpkgs-lib; };
}
26 changes: 18 additions & 8 deletions lib/core/schemeFromYAML.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ let
else
elemAt match 0;
attrLine = line:
let match = builtins.match "([^ :]+): *(.*)" line;
let match = builtins.match "^ *([^ :]+): *(.*)" line;
in if match == null then
throw ''YAML parse failed: "${line}"''
else
Expand All @@ -45,17 +45,27 @@ let
in
mapListToAttrs attrLine lines'';

convertScheme = slug: set: {
convertScheme = slug: set: system: {
inherit system;
name = set.scheme;
inherit (set) author;
inherit slug;
palette = {
inherit (set)
base00 base01 base02 base03 base04 base05 base06 base07 base08 base09
base0A base0B base0C base0D base0E base0F;
};
palette =
if system == "base16" then {
inherit (set)
base00 base01 base02 base03 base04 base05 base06 base07 base08 base09
base0A base0B base0C base0D base0E base0F;
}
else if system == "base24" then {
inherit (set)
base00 base01 base02 base03 base04 base05 base06 base07 base08 base09
base0A base0B base0C base0D base0E base0F
base10 base11 base12 base13 base14 base15 base16 base17;
}
else
throw "Unsupported color scheme system: ${system}";
};

schemeFromYAML = slug: content: convertScheme slug (fromYAML content);
schemeFromYAML = slug: content: convertScheme slug (fromYAML content) (fromYAML content).system;
in
schemeFromYAML
51 changes: 32 additions & 19 deletions lib/core/schemeToYAML.nix
Original file line number Diff line number Diff line change
@@ -1,34 +1,47 @@
{ nixpkgs-lib }:
let
inherit (builtins) concatStringsSep map;
inherit (nixpkgs-lib) optional;

# From nixpkgs, but with newline
concatMapStrings = f: list: concatStringsSep "\n" (map f list);

colorNames = map (n: "base0${n}") [
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"7"
"8"
"9"
"A"
"B"
"C"
"D"
"E"
"F"
];
colorNames = system:
map (n: "base0${n}") [
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"7"
"8"
"9"
"A"
"B"
"C"
"D"
"E"
"F"
] ++ optional system == "base24" map (n: "base1${n}") [
"0"
"1"
"2"
"3"
"4"
"5"
"6"
"7"
];

schemeToYAML = scheme:
''
system: "${scheme.system}"
scheme: "${scheme.name}"
author: "${scheme.author}"
'' + concatMapStrings # Add a line for each base0X color
(color: ''${color}: "${scheme.palette.${color}}"'')
colorNames;
colorNames scheme.system;
in
schemeToYAML
Loading