nix: minor flake refactor; provide GTK and QT theme packages

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I136253e0d928e71e61824bc3f3b5a0726a6a6964
This commit is contained in:
raf 2026-05-14 11:32:16 +03:00
commit 571f60b1a0
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
5 changed files with 346 additions and 21 deletions

View file

@ -2,48 +2,91 @@
description = "Base16/Base24 schemes for Nix";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs?ref=nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-compat = {
url = "github:edolstra/flake-compat";
flake = false;
};
};
outputs = inputs @ {
outputs = {
flake-parts,
self,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
perSystem = {pkgs, ...}: {
} @ inputs:
flake-parts.lib.mkFlake {inherit inputs;} (let
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin"];
# FWIW this could also be lib.extend but lib.extend itself claims that
# it should not be used, so we do this instead.
inherit (inputs.nixpkgs) lib;
basixLib = import ./lib.nix {inherit lib;};
mkThemeAttrSet = pkgs: schemes: let
mkGtkTheme = pkgs.callPackage ./packages/gtk/package.nix {basixLib = self.lib;};
mkQtctTheme = pkgs.callPackage ./packages/qtct/package.nix {basixLib = self.lib;};
mkKvantumTheme = pkgs.callPackage ./packages/kvantum/package.nix {basixLib = self.lib;};
in
lib.mapAttrs (slug: scheme:
pkgs.symlinkJoin {
name = "basix-theme-${self.lib.sanitizeSlug slug}";
paths = [
(mkGtkTheme {inherit slug scheme;})
(mkQtctTheme {inherit slug scheme;})
(mkKvantumTheme {inherit slug scheme;})
];
})
schemes;
mkSystemThemePackages = system: let
pkgs = import inputs.nixpkgs {inherit system;};
in {
base16 = mkThemeAttrSet pkgs self.schemeData.base16;
base24 = mkThemeAttrSet pkgs self.schemeData.base24;
};
in {
inherit systems;
perSystem = {
pkgs,
system,
...
}: let
themePackages = self.themePackages.${system};
in {
packages = {
# Converts YAML -> JSON
convert-scheme = pkgs.callPackage ./packages/convert-scheme/package.nix {};
# Theme collections
themes-base16 = pkgs.symlinkJoin {
name = "basix-themes-base16";
paths = lib.attrValues themePackages.base16;
};
themes-base24 = pkgs.symlinkJoin {
name = "basix-themes-base24";
paths = lib.attrValues themePackages.base24;
};
themes-all = pkgs.symlinkJoin {
name = "basix-themes-all-${system}";
paths = (lib.attrValues themePackages.base16) ++ (lib.attrValues themePackages.base24);
};
};
};
flake = let
inherit (inputs.nixpkgs) lib;
evalSchemeData = lib.flip lib.pipe [
builtins.unsafeDiscardStringContext
lib.filesystem.listFilesRecursive
(builtins.filter (lib.hasSuffix ".json"))
(map (n: {
name = lib.removePrefix ((dirOf n) + "/") (lib.removeSuffix ".json" n);
value = lib.importJSON n;
}))
lib.listToAttrs
];
inherit (basixLib) evalSchemeData;
in {
lib = {
inherit evalSchemeData;
};
lib = basixLib;
schemeData = {
base16 = evalSchemeData "${self}/json/base16";
base24 = evalSchemeData "${self}/json/base24";
};
themePackages = lib.genAttrs systems mkSystemThemePackages;
};
};
});
}

63
lib.nix Normal file
View file

@ -0,0 +1,63 @@
{lib}: let
requiredBaseKeys = [
"base00"
"base01"
"base02"
"base03"
"base04"
"base05"
"base06"
"base07"
"base08"
"base09"
"base0A"
"base0B"
"base0C"
"base0D"
"base0E"
"base0F"
];
sanitizeSlug = slug:
lib.strings.sanitizeDerivationName
(lib.strings.toLower (toString slug));
normalizeHex = color:
lib.strings.toLower
(lib.removePrefix "#" (toString color));
missingBaseKeys = palette:
builtins.filter (key: !(builtins.hasAttr key palette)) requiredBaseKeys;
validatePalette = {
slug,
palette,
}: let
missing = missingBaseKeys palette;
in
if missing != []
then throw "Basix theme generation failed for `${slug}`: missing palette keys ${lib.concatStringsSep ", " missing} (required: base00-base0F)"
else palette;
mkThemeName = slug: "Basix-${sanitizeSlug slug}";
evalSchemeData = lib.flip lib.pipe [
builtins.unsafeDiscardStringContext
lib.filesystem.listFilesRecursive
(builtins.filter (lib.hasSuffix ".json"))
(map (n: {
name = lib.removePrefix ((dirOf n) + "/") (lib.removeSuffix ".json" n);
value = lib.importJSON n;
}))
lib.listToAttrs
];
in {
inherit
evalSchemeData
mkThemeName
normalizeHex
requiredBaseKeys
sanitizeSlug
validatePalette
;
}

109
packages/gtk/package.nix Normal file
View file

@ -0,0 +1,109 @@
{
basixLib,
lib,
stdenvNoCC,
}: {
slug,
scheme,
}: let
palette = basixLib.validatePalette {
inherit slug;
palette = scheme.palette or {};
};
slugSafe = basixLib.sanitizeSlug slug;
themeName = basixLib.mkThemeName slugSafe;
hex = key: basixLib.normalizeHex palette.${key};
gtkrc = ''
gtk-color-scheme = "bg_color:#${hex "base00"}\nfg_color:#${hex "base05"}\nbase_color:#${hex "base01"}\ntext_color:#${hex "base05"}\nselected_bg_color:#${hex "base0D"}\nselected_fg_color:#${hex "base00"}\ntooltip_bg_color:#${hex "base01"}\ntooltip_fg_color:#${hex "base05"}"
style "basix-default" {
bg[NORMAL] = "#${hex "base00"}"
bg[ACTIVE] = "#${hex "base02"}"
bg[PRELIGHT] = "#${hex "base01"}"
bg[SELECTED] = "#${hex "base0D"}"
fg[NORMAL] = "#${hex "base05"}"
fg[INSENSITIVE] = "#${hex "base04"}"
fg[SELECTED] = "#${hex "base00"}"
text[NORMAL] = "#${hex "base05"}"
text[SELECTED] = "#${hex "base00"}"
base[NORMAL] = "#${hex "base01"}"
base[INSENSITIVE] = "#${hex "base03"}"
base[SELECTED] = "#${hex "base0D"}"
}
class "*" style "basix-default"
'';
gtkCss = ''
@define-color bg_color #${hex "base00"};
@define-color fg_color #${hex "base05"};
@define-color base_color #${hex "base01"};
@define-color text_color #${hex "base05"};
@define-color selected_bg_color #${hex "base0D"};
@define-color selected_fg_color #${hex "base00"};
@define-color borders #${hex "base03"};
@define-color warning_color #${hex "base09"};
@define-color error_color #${hex "base08"};
@define-color success_color #${hex "base0B"};
window, dialog, popover, menu, viewport {
background-color: @bg_color;
color: @fg_color;
}
entry, textview, treeview, list {
background-color: @base_color;
color: @text_color;
border: 1px solid @borders;
}
button, headerbar, toolbar {
background-color: @base_color;
color: @fg_color;
border: 1px solid @borders;
box-shadow: none;
}
scrollbar slider {
background-color: @base_color;
border: 1px solid @borders;
}
selection {
background-color: @selected_bg_color;
color: @selected_fg_color;
}
'';
in
stdenvNoCC.mkDerivation {
pname = "basix-gtk-theme-${slugSafe}";
version = "1.0.0";
dontUnpack = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/share/themes/${themeName}/gtk-2.0"
mkdir -p "$out/share/themes/${themeName}/gtk-3.0"
mkdir -p "$out/share/themes/${themeName}/gtk-4.0"
cat > "$out/share/themes/${themeName}/gtk-2.0/gtkrc" <<'EOF_GTK2'
${gtkrc}
EOF_GTK2
cat > "$out/share/themes/${themeName}/gtk-3.0/gtk.css" <<'EOF_GTK3'
${gtkCss}
EOF_GTK3
cat > "$out/share/themes/${themeName}/gtk-4.0/gtk.css" <<'EOF_GTK4'
${gtkCss}
EOF_GTK4
runHook postInstall
'';
meta = {
description = "Generated GTK theme assets for Basix schemes";
platforms = lib.platforms.all;
license = lib.licenses.gpl3Only;
};
}

View file

@ -0,0 +1,60 @@
{
basixLib,
lib,
stdenvNoCC,
}: {
slug,
scheme,
}: let
palette = basixLib.validatePalette {
inherit slug;
palette = scheme.palette or {};
};
slugSafe = basixLib.sanitizeSlug slug;
themeName = basixLib.mkThemeName slugSafe;
hex = key: basixLib.normalizeHex palette.${key};
kvConfig = ''
[GeneralColors]
window.color=#${hex "base00"}
button.color=#${hex "base02"}
text.color=#${hex "base05"}
disabled.text.color=#${hex "base04"}
highlight.color=#${hex "base0D"}
highlighted.text.color=#${hex "base00"}
'';
kvSvg = ''
<?xml version="1.0" encoding="UTF-8"?>
<svg xmlns="http://www.w3.org/2000/svg" width="64" height="64" version="1.1">
<rect x="0" y="0" width="64" height="64" fill="#${hex "base00"}"/>
<rect x="8" y="8" width="48" height="20" rx="2" ry="2" fill="#${hex "base02"}"/>
<rect x="8" y="36" width="48" height="20" rx="2" ry="2" fill="#${hex "base0D"}"/>
</svg>
'';
in
stdenvNoCC.mkDerivation {
pname = "basix-kvantum-theme-${slugSafe}";
version = "1.0.0";
dontUnpack = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/share/Kvantum/${themeName}"
cat > "$out/share/Kvantum/${themeName}/${themeName}.kvconfig" <<'EOF_KVCONFIG'
${kvConfig}
EOF_KVCONFIG
cat > "$out/share/Kvantum/${themeName}/${themeName}.svg" <<'EOF_KVSVG'
${kvSvg}
EOF_KVSVG
runHook postInstall
'';
meta = {
description = "Generated Kvantum theme assets for Basix schemes";
platforms = lib.platforms.all;
license = lib.licenses.gpl3Only;
};
}

50
packages/qtct/package.nix Normal file
View file

@ -0,0 +1,50 @@
{
basixLib,
lib,
stdenvNoCC,
}: {
slug,
scheme,
}: let
palette = basixLib.validatePalette {
inherit slug;
palette = scheme.palette or {};
};
slugSafe = basixLib.sanitizeSlug slug;
themeName = basixLib.mkThemeName slugSafe;
hex = key: basixLib.normalizeHex palette.${key};
argb = key: "#ff${hex key}";
qtConf = ''
[ColorScheme]
active_colors=${argb "base00"},${argb "base05"},${argb "base01"},${argb "base02"},${argb "base03"},${argb "base04"},${argb "base0D"},${argb "base00"},${argb "base08"},${argb "base09"},${argb "base0A"},${argb "base0B"},${argb "base0C"},${argb "base0E"}
disabled_colors=${argb "base03"},${argb "base04"},${argb "base02"},${argb "base03"},${argb "base03"},${argb "base04"},${argb "base03"},${argb "base04"},${argb "base08"},${argb "base09"},${argb "base0A"},${argb "base0B"},${argb "base0C"},${argb "base0E"}
inactive_colors=${argb "base00"},${argb "base05"},${argb "base01"},${argb "base02"},${argb "base03"},${argb "base04"},${argb "base0D"},${argb "base00"},${argb "base08"},${argb "base09"},${argb "base0A"},${argb "base0B"},${argb "base0C"},${argb "base0E"}
'';
in
stdenvNoCC.mkDerivation {
pname = "basix-qtct-theme-${slugSafe}";
version = "1.0.0";
dontUnpack = true;
installPhase = ''
runHook preInstall
mkdir -p "$out/share/qt5ct/colors"
mkdir -p "$out/share/qt6ct/colors"
cat > "$out/share/qt5ct/colors/${themeName}.conf" <<'EOF_QT'
${qtConf}
EOF_QT
cat > "$out/share/qt6ct/colors/${themeName}.conf" <<'EOF_QT'
${qtConf}
EOF_QT
runHook postInstall
'';
meta = {
description = "Generated qt5ct and qt6ct color schemes for Basix schemes";
platforms = lib.platforms.all;
license = lib.licenses.gpl3Only;
};
}