feat(modules): add util library (#25)
This commit is contained in:
parent
8b7aa60e3f
commit
be6320c4b1
14 changed files with 152 additions and 138 deletions
|
@ -1,29 +1,13 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.programs.alacritty.catppuccin;
|
let cfg = config.programs.alacritty.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.programs.alacritty.catppuccin = with lib; {
|
options.programs.alacritty.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "alacritty" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for alacritty";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.alacritty.settings = with builtins;
|
config.programs.alacritty.settings = with builtins;
|
||||||
with lib;
|
with lib;
|
||||||
with pkgs;
|
with pkgs;
|
||||||
let
|
let
|
||||||
# path -> a
|
|
||||||
# fromJSON but for yaml
|
|
||||||
fromYaml = file:
|
|
||||||
let
|
|
||||||
# convert to json
|
|
||||||
json = runCommand "converted.json" { } ''
|
|
||||||
${yj}/bin/yj < ${file} > $out
|
|
||||||
'';
|
|
||||||
in fromJSON (readFile json);
|
|
||||||
|
|
||||||
file = fetchFromGitHub {
|
file = fetchFromGitHub {
|
||||||
owner = "catppuccin";
|
owner = "catppuccin";
|
||||||
repo = "alacritty";
|
repo = "alacritty";
|
||||||
|
@ -31,5 +15,5 @@ in {
|
||||||
sha256 = "sha256-w9XVtEe7TqzxxGUCDUR9BFkzLZjG8XrplXJ3lX6f+x0=";
|
sha256 = "sha256-w9XVtEe7TqzxxGUCDUR9BFkzLZjG8XrplXJ3lX6f+x0=";
|
||||||
} + "/catppuccin-${cfg.flavour}.yml";
|
} + "/catppuccin-${cfg.flavour}.yml";
|
||||||
|
|
||||||
in mkIf cfg.enable (fromYaml file);
|
in mkIf cfg.enable (ctp.fromYaml pkgs file);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.programs.bat.catppuccin; in
|
let cfg = config.programs.bat.catppuccin; in
|
||||||
{
|
{
|
||||||
options.programs.bat.catppuccin = {
|
options.programs.bat.catppuccin =
|
||||||
enable = lib.mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "bat" config;
|
||||||
flavour = lib.mkOption {
|
|
||||||
type = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for bat";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config = {
|
config = {
|
||||||
home.activation.batCache = "${pkgs.bat}/bin/bat cache --build";
|
home.activation.batCache = "${pkgs.bat}/bin/bat cache --build";
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.programs.bottom.catppuccin;
|
let cfg = config.programs.bottom.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.programs.bottom.catppuccin = with lib; {
|
options.programs.bottom.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "bottom" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for bottom";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.bottom.settings = with builtins;
|
config.programs.bottom.settings = with builtins;
|
||||||
with lib;
|
with lib;
|
||||||
|
|
|
@ -9,14 +9,8 @@ let
|
||||||
sha256 = "sha256-QoPPx4AzxJMYo/prqmWD/CM7e5vn/ueyx+XQ5+YfHF8=";
|
sha256 = "sha256-QoPPx4AzxJMYo/prqmWD/CM7e5vn/ueyx+XQ5+YfHF8=";
|
||||||
} + themePath;
|
} + themePath;
|
||||||
in {
|
in {
|
||||||
options.programs.btop.catppuccin = with lib; {
|
options.programs.btop.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "btop" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for btop";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
# xdg is required for this to work
|
# xdg is required for this to work
|
||||||
config.xdg.enable = with lib; mkIf cfg.enable (mkForce true);
|
config.xdg.enable = with lib; mkIf cfg.enable (mkForce true);
|
||||||
|
|
|
@ -1,24 +1,29 @@
|
||||||
{ config, pkgs, lib, ... }: {
|
{ config, pkgs, lib, ... }: let
|
||||||
imports = [
|
extendedLib = import ../lib/mkExtLib.nix lib;
|
||||||
./alacritty.nix
|
in {
|
||||||
./bat.nix
|
imports = let
|
||||||
./bottom.nix
|
files = [
|
||||||
./btop.nix
|
./alacritty.nix
|
||||||
./kitty.nix
|
./bat.nix
|
||||||
./starship.nix
|
./bottom.nix
|
||||||
./helix.nix
|
./btop.nix
|
||||||
./gtk.nix
|
./kitty.nix
|
||||||
./polybar.nix
|
./starship.nix
|
||||||
./tmux.nix
|
./helix.nix
|
||||||
];
|
./gtk.nix
|
||||||
options.catppuccin = {
|
./polybar.nix
|
||||||
flavour = lib.mkOption {
|
./tmux.nix
|
||||||
type = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
];
|
||||||
|
in extendedLib.ctp.mapModules config pkgs extendedLib files;
|
||||||
|
|
||||||
|
options.catppuccin = with extendedLib; {
|
||||||
|
flavour = mkOption {
|
||||||
|
type = ctp.types.flavourOption;
|
||||||
default = "latte";
|
default = "latte";
|
||||||
description = "Global Catppuccin flavour";
|
description = "Global Catppuccin flavour";
|
||||||
};
|
};
|
||||||
accent = lib.mkOption {
|
accent = mkOption {
|
||||||
type = lib.types.enum [ "blue" "flamingo" "green" "lavender" "maroon" "mauve" "peach" "pink" "red" "rosewater" "sapphire" "sky" "teal" "yellow" ];
|
type = ctp.types.accentOption;
|
||||||
default = "teal";
|
default = "teal";
|
||||||
description = "Global Catppuccin accent";
|
description = "Global Catppuccin accent";
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,18 +1,9 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.gtk.catppuccin;
|
let cfg = config.gtk.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.gtk.catppuccin = with lib; {
|
options.gtk.catppuccin = with lib;
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
ctp.mkCatppuccinOpt "gtk" config // {
|
||||||
flavour = mkOption {
|
accent = ctp.mkAccentOpt "gtk" config;
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for gtk";
|
|
||||||
};
|
|
||||||
accent = mkOption {
|
|
||||||
type = types.enum [ "blue" "flamingo" "green" "lavender" "maroon" "mauve" "peach" "pink" "red" "rosewater" "sapphire" "sky" "teal" "yellow" ];
|
|
||||||
default = config.catppuccin.accent;
|
|
||||||
description = "Catppuccin accents for gtk";
|
|
||||||
};
|
|
||||||
size = mkOption {
|
size = mkOption {
|
||||||
type = types.enum [ "standard" "compact" ];
|
type = types.enum [ "standard" "compact" ];
|
||||||
default = "standard";
|
default = "standard";
|
||||||
|
@ -25,17 +16,12 @@ in {
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config.gtk.theme = with lib;
|
config.gtk.theme = with builtins;
|
||||||
with builtins;
|
with lib;
|
||||||
let
|
let
|
||||||
# string -> string
|
flavourUpper = ctp.mkUpper cfg.flavour;
|
||||||
# this capitalizes the first letter in a string
|
accentUpper = ctp.mkUpper cfg.accent;
|
||||||
# it's used to set the theme name correctly here
|
sizeUpper = ctp.mkUpper cfg.size;
|
||||||
mkUpper = word: (toUpper (substring 0 1 word)) + (substring 1 (stringLength word) word);
|
|
||||||
|
|
||||||
flavourUpper = mkUpper cfg.flavour;
|
|
||||||
accentUpper = mkUpper cfg.accent;
|
|
||||||
sizeUpper = mkUpper cfg.size;
|
|
||||||
|
|
||||||
# use the light gtk theme for latte
|
# use the light gtk theme for latte
|
||||||
gtkTheme = if cfg.flavour == "latte" then "Light" else "Dark";
|
gtkTheme = if cfg.flavour == "latte" then "Light" else "Dark";
|
||||||
|
|
|
@ -1,15 +1,10 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.programs.helix.catppuccin;
|
let cfg = config.programs.helix.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.programs.helix.catppuccin = with lib; {
|
options.programs.helix.catppuccin = with lib;
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
ctp.mkCatppuccinOpt "helix" config // {
|
||||||
flavour = mkOption {
|
useItalics = mkEnableOption "Italics in Catppuccin theme for Helix";
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for Helix";
|
|
||||||
};
|
};
|
||||||
useItalics = mkEnableOption "Italics in Catppuccin theme for Helix";
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.helix = with builtins;
|
config.programs.helix = with builtins;
|
||||||
with lib;
|
with lib;
|
||||||
|
|
|
@ -1,23 +1,10 @@
|
||||||
{ config, lib, ... }:
|
{ config, lib, ... }:
|
||||||
let cfg = config.programs.kitty.catppuccin;
|
let cfg = config.programs.kitty.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.programs.kitty.catppuccin = with lib; {
|
options.programs.kitty.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "kitty" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for kitty";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.kitty = with lib;
|
config.programs.kitty = with lib;
|
||||||
let
|
let flavourUpper = ctp.mkUpper cfg.flavour;
|
||||||
# string -> string
|
|
||||||
# this capitalizes the first letter in a string
|
|
||||||
# it's used to set the theme name correctly here
|
|
||||||
mkUpper = word:
|
|
||||||
(toUpper (substring 0 1 word)) + (substring 1 (stringLength word) word);
|
|
||||||
|
|
||||||
flavourUpper = mkUpper cfg.flavour;
|
|
||||||
in mkIf cfg.enable { theme = "Catppuccin-${flavourUpper}"; };
|
in mkIf cfg.enable { theme = "Catppuccin-${flavourUpper}"; };
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.services.polybar.catppuccin;
|
let cfg = config.services.polybar.catppuccin;
|
||||||
in {
|
in {
|
||||||
options.services.polybar.catppuccin = with lib; {
|
options.services.polybar.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "polybar" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for polybar";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.services.polybar.extraConfig = with builtins;
|
config.services.polybar.extraConfig = with builtins;
|
||||||
with lib;
|
with lib;
|
||||||
|
|
|
@ -1,14 +1,8 @@
|
||||||
{ config, pkgs, lib, ... }:
|
{ config, pkgs, lib, ... }:
|
||||||
let cfg = config.programs.starship.catppuccin; in
|
let cfg = config.programs.starship.catppuccin; in
|
||||||
{
|
{
|
||||||
options.programs.starship.catppuccin = {
|
options.programs.starship.catppuccin =
|
||||||
enable = lib.mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "starship" config;
|
||||||
flavour = lib.mkOption {
|
|
||||||
type = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for starship";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.starship.settings = lib.mkIf cfg.enable
|
config.programs.starship.settings = lib.mkIf cfg.enable
|
||||||
({
|
({
|
||||||
|
|
|
@ -16,14 +16,8 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
in {
|
in {
|
||||||
options.programs.tmux.catppuccin = with lib; {
|
options.programs.tmux.catppuccin =
|
||||||
enable = mkEnableOption "Catppuccin theme";
|
lib.ctp.mkCatppuccinOpt "tmux" config;
|
||||||
flavour = mkOption {
|
|
||||||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
|
||||||
default = config.catppuccin.flavour;
|
|
||||||
description = "Catppuccin flavour for tmux";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
|
|
||||||
config.programs.tmux.plugins = with lib; mkIf cfg.enable [
|
config.programs.tmux.plugins = with lib; mkIf cfg.enable [
|
||||||
{
|
{
|
||||||
|
|
86
modules/lib/default.nix
Normal file
86
modules/lib/default.nix
Normal file
|
@ -0,0 +1,86 @@
|
||||||
|
lib:
|
||||||
|
with builtins;
|
||||||
|
with lib; rec {
|
||||||
|
# string -> string
|
||||||
|
# this capitalizes the first letter in a string,
|
||||||
|
# which is sometimes needed in order to format
|
||||||
|
# the names of themes correctly
|
||||||
|
mkUpper = str:
|
||||||
|
(toUpper (substring 0 1 str)) + (substring 1 (stringLength str) str);
|
||||||
|
|
||||||
|
# a -> path -> a
|
||||||
|
# fromJSON but for yaml (and without readFile)
|
||||||
|
# a should be the local pkgs attrset
|
||||||
|
fromYaml = pkgs: file:
|
||||||
|
let
|
||||||
|
# convert to json
|
||||||
|
json = with pkgs; runCommand "converted.json" { } ''
|
||||||
|
${yj}/bin/yj < ${file} > $out
|
||||||
|
'';
|
||||||
|
in fromJSON (readFile json);
|
||||||
|
|
||||||
|
# a -> a -> [path] -> [path]
|
||||||
|
# this imports a list of paths while inheriting
|
||||||
|
# multiple attributes
|
||||||
|
mapModules = config: pkgs: extendedLib:
|
||||||
|
map (m:
|
||||||
|
(import m {
|
||||||
|
inherit config pkgs;
|
||||||
|
lib = extendedLib;
|
||||||
|
}));
|
||||||
|
|
||||||
|
types = {
|
||||||
|
flavourOption = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
||||||
|
accentOption = lib.types.enum [
|
||||||
|
"blue"
|
||||||
|
"flamingo"
|
||||||
|
"green"
|
||||||
|
"lavender"
|
||||||
|
"maroon"
|
||||||
|
"mauve"
|
||||||
|
"peach"
|
||||||
|
"pink"
|
||||||
|
"red"
|
||||||
|
"rosewater"
|
||||||
|
"sapphire"
|
||||||
|
"sky"
|
||||||
|
"teal"
|
||||||
|
"yellow"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
# string -> type -> string -> a -> a
|
||||||
|
# this is an internal function and shouldn't be
|
||||||
|
# used unless you know what you're doing. it takes
|
||||||
|
# a string (the name of the property, i.e., flavour
|
||||||
|
# or accent), the type of the property, the name of
|
||||||
|
# the module, followed by local config attrset
|
||||||
|
mkBasicOpt = attr: type: name: config:
|
||||||
|
mkOption {
|
||||||
|
inherit type;
|
||||||
|
default = config.catppuccin.${attr};
|
||||||
|
description = "Catppuccin ${attr} for ${name}";
|
||||||
|
};
|
||||||
|
|
||||||
|
# string -> a -> a
|
||||||
|
# this creates a flavour option for modules
|
||||||
|
# the first string should be the name of the module,
|
||||||
|
# followed by the local config attrset
|
||||||
|
mkFlavourOpt = mkBasicOpt "flavour" types.flavourOption;
|
||||||
|
|
||||||
|
# string -> a -> a
|
||||||
|
# this creates an accent option for modules
|
||||||
|
# the first string should be the name of the module,
|
||||||
|
# followed by the local config attrset
|
||||||
|
mkAccentOpt = mkBasicOpt "accent" types.accentOption;
|
||||||
|
|
||||||
|
# string -> a -> a
|
||||||
|
# this creates a basic attrset only containing an
|
||||||
|
# enable and flavour option. the fist string should
|
||||||
|
# be the name of the module, followed by the local config
|
||||||
|
# attrset
|
||||||
|
mkCatppuccinOpt = name: config: {
|
||||||
|
enable = mkEnableOption "Catppuccin theme";
|
||||||
|
flavour = mkFlavourOpt name config;
|
||||||
|
};
|
||||||
|
}
|
1
modules/lib/mkExtLib.nix
Normal file
1
modules/lib/mkExtLib.nix
Normal file
|
@ -0,0 +1 @@
|
||||||
|
lib: with builtins; lib.extend (self: _: { ctp = import ./. self; })
|
|
@ -1,11 +1,17 @@
|
||||||
{ lib, ... }: {
|
{ config, pkgs, lib, ... }: let
|
||||||
imports = [
|
extendedLib = import ../lib/mkExtLib.nix lib;
|
||||||
./grub.nix
|
in {
|
||||||
];
|
imports = let
|
||||||
|
files = [
|
||||||
|
./grub.nix
|
||||||
|
];
|
||||||
|
in
|
||||||
|
extendedLib.ctp.mapModules config pkgs extendedLib files;
|
||||||
|
|
||||||
options.catppuccin = {
|
|
||||||
flavour = lib.mkOption {
|
options.catppuccin = with extendedLib; {
|
||||||
type = lib.types.enum [ "latte" "frappe" "macchiato" "mocha" ];
|
flavour = mkOption {
|
||||||
|
type = ctp.types.flavourOption;
|
||||||
default = "latte";
|
default = "latte";
|
||||||
description = "Global Catppuccin flavour";
|
description = "Global Catppuccin flavour";
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue