bahaghari/tinted-theming: init module set

This commit is contained in:
Gabriel Arazas 2024-02-22 14:34:18 +08:00
parent 605ddfc840
commit de6d5dc5b4
No known key found for this signature in database
GPG Key ID: ADE0C41DAB221FCC
6 changed files with 302 additions and 0 deletions

View File

@ -0,0 +1,59 @@
= Bahaghari
:toc:
Bahaghari (Tagalog word for "rainbow") is a specialized set of Nix modules for generating and applying themes.
Mainly useful for making your ricing process with NixOS and home-manager environments easier.
This module set should allow for some flexibility for your use case.
At its current state, Bahaghari is considered unstable and might have breaking changes more than what you'd expect.
== Module sets
As a whole, Bahaghari is more like a set of sets, a metaset, if you will.
Specifically, it is composed of module sets of which has different ways to use them.
Here is the exhaustive list of them and its details.
=== Tinted Theming
Bahaghari has a module set for interacting with Tinted Theming standard schemes and templates.
To use it, simply import it and you're pretty much set.
// TODO: Nix code importing here
Optionally, you can also import Bahaghari's library set for Tinted Theming.
Like most of the library components from Bahaghari, it requires both the `pkgs` and `lib` attribute found from the standard nixpkgs module system.
// TODO: Nix code importing BahagharLib for TT. Also code samples for it.
This module is designed to closely follow Tinted Theming's standard while offering some convenience with the library set.
For example, you can use `importYAML` from Bahaghari's standard library set to easily import standard Base16 schemes into Nix-representable data which you can press onto your Nix configuration.
// TODO: GNOME HIG module set
=== Templated configuration sub-modules
Bahaghari offers a pre-configured version of already existing modules for NixOS, home-manager, and NixVim quite similar to Stylix's `stylix.targets.<name>` submodules.
To make use of this, you'll have to import Bahaghari module set's
// TODO: Pictures and sample configurations
== Comparison with other modules
=== nix-colors
Bahaghari initially started as a derivative to nix-colors as a single Nix module entirely dedicated for Tinted Theming standard.
It was created to address its limitation of allowing only one colorscheme at a time which limits a lot of possible applications.
Most notably, the feature I'm looking for is generating multiple colorscheme templates for different applications which is nice for hybrid deployments of home-manager-plus-mutable-configurations (AKA traditional dotfiles).
While Bahaghari eventually diverged from nix-colors entirely, it can be used as an alternative specifically with Bahaghari's Tinted Theming module set.
You can replicate nix-colors' preference of allowing a default set of colorscheme
== Stylix
While Bahaghari can be used similarly to Stylix, it isn't completely 1-to-1 to Stylix as it focuses on the holistic side of customization including for fonts and wallpaper.
On the other hand, Bahaghari completely focuses on colorscheme generation. footnote:[While Bahaghari as a project can also focus beyond colorschemes similar to Stylix, it isn't a part of the vision for now. Who knows, it might be. ;)]
Bahaghari also took some cues from Stylix specifically from its Stylix targets which became the pre-templated configurations submodules for each of the module set.

View File

@ -0,0 +1,28 @@
{ pkgs, lib }:
{
# A very naive implementation of checking if a Tinted Theming scheme is a
# Base16 scheme.
isBase16 = palette:
let
paletteNames = lib.attrNames palette;
schemeNames = builtins.map (number: "base${number}") [
"00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A"
"0B" "0C" "0D" "0E" "0F"
];
in
(lib.count (name: lib.elem name schemeNames) paletteNames) == 16;
# A very naive implementation of checking if a Tinted Theming scheme is a
# Base24 scheme.
isBase24 = palette:
let
paletteNames = lib.attrNames palette;
schemeNames = builtins.map (number: "base${number}") [
"00" "01" "02" "03" "04" "05" "06" "07" "08" "09" "0A"
"0B" "0C" "0D" "0E" "0F" "10" "11" "12" "13" "14" "15"
"16" "17"
];
in
(lib.count (name: lib.elem name schemeNames) paletteNames) == 24;
}

View File

@ -0,0 +1,29 @@
# A Bahaghari module for interacting with the Tinted Theming builder.
{ config, lib, pkgs, ... }:
let
cfg = config.bahaghari;
in
{
options.bahaghari.tinted-theming.builder = {
package = lib.mkPackageOption pkgs "base16-builder-go" { };
extraArgs = lib.mkOption {
type = with lib.types; functionTo str;
default = args: ''
${lib.getExe' pkgs.base16-builder-go "base16-builder-go"} \
-schemes-dir ${lib.escapeShellArg args.schemesDir} \
-template-dir ${lib.escapeShell args.template}
'';
description = ''
A function returning a script to be applied per-template. The
function parameter is an attribute set with the following values:
* `template` contains the path to the template.
* `name` is the attribute name of the template.
* `schemesDir` is a path containing all of the schemes as a YAML file
(technically a JSON file).
'';
};
};
}

View File

@ -0,0 +1,8 @@
# Bahaghari's Tinted Theming user-facing module set.
{
imports = [
./builder.nix
./schemes.nix
./templates.nix
];
}

View File

@ -0,0 +1,150 @@
# Essentially a derivative of nix-colors module that closely follows Tinted
# Theming "standard" and can hold multiple palettes suitable for generating
# multiple configuration files for organization purposes.
{ pkgs, lib, ... }:
let
inherit (import ../../lib/tinted-theming.nix { inherit pkgs lib; }) isBase24 isBase16;
# This follows the schema of a Tinted Theming scheme. Its support for legacy
# Base16 theme is pretty awful for now. Anyways. this would allow a simple
# `lib.importYAML` and wam-bam-thank-you-mam.
schemeType = { name, config, lib, ... }: {
# This would allow extensions to the schema if the scheme author or the
# user wants to add some.
freeformType = with lib.types; attrsOf anything;
options = {
# The builder will be the one to detect these properly. Though, we could
# also detect this ourselves as well... but with Nixlang? REALLY!?!
system = lib.mkOption {
type = with lib.types; nullOr (enum [ "base16" "base24" ]);
default =
if (isBase24 config.palette)
then "base24"
else if (isBase16 config.palette)
then "base16"
else null;
example = "base24";
description = ''
Indicates which system this scheme supports. This is mainly on the
builder to properly detect this.
'';
};
author = lib.mkOption {
type = lib.types.nonEmptyStr;
default = "Scheme Author";
example = "You (ME?)";
description = ''
The scheme author's readable name.
'';
};
name = lib.mkOption {
type = lib.types.nonEmptyStr;
default = name;
example = "Bark on a tree";
description = ''
The human-readable name of the scheme.
'';
};
description = lib.mkOption {
type = with lib.types; nullOr str;
default = null;
example = "Rusty theme inspired from the forestry (and Nord theme).";
description = "A short description of the theme.";
};
variant = lib.mkOption {
type = with lib.types; nullOr (enum [ "dark" "light" ]);
default = null;
example = "light";
description = ''
The variant of the theme. This is typically associated with already
existing standards such as the FreeDesktop appearance preferences or
Vim `background` settings.
'';
};
palette = lib.mkOption {
type = with lib.types; attrsOf (
coercedTo str (lib.removePrefix "#") str
);
default = { };
example = {
base00 = "2b221f";
base01 = "412c26";
base02 = "5c362c";
base03 = "a45b43";
base04 = "e1bcb2";
base05 = "f5ecea";
base06 = "fefefe";
base07 = "eb8a65";
base08 = "d03e68";
base09 = "df937a";
base0A = "afa644";
base0B = "85b26e";
base0C = "eb914a";
base0D = "c67f62";
base0E = "8b7ab9";
base0F = "7f3F83";
};
description = ''
A set of colors. For this module, we place a small additional
restriction in here that all attributes should be a string. It is
common to set colors in HTML hex format.
'';
};
};
};
in
{
options.bahaghari.tinted-theming = {
schemes = lib.mkOption {
type = with lib.types; attrsOf (submodule schemeType);
default = { };
example = {
"bark-on-a-tree" = {
system = "base16";
author = "Gabriel Arazas";
description = ''
Rusty and woody theme inspired from forestry (and Nord theme).
'';
variant = "dark";
palette = rec {
background = base00;
foreground = base05;
base00 = "2b221f";
base01 = "412c26";
base02 = "5c362c";
base03 = "a45b43";
base04 = "e1bcb2";
base05 = "f5ecea";
base06 = "fefefe";
base07 = "eb8a65";
base08 = "d03e68";
base09 = "df937a";
base0A = "afa644";
base0B = "85b26e";
base0C = "eb914a";
base0D = "c67f62";
base0E = "8b7ab9";
base0F = "7f3F83";
};
};
};
description = ''
A set of [Tinted Theming](https://github.com/tinted-theming) schemes.
You can set the palette to whatever criteria you deem suitable but this
module closely follows the main standards with this theming ecosystem
(specifically Base16 and Base24).
The most common palette scheme is Base16 where the colors are set from
`base00` to `base0F`. Some themes could have 24-colors variant or have
additional meaningful names (e.g., `foreground`, `background`).
'';
};
};
}

View File

@ -0,0 +1,28 @@
# A set of Tinted Theming templates to be applied somewhere. At its current
# state, this module is useless itself that it only holds a global set of
# templates for now.
{ lib, ... }:
{
options.bahaghari.tinted-theming = {
templates = lib.mkOption {
type = with lib.types; attrsOf path;
default = { };
example = lib.literalExpression ''
{
vim = pkgs.fetchFromGitHub {
owner = "tinted-theming";
repo = "base16-vim";
rev = "tinted-theming/base16-vim";
hash = "sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=";
};
helix = ./templates/helix;
}
'';
description = ''
A set of Tinted Theming templates to be applied for the schemes.
'';
};
};
}