custom schemes

This commit is contained in:
Dmitriy Kholkin 2020-08-10 18:58:49 +04:00
parent 7039e397b2
commit 8eaa7ac1cb
Signed by: AtaraxiaDev
GPG Key ID: FD266B810DF48DF2
2 changed files with 105 additions and 25 deletions

View File

@ -6,6 +6,7 @@ Differences:
- Returns support for obtaining color values from the color scheme
- Added possibility to select a template type (`'default'`, `'color'`, etc)
- Added possibility to use custom schemes by importing local files or remote repository
- Removed unused files
## Usage
@ -90,6 +91,57 @@ home.user.${user} = { config, pkgs, lib }: {
}
```
You can also use local schemes:
```nix
{ pkgs, lib, config, ...}:
{
config = {
# Choose your theme
themes.base16 = {
enable = true;
customScheme = {
enable = true;
path = ./base16-custom-scheme.yaml;
}
};
};
}
```
Or use an imported color scheme:
For example, import scheme repository into yours 'flake.nix'
```nix
inputs.base16-horizon-scheme = {
url = github:michael-ball/base16-horizon-scheme;
flake = false;
};
```
```nix
{ pkgs, lib, config, inputs, ...}:
{
config = {
# Choose your theme
themes.base16 = {
enable = true;
customScheme = {
enable = true;
path = "${inputs.base16-horizon-scheme}/horizon-dark.yaml";
}
};
# The template will be generated from the local scheme
programs.rofi = {
enable = true;
theme = "${config.lib.base16.templateFile { name = "rofi"; };}";
};
};
}
```
## Reloading
Changing themes involves switching the theme definition and typing
@ -101,12 +153,6 @@ enough.
You are unlikely to achieve a complete switch without logging out and logging back
in again.
## Todo
Provide better support for custom schemes (currently it
is assumed that you'll use something in base16
repositories, but there is no reason to).
## Updating Sources
If you're using nix flakes:
@ -120,3 +166,7 @@ If you're **not** using nix flakes:
- `cd` into repository dir
- Run `update_sources.sh`
## Todo
Improve the source code.

View File

@ -53,34 +53,64 @@ let
allowSubstitutes = false; # will never be in cache
};
mustacheCustom = schemePath: name: type:
pkgs.stdenv.mkDerivation {
name = "${name}-base16-scheme";
data = preprocess schemePath;
src = mkTemplate name type;
phases = [ "buildPhase" ];
buildPhase ="${pkgs.mustache-go}/bin/mustache $data $src > $out";
allowSubstitutes = false; # will never be in cache
};
schemeJSON = scheme: variant:
importJSON (preprocess (mkTheme scheme variant));
schemeJSONCustom = schemePath:
importJSON (preprocess schemePath);
in
{
options = {
themes.base16.enable = mkEnableOption "Base 16 Color Schemes";
themes.base16.scheme = mkOption {
type = types.str;
default = "solarized";
};
themes.base16.variant = mkOption {
type = types.str;
default = "solarized-dark";
};
themes.base16.extraParams = mkOption {
type = types.attrsOf types.str;
default = {};
};
themes.base16.defaultTemplateType = mkOption {
type = types.str;
default = "default";
example = "colors";
options = with types; {
themes.base16 = {
enable = mkEnableOption "Base 16 Color Schemes";
customScheme = {
enable = mkEnableOption "Use custom scheme instead of remote repository";
path = mkOption {
type = nullOr path;
default = null;
};
};
scheme = mkOption {
type = str;
default = "solarized";
};
variant = mkOption {
type = str;
default = "solarized-dark";
};
extraParams = mkOption {
type = attrsOf str;
default = {};
};
defaultTemplateType = mkOption {
type = str;
default = "default";
example = "colors";
};
};
};
config = {
lib.base16.theme = schemeJSON cfg.scheme cfg.variant // cfg.extraParams;
lib.base16.theme =
if cfg.customScheme.enable then
schemeJSONCustom cfg.customScheme.path // cfg.extraParams
else
schemeJSON cfg.scheme cfg.variant // cfg.extraParams;
lib.base16.templateFile = { name, type ? cfg.defaultTemplateType, ... }:
if cfg.customScheme.enable then
mustacheCustom cfg.customScheme.path name type
else
mustache cfg.scheme cfg.variant name type;
};
}