big restruct

This commit is contained in:
cnst
2024-08-02 21:27:09 +02:00
parent c65a8ac71d
commit f99d9fe4e5
364 changed files with 95 additions and 84 deletions

View File

@@ -0,0 +1,54 @@
# stolen from https://github.com/diniamo/niqspkgs/blob/544c3b2c69fd1b5ab3407e7b35c76060801a8bcf/pkgs/bibata-hyprcursor/default.nix
from sys import argv
import os
from os import path
from pathlib import Path
import tomli
import tomli_w
def fallback_value(config, cursor, field):
return (config.get(cursor, None) or {}).get(field, None) or (
config["fallback_settings"].get(field, None)
)
def filter_none_dict(**kwargs):
return {k: v for k, v in kwargs.items() if v is not None}
def construct_meta(config, name, sizes):
meta = filter_none_dict(
define_size=";".join(sizes),
define_override=(
None
if (overrides := fallback_value(config, name, "x11_symlinks")) is None
else ";".join(overrides)
),
hotspot_x=fallback_value(config, name, "x_hotspot") / 256,
hotspot_y=fallback_value(config, name, "y_hotspot") / 256,
)
with open(f"{name}/meta.toml", "wb") as file:
tomli_w.dump({"General": meta}, file)
with open(argv[1], "rb") as file:
config = tomli.load(file)["cursors"]
os.chdir(argv[2])
for cursor in os.listdir("."):
if path.isfile(cursor):
name = Path(cursor).stem
os.mkdir(name)
os.rename(cursor, f"{name}/{cursor}")
construct_meta(config, name, [f"0,{cursor}"])
else:
delay = fallback_value(config, cursor, "x11_delay")
construct_meta(
config, cursor, map(lambda c: f"0,{c},{delay}", os.listdir(cursor))
)

View File

@@ -0,0 +1,94 @@
# stolen from https://github.com/diniamo/niqspkgs/blob/544c3b2c69fd1b5ab3407e7b35c76060801a8bcf/pkgs/bibata-hyprcursor/default.nix
{
lib,
stdenvNoCC,
fetchFromGitHub,
python3,
python3Packages,
hyprcursor,
variant ? "modern",
baseColor ? "#000000",
outlineColor ? "#FFFFFF",
watchBackgroundColor ? "#000000",
colorName ? "classic",
}: let
capitalize = str: let
capital_letter = builtins.substring 0 1 str;
non_capital = lib.removePrefix capital_letter str;
in
lib.toUpper capital_letter + non_capital;
themeName = "Bibata-${capitalize variant}-${capitalize colorName}";
in
assert builtins.elem variant ["modern" "modern-right" "original" "original-right"];
stdenvNoCC.mkDerivation (final: {
pname = "bibata-hyprcursor";
version = "v2.0.7";
src = fetchFromGitHub {
owner = "ful1e5";
repo = "Bibata_Cursor";
rev = final.version;
hash = "sha256-kIKidw1vditpuxO1gVuZeUPdWBzkiksO/q2R/+DUdEc=";
};
nativeBuildInputs = [
python3
python3Packages.tomli
python3Packages.tomli-w
hyprcursor
];
phases = ["unpackPhase" "configurePhase" "buildPhase" "installPhase"];
unpackPhase = ''
runHook preUnpack
cp $src/configs/${
if lib.hasSuffix "right" variant
then "right"
else "normal"
}/x.build.toml config.toml
mkdir cursors
for cursor in $src/svg/${variant}/*; do
cp -r $src/svg/${variant}/$(readlink $cursor) cursors
done
chmod -R u+w .
runHook postUnpack
'';
configurePhase = ''
runHook preConfigure
cat << EOF > manifest.hl
name = ${themeName}
description = The Bibata Cursor theme packaged for hyprcursor.
version = ${final.version}
cursors_directory = cursors
EOF
find cursors -type f -name '*.svg' | xargs sed -i -e 's/#00FF00/${baseColor}/g' -e 's/#0000FF/${outlineColor}/g' -e 's/#FF0000/${watchBackgroundColor}/g'
python ${./configure.py} config.toml cursors
runHook postConfigure
'';
buildPhase = ''
runHook preBuild
hyprcursor-util --create . --output .
runHook postBuild
'';
installPhase = ''
runHook preInstall
mkdir -p $out/share/icons
cp -r theme_${themeName} $out/share/icons/${themeName}
runHook postInstall
'';
})