From b48f8f14609928cce197616f42cabeffb12366b5 Mon Sep 17 00:00:00 2001 From: command_block Date: Thu, 23 May 2024 23:24:44 +0800 Subject: [PATCH 1/3] change upstream to tinted-theming/schemes, support base24 schemes --- README.md | 28 +++++++++++++----------- default.nix | 6 +++--- flake.lock | 42 ++++++++++++++++++------------------ flake.nix | 10 ++++----- lib/contrib/default.nix | 2 +- lib/contrib/from-picture.nix | 15 ++++++++++++- lib/core/default.nix | 1 + lib/core/schemeFromYAML.nix | 26 +++++++++++++++------- module/colorscheme.nix | 8 +++++++ schemes.nix | 32 ++++++++++++++++++--------- 10 files changed, 109 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index 53f5b93..d0c8bd5 100644 --- a/README.md +++ b/README.md @@ -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 @@ -21,12 +21,15 @@ 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: @@ -34,7 +37,7 @@ The usual setup looks like this: 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! @@ -96,7 +99,7 @@ in { nix-colors.homeManagerModules.default ]; - colorScheme = nix-colors.colorSchemes.paraiso; + colorScheme = nix-colors.colorSchemes.base16.paraiso; # ... } @@ -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): @@ -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 = { @@ -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)"; @@ -241,7 +245,7 @@ in { Please please upstream nice schemes you have created! 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 @@ -249,16 +253,16 @@ 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 # ... }; # ... diff --git a/default.nix b/default.nix index 4c13a54..b7d28ab 100644 --- a/default.nix +++ b/default.nix @@ -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; diff --git a/flake.lock b/flake.lock index a6c248a..4f32d0c 100644 --- a/flake.lock +++ b/flake.lock @@ -1,28 +1,12 @@ { "nodes": { - "base16-schemes": { - "flake": false, - "locked": { - "lastModified": 1696158499, - "narHash": "sha256-5yIHgDTPjoX/3oDEfLSQ0eJZdFL1SaCfb9d6M0RmOTM=", - "owner": "tinted-theming", - "repo": "base16-schemes", - "rev": "a9112eaae86d9dd8ee6bb9445b664fba2f94037a", - "type": "github" - }, - "original": { - "owner": "tinted-theming", - "repo": "base16-schemes", - "type": "github" - } - }, "nixpkgs-lib": { "locked": { - "lastModified": 1697935651, - "narHash": "sha256-qOfWjQ2JQSQL15KLh6D7xQhx0qgZlYZTYlcEiRuAMMw=", + "lastModified": 1716079763, + "narHash": "sha256-DGRfb7fO7c3XDS3twmuaV5NAGPPdU3W7Q35fjIZc8iY=", "owner": "nix-community", "repo": "nixpkgs.lib", - "rev": "e1e11fdbb01113d85c7f41cada9d2847660e3902", + "rev": "0df131b5ee4d928a4b664b6d0cd99cf134d6ab6b", "type": "github" }, "original": { @@ -33,8 +17,24 @@ }, "root": { "inputs": { - "base16-schemes": "base16-schemes", - "nixpkgs-lib": "nixpkgs-lib" + "nixpkgs-lib": "nixpkgs-lib", + "schemes": "schemes" + } + }, + "schemes": { + "flake": false, + "locked": { + "lastModified": 1713388094, + "narHash": "sha256-wcotm0Ek2ISn8iJBzEujJQdcPLKWrPAOZ/dS/DLKafw=", + "owner": "tinted-theming", + "repo": "schemes", + "rev": "abcf2a055ae69f1bf047463332f83db3125aa8a5", + "type": "github" + }, + "original": { + "owner": "tinted-theming", + "repo": "schemes", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index d3c33b5..af06f1a 100644 --- a/flake.nix +++ b/flake.nix @@ -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; }; } diff --git a/lib/contrib/default.nix b/lib/contrib/default.nix index 2743561..dbe11c0 100644 --- a/lib/contrib/default.nix +++ b/lib/contrib/default.nix @@ -1,4 +1,4 @@ -{ pkgs ? (builtins.trace "nix-colors/lib-contrib: using as pkgs because the pkgs parameter was not provided" (import { })) }: +{ nixpkgs-lib, pkgs ? (builtins.trace "nix-colors/lib-contrib: using as pkgs because the pkgs parameter was not provided" (import { })) }: rec { # Takes a scheme, resulting wallpaper height and width, plus logo scale, and ouputs the generated wallpaper path # Example: diff --git a/lib/contrib/from-picture.nix b/lib/contrib/from-picture.nix index 2fa6e40..2f58130 100644 --- a/lib/contrib/from-picture.nix +++ b/lib/contrib/from-picture.nix @@ -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"; @@ -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 diff --git a/lib/core/default.nix b/lib/core/default.nix index 293435f..d030fb0 100644 --- a/lib/core/default.nix +++ b/lib/core/default.nix @@ -4,6 +4,7 @@ Example: schemeFromYAML "pasque" (builtins.readFile ./pasque.yaml) => { + system = "base16"; author = "Gabriel Fontes (https://github.com/Misterio77)"; name = "Pasque"; slug = "pasque"; diff --git a/lib/core/schemeFromYAML.nix b/lib/core/schemeFromYAML.nix index 03da949..b759dff 100644 --- a/lib/core/schemeFromYAML.nix +++ b/lib/core/schemeFromYAML.nix @@ -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 @@ -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 diff --git a/module/colorscheme.nix b/module/colorscheme.nix index 8f97ae9..362f373 100644 --- a/module/colorscheme.nix +++ b/module/colorscheme.nix @@ -18,6 +18,14 @@ in ]; options.colorScheme = { + system = mkOption { + type = types.str; + default = "base16"; + example = "base16"; + description = '' + Color scheme system + ''; + }; slug = mkOption { type = types.str; example = "awesome-scheme"; diff --git a/schemes.nix b/schemes.nix index 065db43..e315831 100644 --- a/schemes.nix +++ b/schemes.nix @@ -1,4 +1,4 @@ -{ lib, base16-schemes, ... }: +{ lib, schemes, ... }: let inherit (builtins) readFile readDir attrNames listToAttrs stringLength substring baseNameOf @@ -28,15 +28,27 @@ let isYamlFile = filename: (hasSuffix ".yml" filename) || (hasSuffix ".yaml" filename); - colorSchemeFiles = filter isYamlFile (attrNames (readDir base16-schemes)); + getColorSchemeFiles = source: system: + filter isYamlFile (attrNames (readDir "${source}/${system}")); - colorSchemes = listToAttrs (map - (filename: rec { - # Scheme slug - name = stripYamlExtension (baseNameOf filename); - # Scheme contents - value = schemeFromYAML name (readFile "${base16-schemes}/${filename}"); - }) - colorSchemeFiles); + getColorSchemes = colorSchemeFiles: system: + listToAttrs (map + (filename: rec { + # Scheme slug + name = stripYamlExtension (baseNameOf filename); + # Scheme contents + value = schemeFromYAML name (readFile "${schemes}/${system}/${filename}"); + }) + colorSchemeFiles); + + colorSchemeFiles = { + base16 = getColorSchemeFiles schemes "base16"; + base24 = getColorSchemeFiles schemes "base24"; + }; + + colorSchemes = { + base16 = getColorSchemes colorSchemeFiles.base16 "base16"; + base24 = getColorSchemes colorSchemeFiles.base24 "base24"; + }; in colorSchemes From 61f06d4d96db9132110abe6ffc50818e1aaa146b Mon Sep 17 00:00:00 2001 From: command_block Date: Fri, 24 May 2024 02:34:24 +0800 Subject: [PATCH 2/3] add base24 support for schemeToYAML --- lib/core/default.nix | 2 +- lib/core/schemeToYAML.nix | 51 ++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/lib/core/default.nix b/lib/core/default.nix index d030fb0..1936cf2 100644 --- a/lib/core/default.nix +++ b/lib/core/default.nix @@ -30,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; }; } diff --git a/lib/core/schemeToYAML.nix b/lib/core/schemeToYAML.nix index 45b53a8..69b546e 100644 --- a/lib/core/schemeToYAML.nix +++ b/lib/core/schemeToYAML.nix @@ -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 From 95b194675d9300fb22cd47a431fb2a443f606cd4 Mon Sep 17 00:00:00 2001 From: command_block Date: Fri, 24 May 2024 01:55:08 +0800 Subject: [PATCH 3/3] fix typo --- README.md | 2 +- module/colorscheme.nix | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d0c8bd5..74285e0 100644 --- a/README.md +++ b/README.md @@ -242,7 +242,7 @@ 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 [tinted-schemes](https://github.com/tinted-theming/schemes), and once diff --git a/module/colorscheme.nix b/module/colorscheme.nix index 362f373..ab46355 100644 --- a/module/colorscheme.nix +++ b/module/colorscheme.nix @@ -46,7 +46,7 @@ in default = ""; example = "A very nice theme"; description = '' - Color scheme author + Color scheme description ''; }; author = mkOption {