Skip to content

Commit

Permalink
feat(lib)!: use constant module arguments automatically
Browse files Browse the repository at this point in the history
  • Loading branch information
getchoo committed Nov 2, 2023
1 parent cecf37c commit 2b4277a
Show file tree
Hide file tree
Showing 22 changed files with 48 additions and 50 deletions.
5 changes: 2 additions & 3 deletions modules/home-manager/alacritty.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{ config
, pkgs
, lib
, sources
, ...
Expand All @@ -11,11 +10,11 @@ let
in
{
options.programs.alacritty.catppuccin =
ctp.mkCatppuccinOpt "alacritty" config;
ctp.mkCatppuccinOpt "alacritty";

config.programs.alacritty.settings =
let
file = "${sources.alacritty}/catppuccin-${cfg.flavour}.yml";
in
lib.mkIf enable (ctp.fromYaml pkgs file);
lib.mkIf enable (ctp.fromYaml file);
}
2 changes: 1 addition & 1 deletion modules/home-manager/bat.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
in
{
options.programs.bat.catppuccin =
lib.ctp.mkCatppuccinOpt "bat" config;
lib.ctp.mkCatppuccinOpt "bat";

config = lib.mkIf enable {
programs.bat = {
Expand Down
13 changes: 10 additions & 3 deletions modules/home-manager/bottom.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,20 @@
, ...
}:
let
inherit (builtins) fromTOML readFile;
cfg = config.programs.bottom.catppuccin;
enable = cfg.enable && config.programs.bottom.enable;
in
{
options.programs.bottom.catppuccin =
lib.ctp.mkCatppuccinOpt "bottom" config;
lib.ctp.mkCatppuccinOpt "bottom";

config.programs.bottom.settings = lib.mkIf enable (fromTOML (readFile "${sources.bottom}/themes/${cfg.flavour}.toml"));
config = lib.mkIf enable {

programs.bottom = {

settings = builtins.fromTOML (
builtins.readFile "${sources.bottom}/themes/${cfg.flavour}.toml"
);
};
};
}
2 changes: 1 addition & 1 deletion modules/home-manager/btop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ let
in
{
options.programs.btop.catppuccin =
lib.ctp.mkCatppuccinOpt "btop" config;
lib.ctp.mkCatppuccinOpt "btop";

config = lib.mkIf enable
{
Expand Down
10 changes: 3 additions & 7 deletions modules/home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
{ inputs, sources }: { config
, pkgs
, lib
, ...
}:
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs :
let
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib;
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib ( flakeArgs // systemArgs);
inherit (extendedLib) ctp;
in
{
Expand All @@ -30,7 +26,7 @@ in
./tmux.nix
];
in
extendedLib.ctp.mapModules config pkgs extendedLib (sources pkgs) files;
extendedLib.ctp.mapModules extendedLib files;

options.catppuccin = {
flavour = lib.mkOption {
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/fish.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let
themePath = "/themes/${themeName}.theme";
in
{
options.programs.fish.catppuccin = lib.ctp.mkCatppuccinOpt "fish" config;
options.programs.fish.catppuccin = lib.ctp.mkCatppuccinOpt "fish";

# xdg is required for this to work
config = mkIf enable {
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/glamour.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let
in
{
options.programs.glamour.catppuccin =
lib.ctp.mkCatppuccinOpt "glamour" config;
lib.ctp.mkCatppuccinOpt "glamour";

config = {
home.sessionVariables = lib.mkIf enable {
Expand Down
4 changes: 2 additions & 2 deletions modules/home-manager/gtk.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ let
in
{
options.gtk.catppuccin =
ctp.mkCatppuccinOpt "gtk" config
ctp.mkCatppuccinOpt "gtk"
// {
accent = ctp.mkAccentOpt "gtk" config;
accent = ctp.mkAccentOpt "gtk";
size = mkOption {
type = types.enum [ "standard" "compact" ];
default = "standard";
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/helix.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
in
{
options.programs.helix.catppuccin = with lib;
ctp.mkCatppuccinOpt "helix" config
ctp.mkCatppuccinOpt "helix"
// {
useItalics = mkEnableOption "Italics in Catppuccin theme for Helix";
};
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/kitty.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
in
{
options.programs.kitty.catppuccin =
ctp.mkCatppuccinOpt "kitty" config;
ctp.mkCatppuccinOpt "kitty";

config.programs.kitty =
lib.mkIf enable { theme = "Catppuccin-${ctp.mkUpper cfg.flavour}"; };
Expand Down
11 changes: 3 additions & 8 deletions modules/home-manager/lazygit.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{ config
, lib
, pkgs
, sources
, ...
}:
Expand All @@ -13,17 +12,13 @@ let
in
{
options.programs.lazygit.catppuccin =
lib.ctp.mkCatppuccinOpt "lazygit" config // {
accent = ctp.mkAccentOpt "lazygit" config;
lib.ctp.mkCatppuccinOpt "lazygit" // {
accent = ctp.mkAccentOpt "lazygit";

};

config = lib.mkIf enable {

programs.lazygit.settings =
let
file = "${sources.lazygit}/themes/${themePath}";
in
lib.ctp.fromYaml pkgs file;
programs.lazygit.settings = lib.ctp.fromYaml "${sources.lazygit}/themes/${themePath}";
};
}
4 changes: 2 additions & 2 deletions modules/home-manager/mako.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ let

cfg = config.services.mako.catppuccin;
enable = cfg.enable && config.services.mako.enable;
theme = lib.ctp.fromINI pkgs (sources.mako + /src/${cfg.flavour});
theme = lib.ctp.fromINI (sources.mako + /src/${cfg.flavour});

# Settings that need to be extracted and put in extraConfig
extraConfigAttrs = lib.attrsets.getAttrs [ "urgency=high" ] theme;
in
{
options.services.mako.catppuccin =
lib.ctp.mkCatppuccinOpt "mako" config;
lib.ctp.mkCatppuccinOpt "mako";

# Will cause infinite recursion if config.services.mako is directly set as a whole
config.services.mako = lib.mkIf enable {
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/micro.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ let
in
{
options.programs.micro.catppuccin =
lib.ctp.mkCatppuccinOpt "micro" config;
lib.ctp.mkCatppuccinOpt "micro";

config = lib.mkIf enable {
programs.micro.settings.colorscheme = lib.removeSuffix ".micro" themePath;
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ let
enable = cfg.enable && config.programs.neovim.enable;
in
{
options.programs.neovim.catppuccin = lib.ctp.mkCatppuccinOpt "neovim" config;
options.programs.neovim.catppuccin = lib.ctp.mkCatppuccinOpt "neovim";

config.programs.neovim = lib.mkIf enable {
plugins = with pkgs.vimPlugins; [
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/polybar.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let
in
{
options.services.polybar.catppuccin =
lib.ctp.mkCatppuccinOpt "polybar" config;
lib.ctp.mkCatppuccinOpt "polybar";

config.services.polybar.extraConfig = lib.mkIf enable
(builtins.readFile "${sources.polybar}/themes/${cfg.flavour}.ini");
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/starship.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
in
{
options.programs.starship.catppuccin =
lib.ctp.mkCatppuccinOpt "starship" config;
lib.ctp.mkCatppuccinOpt "starship";

config.programs.starship.settings =
lib.mkIf enable
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/sway.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ let
in
{
options.wayland.windowManager.sway.catppuccin =
lib.ctp.mkCatppuccinOpt "sway" config;
lib.ctp.mkCatppuccinOpt "sway";

config.wayland.windowManager.sway.extraConfigEarly =
lib.mkIf enable ''
Expand Down
2 changes: 1 addition & 1 deletion modules/home-manager/tmux.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ let
in
{
options.programs.tmux.catppuccin =
lib.ctp.mkCatppuccinOpt "tmux" config;
lib.ctp.mkCatppuccinOpt "tmux";

config.programs.tmux.plugins = lib.mkIf enable [
{
Expand Down
17 changes: 9 additions & 8 deletions modules/lib/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
lib:
lib: {config, pkgs, sources, ...}:
let
# 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:
mkBasicOpt = attr: type: name:
lib.mkOption {
inherit type;
default = config.catppuccin.${attr};
Expand Down Expand Up @@ -53,7 +53,7 @@ in
# a -> path -> a
# fromJSON but for yaml (and without readFile)
# a should be the local pkgs attrset
fromYaml = pkgs: file:
fromYaml = file:
let
inherit (builtins) fromJSON readFile;

Expand All @@ -68,7 +68,7 @@ in
# a -> path -> a
# fromJSON but for ini (and without readFile)
# a should be the local pkgs attrset
fromINI = pkgs: file:
fromINI = file:
let
inherit (builtins) fromJSON readFile;

Expand All @@ -83,9 +83,10 @@ in
# a -> a -> [path] -> [path]
# this imports a list of paths while inheriting
# multiple attributes
mapModules = config: pkgs: extendedLib: sources:
mapModules = extendedLib:
map (m: (import m {
inherit config pkgs sources;
inherit config pkgs;
sources = sources pkgs;
lib = extendedLib;
}));

Expand All @@ -94,9 +95,9 @@ in
# enable and flavour option. the fist string should
# be the name of the module, followed by the local config
# attrset
mkCatppuccinOpt = name: config: {
mkCatppuccinOpt = name: {
enable = lib.mkEnableOption "Catppuccin theme";
flavour = mkFlavourOpt name config;
flavour = mkFlavourOpt name;
};

# string -> a -> a
Expand Down
2 changes: 1 addition & 1 deletion modules/lib/mkExtLib.nix
Original file line number Diff line number Diff line change
@@ -1 +1 @@
lib: lib.extend (self: _: { ctp = import ./. self; })
lib: args: lib.extend (self: _: { ctp = import ./. self args; })
6 changes: 3 additions & 3 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{ inputs, sources }: { config, pkgs, lib, ... }:
{ inputs, ... }@flakeArgs: { lib, pkgs, ... }@systemArgs:
let
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib;
extendedLib = import ../lib/mkExtLib.nix inputs.nixpkgs.lib (systemArgs // flakeArgs);
in
{
imports =
Expand All @@ -9,7 +9,7 @@ in
./grub.nix
];
in
extendedLib.ctp.mapModules config pkgs extendedLib (sources pkgs) files;
extendedLib.ctp.mapModules extendedLib files;


options.catppuccin = with extendedLib; {
Expand Down
2 changes: 1 addition & 1 deletion modules/nixos/grub.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ let
in
{
options.boot.loader.grub.catppuccin =
lib.ctp.mkCatppuccinOpt "grub" config;
lib.ctp.mkCatppuccinOpt "grub";

config.boot.loader.grub = lib.mkIf enable {
font = "${theme}/font.pf2";
Expand Down

0 comments on commit 2b4277a

Please sign in to comment.