From 2b4277a171c4a335dab2ee68d7b9c29a475721b9 Mon Sep 17 00:00:00 2001 From: seth Date: Thu, 2 Nov 2023 13:36:17 -0400 Subject: [PATCH] feat(lib)!: use constant module arguments automatically --- modules/home-manager/alacritty.nix | 5 ++--- modules/home-manager/bat.nix | 2 +- modules/home-manager/bottom.nix | 13 ++++++++++--- modules/home-manager/btop.nix | 2 +- modules/home-manager/default.nix | 10 +++------- modules/home-manager/fish.nix | 2 +- modules/home-manager/glamour.nix | 2 +- modules/home-manager/gtk.nix | 4 ++-- modules/home-manager/helix.nix | 2 +- modules/home-manager/kitty.nix | 2 +- modules/home-manager/lazygit.nix | 11 +++-------- modules/home-manager/mako.nix | 4 ++-- modules/home-manager/micro.nix | 2 +- modules/home-manager/neovim.nix | 2 +- modules/home-manager/polybar.nix | 2 +- modules/home-manager/starship.nix | 2 +- modules/home-manager/sway.nix | 2 +- modules/home-manager/tmux.nix | 2 +- modules/lib/default.nix | 17 +++++++++-------- modules/lib/mkExtLib.nix | 2 +- modules/nixos/default.nix | 6 +++--- modules/nixos/grub.nix | 2 +- 22 files changed, 48 insertions(+), 50 deletions(-) diff --git a/modules/home-manager/alacritty.nix b/modules/home-manager/alacritty.nix index 2c0101c4..ba159daf 100644 --- a/modules/home-manager/alacritty.nix +++ b/modules/home-manager/alacritty.nix @@ -1,5 +1,4 @@ { config -, pkgs , lib , sources , ... @@ -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); } diff --git a/modules/home-manager/bat.nix b/modules/home-manager/bat.nix index 36e8e5aa..ac88fdd9 100644 --- a/modules/home-manager/bat.nix +++ b/modules/home-manager/bat.nix @@ -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 = { diff --git a/modules/home-manager/bottom.nix b/modules/home-manager/bottom.nix index c58a7957..2eeaac99 100644 --- a/modules/home-manager/bottom.nix +++ b/modules/home-manager/bottom.nix @@ -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" + ); + }; + }; } diff --git a/modules/home-manager/btop.nix b/modules/home-manager/btop.nix index f5a58e94..a6605f52 100644 --- a/modules/home-manager/btop.nix +++ b/modules/home-manager/btop.nix @@ -13,7 +13,7 @@ let in { options.programs.btop.catppuccin = - lib.ctp.mkCatppuccinOpt "btop" config; + lib.ctp.mkCatppuccinOpt "btop"; config = lib.mkIf enable { diff --git a/modules/home-manager/default.nix b/modules/home-manager/default.nix index b8521596..34c5ce2a 100644 --- a/modules/home-manager/default.nix +++ b/modules/home-manager/default.nix @@ -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 { @@ -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 { diff --git a/modules/home-manager/fish.nix b/modules/home-manager/fish.nix index d92e3bb0..95400f85 100644 --- a/modules/home-manager/fish.nix +++ b/modules/home-manager/fish.nix @@ -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 { diff --git a/modules/home-manager/glamour.nix b/modules/home-manager/glamour.nix index 8729d59d..b2b286fc 100644 --- a/modules/home-manager/glamour.nix +++ b/modules/home-manager/glamour.nix @@ -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 { diff --git a/modules/home-manager/gtk.nix b/modules/home-manager/gtk.nix index 44879685..9c70c60e 100644 --- a/modules/home-manager/gtk.nix +++ b/modules/home-manager/gtk.nix @@ -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"; diff --git a/modules/home-manager/helix.nix b/modules/home-manager/helix.nix index 3811cdf6..e01caf0b 100644 --- a/modules/home-manager/helix.nix +++ b/modules/home-manager/helix.nix @@ -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"; }; diff --git a/modules/home-manager/kitty.nix b/modules/home-manager/kitty.nix index 847d8068..7e2f1380 100644 --- a/modules/home-manager/kitty.nix +++ b/modules/home-manager/kitty.nix @@ -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}"; }; diff --git a/modules/home-manager/lazygit.nix b/modules/home-manager/lazygit.nix index 400c8c72..7ec5bba9 100644 --- a/modules/home-manager/lazygit.nix +++ b/modules/home-manager/lazygit.nix @@ -1,6 +1,5 @@ { config , lib -, pkgs , sources , ... }: @@ -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}"; }; } diff --git a/modules/home-manager/mako.nix b/modules/home-manager/mako.nix index 2f1f6096..e31c3ff4 100644 --- a/modules/home-manager/mako.nix +++ b/modules/home-manager/mako.nix @@ -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 { diff --git a/modules/home-manager/micro.nix b/modules/home-manager/micro.nix index e320774e..29085c38 100644 --- a/modules/home-manager/micro.nix +++ b/modules/home-manager/micro.nix @@ -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; diff --git a/modules/home-manager/neovim.nix b/modules/home-manager/neovim.nix index 6e7231bc..c77bd3ff 100644 --- a/modules/home-manager/neovim.nix +++ b/modules/home-manager/neovim.nix @@ -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; [ diff --git a/modules/home-manager/polybar.nix b/modules/home-manager/polybar.nix index c740a03b..38d00ee4 100644 --- a/modules/home-manager/polybar.nix +++ b/modules/home-manager/polybar.nix @@ -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"); diff --git a/modules/home-manager/starship.nix b/modules/home-manager/starship.nix index 9cae070e..cbf2b526 100644 --- a/modules/home-manager/starship.nix +++ b/modules/home-manager/starship.nix @@ -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 diff --git a/modules/home-manager/sway.nix b/modules/home-manager/sway.nix index f665776e..628f476e 100644 --- a/modules/home-manager/sway.nix +++ b/modules/home-manager/sway.nix @@ -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 '' diff --git a/modules/home-manager/tmux.nix b/modules/home-manager/tmux.nix index 3c6d323b..4cdd2ccc 100644 --- a/modules/home-manager/tmux.nix +++ b/modules/home-manager/tmux.nix @@ -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 [ { diff --git a/modules/lib/default.nix b/modules/lib/default.nix index ee91c41d..891c6ced 100644 --- a/modules/lib/default.nix +++ b/modules/lib/default.nix @@ -1,4 +1,4 @@ -lib: +lib: {config, pkgs, sources, ...}: let # string -> type -> string -> a -> a # this is an internal function and shouldn't be @@ -6,7 +6,7 @@ let # 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}; @@ -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; @@ -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; @@ -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; })); @@ -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 diff --git a/modules/lib/mkExtLib.nix b/modules/lib/mkExtLib.nix index b7c45034..45ef539b 100644 --- a/modules/lib/mkExtLib.nix +++ b/modules/lib/mkExtLib.nix @@ -1 +1 @@ -lib: lib.extend (self: _: { ctp = import ./. self; }) +lib: args: lib.extend (self: _: { ctp = import ./. self args; }) diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index 16e7a40a..07a17b2f 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -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 = @@ -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; { diff --git a/modules/nixos/grub.nix b/modules/nixos/grub.nix index 296084fd..78b48ca0 100644 --- a/modules/nixos/grub.nix +++ b/modules/nixos/grub.nix @@ -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";