Skip to content

Commit

Permalink
refactor(modules): inject custom lib with lib.modules.importApply
Browse files Browse the repository at this point in the history
A bit cleaner than our current solution, and creates a clear separation
between our functions and those from Nixpkgs
  • Loading branch information
getchoo committed Nov 27, 2024
1 parent d31b71e commit d870483
Show file tree
Hide file tree
Showing 60 changed files with 194 additions and 159 deletions.
20 changes: 16 additions & 4 deletions modules/global.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,33 @@
{ lib, ... }:
{ catppuccinModules }:
{
config,
lib,
pkgs,
...
}:

let
catppuccinLib = (import ./lib/mk-ext-lib.nix { inherit config lib pkgs; }).ctp;
in

{
config = {
assertions = [ (lib.ctp.assertMinimumVersion "24.05") ];
assertions = [ (catppuccinLib.assertMinimumVersion "24.05") ];
};

imports = catppuccinLib.applyToModules catppuccinModules;

options.catppuccin = {
enable = lib.mkEnableOption "Catppuccin globally";

flavor = lib.mkOption {
type = lib.ctp.types.flavor;
type = catppuccinLib.types.flavor;
default = "mocha";
description = "Global Catppuccin flavor";
};

accent = lib.mkOption {
type = lib.ctp.types.accent;
type = catppuccinLib.types.accent;
default = "mauve";
description = "Global Catppuccin accent";
};
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/aerc.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,7 +7,7 @@ let
themeName = "catppuccin-${cfg.flavor}";
in
{
options.programs.aerc.catppuccin = lib.ctp.mkCatppuccinOption { name = "aerc"; };
options.programs.aerc.catppuccin = catppuccinLib.mkCatppuccinOption { name = "aerc"; };

config = lib.mkIf enable {
programs.aerc = {
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/alacritty.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.alacritty.catppuccin;
enable = cfg.enable && config.programs.alacritty.enable;
in
{
options.programs.alacritty.catppuccin = lib.ctp.mkCatppuccinOption { name = "alacritty"; };
options.programs.alacritty.catppuccin = catppuccinLib.mkCatppuccinOption { name = "alacritty"; };

config = lib.mkIf enable {
programs.alacritty.settings = lib.importTOML "${sources.alacritty}/catppuccin-${cfg.flavor}.toml";
Expand Down
1 change: 0 additions & 1 deletion modules/home-manager/all-modules.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
[
../global.nix
./aerc.nix
./alacritty.nix
./bat.nix
Expand Down
5 changes: 3 additions & 2 deletions modules/home-manager/bat.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.bat.catppuccin;
enable = cfg.enable && config.programs.bat.enable;
themeName = "Catppuccin ${lib.ctp.mkUpper cfg.flavor}";
themeName = "Catppuccin ${catppuccinLib.mkUpper cfg.flavor}";
in
{
options.programs.bat.catppuccin = lib.ctp.mkCatppuccinOption { name = "bat"; };
options.programs.bat.catppuccin = catppuccinLib.mkCatppuccinOption { name = "bat"; };

config = lib.mkIf enable {
programs.bat = {
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/bottom.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.bottom.catppuccin;
enable = cfg.enable && config.programs.bottom.enable;
in
{
options.programs.bottom.catppuccin = lib.ctp.mkCatppuccinOption { name = "bottom"; };
options.programs.bottom.catppuccin = catppuccinLib.mkCatppuccinOption { name = "bottom"; };

config = lib.mkIf enable {
programs.bottom = {
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/btop.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -9,7 +10,7 @@ let
theme = sources.btop + themePath;
in
{
options.programs.btop.catppuccin = lib.ctp.mkCatppuccinOption { name = "btop"; };
options.programs.btop.catppuccin = catppuccinLib.mkCatppuccinOption { name = "btop"; };

config = lib.mkIf enable {
xdg.configFile."btop${themePath}".source = theme;
Expand Down
5 changes: 3 additions & 2 deletions modules/home-manager/cava.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,11 +7,11 @@ let
flavor = "${cfg.flavor}" + lib.optionalString cfg.transparent "-transparent";
in
{
options.programs.cava.catppuccin = lib.ctp.mkCatppuccinOption { name = "cava"; } // {
options.programs.cava.catppuccin = catppuccinLib.mkCatppuccinOption { name = "cava"; } // {
transparent = lib.mkEnableOption "transparent version of flavor";
};

config.programs.cava = lib.mkIf enable {
settings = lib.ctp.fromINIRaw (sources.cava + "/themes/${flavor}.cava");
settings = catppuccinLib.fromINIRaw (sources.cava + "/themes/${flavor}.cava");
};
}
10 changes: 5 additions & 5 deletions modules/home-manager/cursor.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{ catppuccinLib }:
{
config,
pkgs,
lib,
...
}:
let
inherit (lib) ctp mkIf;
cfg = config.catppuccin.pointerCursor;

# "dark" and "light" can be used alongside the regular accents
cursorAccentType = ctp.mergeEnums ctp.types.accent (
cursorAccentType = catppuccinLib.mergeEnums catppuccinLib.types.accent (
lib.types.enum [
"dark"
"light"
Expand All @@ -18,7 +18,7 @@ let
in
{
options.catppuccin.pointerCursor =
ctp.mkCatppuccinOption {
catppuccinLib.mkCatppuccinOption {
name = "pointer cursors";
# NOTE: we exclude this from the global `catppuccin.enable` as there is no
# `enable` option in the upstream module to guard it
Expand All @@ -33,8 +33,8 @@ in
};
};

config.home.pointerCursor = mkIf cfg.enable {
config.home.pointerCursor = lib.mkIf cfg.enable {
name = "catppuccin-${cfg.flavor}-${cfg.accent}-cursors";
package = pkgs.catppuccin-cursors.${cfg.flavor + ctp.mkUpper cfg.accent};
package = pkgs.catppuccin-cursors.${cfg.flavor + catppuccinLib.mkUpper cfg.accent};
};
}
15 changes: 5 additions & 10 deletions modules/home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
{ lib, ... }:

{
config,
lib,
pkgs,
...
}:
{
imports = import ../lib/import-modules.nix {
inherit config lib pkgs;
modules = import ./all-modules.nix;
};
imports = [
(lib.modules.importApply ../global.nix { catppuccinModules = import ./all-modules.nix; })
];
}
3 changes: 2 additions & 1 deletion modules/home-manager/delta.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.git.delta.catppuccin;
enable = cfg.enable && config.programs.git.delta.enable;
in
{
options.programs.git.delta.catppuccin = lib.ctp.mkCatppuccinOption { name = "delta"; };
options.programs.git.delta.catppuccin = catppuccinLib.mkCatppuccinOption { name = "delta"; };

config = lib.mkIf enable {
programs.git = {
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/dunst.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.services.dunst.catppuccin;
enable = cfg.enable && config.services.dunst.enable;
in
{
options.services.dunst.catppuccin = lib.ctp.mkCatppuccinOption { name = "dunst"; } // {
options.services.dunst.catppuccin = catppuccinLib.mkCatppuccinOption { name = "dunst"; } // {
prefix = lib.mkOption {
type = lib.types.str;
default = "00";
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/fcitx5.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,7 +7,7 @@ let
in
{
options.i18n.inputMethod.fcitx5.catppuccin =
lib.ctp.mkCatppuccinOption {
catppuccinLib.mkCatppuccinOption {
name = "Fcitx5";
accentSupport = true;
}
Expand Down
5 changes: 3 additions & 2 deletions modules/home-manager/fish.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.fish.catppuccin;
enable = cfg.enable && config.programs.fish.enable;

themeName = "Catppuccin ${lib.ctp.mkUpper cfg.flavor}";
themeName = "Catppuccin ${catppuccinLib.mkUpper cfg.flavor}";
themePath = "/themes/${themeName}.theme";
in
{
options.programs.fish.catppuccin = lib.ctp.mkCatppuccinOption { name = "fish"; };
options.programs.fish.catppuccin = catppuccinLib.mkCatppuccinOption { name = "fish"; };

config = lib.mkIf enable {
xdg.configFile."fish${themePath}".source = "${sources.fish}${themePath}";
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/foot.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,7 +7,7 @@ let
enable = cfg.enable && config.programs.foot.enable;
in
{
options.programs.foot.catppuccin = lib.ctp.mkCatppuccinOption { name = "foot"; };
options.programs.foot.catppuccin = catppuccinLib.mkCatppuccinOption { name = "foot"; };

config.programs.foot = lib.mkIf enable {
settings.main.include = sources.foot + "/themes/catppuccin-${cfg.flavor}.ini";
Expand Down
5 changes: 3 additions & 2 deletions modules/home-manager/freetube.nix
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.programs.freetube.settings) baseTheme;
inherit (lib.ctp) mkUpper types;
inherit (catppuccinLib) mkUpper types;
cfg = config.programs.freetube.catppuccin;
enable = cfg.enable && config.programs.freetube.enable;
in
{
options.programs.freetube.catppuccin =
lib.ctp.mkCatppuccinOption {
catppuccinLib.mkCatppuccinOption {
name = "freetube";
accentSupport = true;
}
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/fuzzel.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.fuzzel.catppuccin;
in
{
options.programs.fuzzel.catppuccin = lib.ctp.mkCatppuccinOption {
options.programs.fuzzel.catppuccin = catppuccinLib.mkCatppuccinOption {
name = "fuzzel";
accentSupport = true;
};
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/fzf.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -7,7 +8,7 @@ let
palette = (lib.importJSON "${sources.palette}/palette.json").${cfg.flavor}.colors;
in
{
options.programs.fzf.catppuccin = lib.ctp.mkCatppuccinOption {
options.programs.fzf.catppuccin = catppuccinLib.mkCatppuccinOption {
name = "fzf";
accentSupport = true;
};
Expand Down
5 changes: 3 additions & 2 deletions modules/home-manager/gh-dash.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,10 +7,10 @@ let
theme = "${sources.gh-dash}/themes/${cfg.flavor}/catppuccin-${cfg.flavor}-${cfg.accent}.yml";
in
{
options.programs.gh-dash.catppuccin = lib.ctp.mkCatppuccinOption {
options.programs.gh-dash.catppuccin = catppuccinLib.mkCatppuccinOption {
name = "gh-dash";
accentSupport = true;
};

config.programs.gh-dash.settings = lib.mkIf enable (lib.ctp.fromYaml theme);
config.programs.gh-dash.settings = lib.mkIf enable (catppuccinLib.fromYaml theme);
}
3 changes: 2 additions & 1 deletion modules/home-manager/gitui.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
Expand All @@ -6,7 +7,7 @@ let
enable = cfg.enable && config.programs.gitui.enable;
in
{
options.programs.gitui.catppuccin = lib.ctp.mkCatppuccinOption { name = "gitui"; };
options.programs.gitui.catppuccin = catppuccinLib.mkCatppuccinOption { name = "gitui"; };

config = lib.mkIf enable {
programs.gitui.theme = builtins.path {
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/glamour.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.glamour.catppuccin;
inherit (cfg) enable;
in
{
options.programs.glamour.catppuccin = lib.ctp.mkCatppuccinOption { name = "glamour"; };
options.programs.glamour.catppuccin = catppuccinLib.mkCatppuccinOption { name = "glamour"; };

config = {
home.sessionVariables = lib.mkIf enable {
Expand Down
6 changes: 3 additions & 3 deletions modules/home-manager/gtk.nix
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{ catppuccinLib }:
{
config,
pkgs,
Expand All @@ -7,7 +8,6 @@
let
inherit (lib)
concatStringsSep
ctp
mkIf
mkEnableOption
mkMerge
Expand All @@ -20,7 +20,7 @@ let
in
{
options.gtk.catppuccin =
ctp.mkCatppuccinOption {
catppuccinLib.mkCatppuccinOption {
name = "gtk";
default = false;
defaultText = lib.literalExpression "false";
Expand Down Expand Up @@ -52,7 +52,7 @@ in

gnomeShellTheme = mkEnableOption "Catppuccin gtk theme for GNOME Shell";

icon = ctp.mkCatppuccinOption {
icon = catppuccinLib.mkCatppuccinOption {
name = "GTK modified Papirus icon theme";
# NOTE: we exclude this from the global `catppuccin.enable` as there is no
# `enable` option in the upstream module to guard it
Expand Down
3 changes: 2 additions & 1 deletion modules/home-manager/helix.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{ catppuccinLib }:
{ config, lib, ... }:
let
inherit (config.catppuccin) sources;
cfg = config.programs.helix.catppuccin;
enable = cfg.enable && config.programs.helix.enable;
in
{
options.programs.helix.catppuccin = lib.ctp.mkCatppuccinOption { name = "helix"; } // {
options.programs.helix.catppuccin = catppuccinLib.mkCatppuccinOption { name = "helix"; } // {
useItalics = lib.mkEnableOption "Italics in Catppuccin theme for Helix";
};

Expand Down
Loading

0 comments on commit d870483

Please sign in to comment.