From 68f9c7db73a975989cab7531f65a4f83e89e8f99 Mon Sep 17 00:00:00 2001 From: Marty Sluijtman Date: Fri, 12 Jan 2024 14:11:32 +0100 Subject: [PATCH] Initial commit --- README.md | 4 ++++ flake.nix | 5 +++++ lib.nix | 3 +++ lib/getKittyColorscheme.nix | 22 ++++++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 README.md create mode 100644 flake.nix create mode 100644 lib.nix create mode 100644 lib/getKittyColorscheme.nix diff --git a/README.md b/README.md new file mode 100644 index 0000000..623b803 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +# Funkytions + +A collection of nix functions that were obnoxious enough to want to have in a +sperate repository. diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f6f197e --- /dev/null +++ b/flake.nix @@ -0,0 +1,5 @@ +{ description = "A collection of tedious nix functions"; + outputs = _: { + lib = import ./lib.nix; + }; +} diff --git a/lib.nix b/lib.nix new file mode 100644 index 0000000..93e410e --- /dev/null +++ b/lib.nix @@ -0,0 +1,3 @@ +{ + getKittyColorscheme = import ./lib/getKittyColorscheme.nix; +} diff --git a/lib/getKittyColorscheme.nix b/lib/getKittyColorscheme.nix new file mode 100644 index 0000000..d3083d9 --- /dev/null +++ b/lib/getKittyColorscheme.nix @@ -0,0 +1,22 @@ +{ lib, config, pkgs, ... }: +arg: +with lib; +let cfg = config.colorscheme; + + getKittyTheme = with builtins; (theme: + let matching = filter (x: x.name == theme) + (fromJSON + (readFile + "${pkgs.kitty-themes}/share/kitty-themes/themes.json")); + + in throwIf (length matching == 0) + "kitty-themes does not contain a theme named ${theme}" + "${pkgs.kitty-themes}/share/kitty-themes/${(head matching).file}"); + + unwrapKittyTheme = with pkgs; path: let + theme = runCommand "theme.toml" { nativebuildinputs = [ coreutils ]; } '' + cat '${path}' | sed -E '/^#|^$/d;s/\s+(.*)/ = "\1"/g' > $out + ''; + in (builtins.fromTOML (builtins.readFile theme)); + +in unwrapKittyTheme (getKittyTheme arg)