-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modules): add util library (#25)
- Loading branch information
Showing
14 changed files
with
152 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,19 @@ | ||
{ config, pkgs, lib, ... }: | ||
let cfg = config.programs.alacritty.catppuccin; | ||
in { | ||
options.programs.alacritty.catppuccin = with lib; { | ||
enable = mkEnableOption "Catppuccin theme"; | ||
flavour = mkOption { | ||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ]; | ||
default = config.catppuccin.flavour; | ||
description = "Catppuccin flavour for alacritty"; | ||
}; | ||
}; | ||
options.programs.alacritty.catppuccin = | ||
lib.ctp.mkCatppuccinOpt "alacritty" config; | ||
|
||
config.programs.alacritty.settings = with builtins; | ||
with lib; | ||
with pkgs; | ||
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 { | ||
owner = "catppuccin"; | ||
repo = "alacritty"; | ||
rev = "3c808cbb4f9c87be43ba5241bc57373c793d2f17"; | ||
sha256 = "sha256-w9XVtEe7TqzxxGUCDUR9BFkzLZjG8XrplXJ3lX6f+x0="; | ||
} + "/catppuccin-${cfg.flavour}.yml"; | ||
|
||
in mkIf cfg.enable (fromYaml file); | ||
in mkIf cfg.enable (ctp.fromYaml pkgs file); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,10 @@ | ||
{ config, lib, ... }: | ||
let cfg = config.programs.kitty.catppuccin; | ||
in { | ||
options.programs.kitty.catppuccin = with lib; { | ||
enable = mkEnableOption "Catppuccin theme"; | ||
flavour = mkOption { | ||
type = types.enum [ "latte" "frappe" "macchiato" "mocha" ]; | ||
default = config.catppuccin.flavour; | ||
description = "Catppuccin flavour for kitty"; | ||
}; | ||
}; | ||
options.programs.kitty.catppuccin = | ||
lib.ctp.mkCatppuccinOpt "kitty" config; | ||
|
||
config.programs.kitty = with lib; | ||
let | ||
# 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; | ||
let flavourUpper = ctp.mkUpper cfg.flavour; | ||
in mkIf cfg.enable { theme = "Catppuccin-${flavourUpper}"; }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
lib: with builtins; lib.extend (self: _: { ctp = import ./. self; }) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters