Skip to content

Commit

Permalink
refactor: use alternatives to with and rec (#38)
Browse files Browse the repository at this point in the history
* fix(home-manager): dont declare xdg.configFile when btop isn't enabled

* refactor: use alternatives to `with` and `rec`

---------

Co-authored-by: Sam Nystrom <[email protected]>
  • Loading branch information
getchoo and Stonks3141 authored Jul 13, 2023
1 parent 9616836 commit 60a1d9b
Show file tree
Hide file tree
Showing 17 changed files with 306 additions and 200 deletions.
39 changes: 23 additions & 16 deletions modules/home-manager/alacritty.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
{ config, pkgs, lib, ... }:
let cfg = config.programs.alacritty.catppuccin;
in {
{ config
, pkgs
, lib
, ...
}:
let
inherit (lib) ctp;
cfg = config.programs.alacritty.catppuccin;
enable = cfg.enable && config.programs.alacritty.enable;
in
{
options.programs.alacritty.catppuccin =
lib.ctp.mkCatppuccinOpt "alacritty" config;
ctp.mkCatppuccinOpt "alacritty" config;

config.programs.alacritty.settings = with builtins;
with lib;
with pkgs;
config.programs.alacritty.settings =
let
file = fetchFromGitHub
{
owner = "catppuccin";
repo = "alacritty";
rev = "3c808cbb4f9c87be43ba5241bc57373c793d2f17";
sha256 = "sha256-w9XVtEe7TqzxxGUCDUR9BFkzLZjG8XrplXJ3lX6f+x0=";
} + "/catppuccin-${cfg.flavour}.yml";

file =
pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "alacritty";
rev = "3c808cbb4f9c87be43ba5241bc57373c793d2f17";
sha256 = "sha256-w9XVtEe7TqzxxGUCDUR9BFkzLZjG8XrplXJ3lX6f+x0=";
}
+ "/catppuccin-${cfg.flavour}.yml";
in
mkIf cfg.enable (ctp.fromYaml pkgs file);
lib.mkIf enable (ctp.fromYaml pkgs file);
}
16 changes: 12 additions & 4 deletions modules/home-manager/bat.nix
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
{ config, pkgs, lib, ... }:
let cfg = config.programs.bat.catppuccin; in
{ config
, pkgs
, lib
, ...
}:
let
cfg = config.programs.bat.catppuccin;
enable = cfg.enable && config.programs.bat.enable;
in
{
options.programs.bat.catppuccin =
lib.ctp.mkCatppuccinOpt "bat" config;

config = {
programs.bat = lib.mkIf cfg.enable {
programs.bat = lib.mkIf enable {
config.theme = "Catppuccin-${cfg.flavour}";
themes."Catppuccin-${cfg.flavour}" = builtins.readFile (pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "bat";
rev = "ba4d16880d63e656acced2b7d4e034e4a93f74b1";
sha256 = "sha256-6WVKQErGdaqb++oaXnY3i6/GuH2FhTgK0v4TN4Y0Wbw=";
} + /Catppuccin-${cfg.flavour}.tmTheme);
}
+ "/Catppuccin-${cfg.flavour}.tmTheme");
};
};
}
32 changes: 19 additions & 13 deletions modules/home-manager/bottom.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
{ config, pkgs, lib, ... }:
let cfg = config.programs.bottom.catppuccin;
in {
{ config
, pkgs
, lib
, ...
}:
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;

config.programs.bottom.settings = with builtins;
with lib;
with pkgs;
mkIf cfg.enable (fromTOML (readFile (fetchFromGitHub
{
owner = "catppuccin";
repo = "bottom";
rev = "c0efe9025f62f618a407999d89b04a231ba99c92";
sha256 = "sha256-VaHX2I/Gn82wJWzybpWNqU3dPi3206xItOlt0iF6VVQ=";
} + "/themes/${cfg.flavour}.toml")));
config.programs.bottom.settings = lib.mkIf enable (fromTOML (readFile (pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "bottom";
rev = "c0efe9025f62f618a407999d89b04a231ba99c92";
sha256 = "sha256-VaHX2I/Gn82wJWzybpWNqU3dPi3206xItOlt0iF6VVQ=";
}
+ "/themes/${cfg.flavour}.toml")));
}
11 changes: 7 additions & 4 deletions modules/home-manager/btop.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
, ...
}:
let
inherit (lib) mkIf;
cfg = config.programs.btop.catppuccin;
enable = cfg.enable && config.programs.btop.enable;

themePath = "/themes/catppuccin_${cfg.flavour}.theme";
theme =
pkgs.fetchFromGitHub
Expand All @@ -23,12 +26,12 @@ in
# xdg is required for this to work
config =
{
xdg.enable = with lib; mkIf cfg.enable (mkForce true);
xdg.enable = mkIf enable (lib.mkForce true);

programs.btop.settings.color_theme = with lib;
mkIf cfg.enable "${config.xdg.configHome + "/btop/${themePath}"}";
programs.btop.settings.color_theme =
mkIf enable "${config.xdg.configHome + "/btop/${themePath}"}";
}
// (lib.mkIf cfg.enable {
// (lib.mkIf enable {
xdg.configFile."btop${themePath}".source = theme;
});
}
13 changes: 9 additions & 4 deletions modules/home-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
nixpkgs: { config, pkgs, lib, ... }:
nixpkgs: { config
, pkgs
, lib
, ...
}:
let
extendedLib = import ../lib/mkExtLib.nix nixpkgs.lib;
inherit (extendedLib) ctp;
in
{
imports =
Expand All @@ -23,13 +28,13 @@ in
in
extendedLib.ctp.mapModules config pkgs extendedLib files;

options.catppuccin = with extendedLib; {
flavour = mkOption {
options.catppuccin = {
flavour = lib.mkOption {
type = ctp.types.flavourOption;
default = "latte";
description = "Global Catppuccin flavour";
};
accent = mkOption {
accent = lib.mkOption {
type = ctp.types.accentOption;
default = "teal";
description = "Global Catppuccin accent";
Expand Down
33 changes: 21 additions & 12 deletions modules/home-manager/gtk.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
{ config, pkgs, lib, ... }:
let cfg = config.gtk.catppuccin;
in {
options.gtk.catppuccin = with lib;
ctp.mkCatppuccinOpt "gtk" config // {
{ config
, pkgs
, lib
, ...
}:
let
inherit (lib) ctp mkOption types;
cfg = config.gtk.catppuccin;
enable = cfg.enable && config.gtk.enable;
in
{
options.gtk.catppuccin =
ctp.mkCatppuccinOpt "gtk" config
// {
accent = ctp.mkAccentOpt "gtk" config;
size = mkOption {
type = types.enum [ "standard" "compact" ];
Expand All @@ -16,20 +25,20 @@ in {
};
};

config.gtk.theme = with builtins;
with lib;
config.gtk.theme =
let
flavourUpper = ctp.mkUpper cfg.flavour;
accentUpper = ctp.mkUpper cfg.accent;
sizeUpper = ctp.mkUpper cfg.size;

# 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";
in
mkIf cfg.enable {
name =
"Catppuccin-${flavourUpper}-${sizeUpper}-${accentUpper}-${gtkTheme}";
lib.mkIf enable {
name = "Catppuccin-${flavourUpper}-${sizeUpper}-${accentUpper}-${gtkTheme}";
package = pkgs.catppuccin-gtk.override {
inherit (cfg) size tweaks;
accents = [ cfg.accent ];
Expand Down
38 changes: 26 additions & 12 deletions modules/home-manager/helix.nix
Original file line number Diff line number Diff line change
@@ -1,26 +1,40 @@
{ config, pkgs, lib, ... }:
let cfg = config.programs.helix.catppuccin;
in {
{ config
, pkgs
, lib
, ...
}:
let
inherit (builtins) fromTOML readFile;
cfg = config.programs.helix.catppuccin;
enable = cfg.enable && config.programs.helix.enable;
in
{
options.programs.helix.catppuccin = with lib;
ctp.mkCatppuccinOpt "helix" config // {
ctp.mkCatppuccinOpt "helix" config
// {
useItalics = mkEnableOption "Italics in Catppuccin theme for Helix";
};

config.programs.helix = with builtins;
with lib;
with pkgs;
let subdir = if cfg.useItalics then "default" else "no_italics";
in mkIf cfg.enable {
config.programs.helix =
let
subdir =
if cfg.useItalics
then "default"
else "no_italics";
in
lib.mkIf enable {
settings = {
theme = "catppuccin-${cfg.flavour}";
editor.color-modes = mkDefault true;
editor.color-modes = lib.mkDefault true;
};
themes."catppuccin-${cfg.flavour}" = fromTOML (readFile (fetchFromGitHub

themes."catppuccin-${cfg.flavour}" = fromTOML (readFile (pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "helix";
rev = "5677c16dc95297a804caea9161072ff174018fdd";
sha256 = "sha256-aa8KZ7/1TXcBqaV/TYOZ8rpusOf5QeQ9i2Upnncbziw=";
} + "/themes/${subdir}/catppuccin_${cfg.flavour}.toml"));
}
+ "/themes/${subdir}/catppuccin_${cfg.flavour}.toml"));
};
}
20 changes: 13 additions & 7 deletions modules/home-manager/kitty.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
{ config, lib, ... }:
let cfg = config.programs.kitty.catppuccin;
in {
{ config
, lib
, ...
}:
let
inherit (lib) ctp;
cfg = config.programs.kitty.catppuccin;
enable = cfg.enable && config.programs.kitty.enable;
in
{
options.programs.kitty.catppuccin =
lib.ctp.mkCatppuccinOpt "kitty" config;
ctp.mkCatppuccinOpt "kitty" config;

config.programs.kitty = with lib;
let flavourUpper = ctp.mkUpper cfg.flavour;
in mkIf cfg.enable { theme = "Catppuccin-${flavourUpper}"; };
config.programs.kitty =
lib.mkIf enable { theme = "Catppuccin-${ctp.mkUpper cfg.flavour}"; };
}
36 changes: 21 additions & 15 deletions modules/home-manager/lazygit.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
{ config, pkgs, lib, ... }:
let cfg = config.programs.lazygit.catppuccin;
in {
{ config
, pkgs
, lib
, ...
}:
let
cfg = config.programs.lazygit.catppuccin;
enable = cfg.enable && config.programs.lazygit.enable;
in
{
options.programs.lazygit.catppuccin =
lib.ctp.mkCatppuccinOpt "lazygit" config;

config.programs.lazygit.settings = with builtins;
with lib;
with pkgs;
config.programs.lazygit.settings =
let
file = fetchFromGitHub
{
owner = "catppuccin";
repo = "lazygit";
rev = "f01edfd57fa2aa7cd69a92537a613bb3c91e65dd";
sha256 = "sha256-zjzDtXcGtUon4QbrZnlAPzngEyH56yy8TCyFv0rIbOA=";
} + "/themes/${cfg.flavour}.yml";

file =
pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "lazygit";
rev = "f01edfd57fa2aa7cd69a92537a613bb3c91e65dd";
sha256 = "sha256-zjzDtXcGtUon4QbrZnlAPzngEyH56yy8TCyFv0rIbOA=";
}
+ "/themes/${cfg.flavour}.yml";
in
mkIf cfg.enable (ctp.fromYaml pkgs file);
lib.mkIf enable (lib.ctp.fromYaml pkgs file);
}
9 changes: 7 additions & 2 deletions modules/home-manager/neovim.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,16 @@
{ config, pkgs, lib, ... }:
{ config
, pkgs
, lib
, ...
}:
let
cfg = config.programs.neovim.catppuccin;
enable = cfg.enable && config.programs.neovim.enable;
in
{
options.programs.neovim.catppuccin = lib.ctp.mkCatppuccinOpt "neovim" config;

config.programs.neovim = with lib; mkIf cfg.enable {
config.programs.neovim = lib.mkIf enable {
plugins = with pkgs.vimPlugins; [
{
plugin = catppuccin-nvim;
Expand Down
31 changes: 18 additions & 13 deletions modules/home-manager/polybar.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
{ config, pkgs, lib, ... }:
let cfg = config.services.polybar.catppuccin;
in {
{ config
, pkgs
, lib
, ...
}:
let
cfg = config.services.polybar.catppuccin;
enable = cfg.enable && config.services.polybar.enable;
in
{
options.services.polybar.catppuccin =
lib.ctp.mkCatppuccinOpt "polybar" config;

config.services.polybar.extraConfig = with builtins;
with lib;
with pkgs;
mkIf cfg.enable (readFile (fetchFromGitHub
{
owner = "catppuccin";
repo = "polybar";
rev = "9ee66f83335404186ce979bac32fcf3cd047396a";
sha256 = "sha256-bUbSgMg/sa2faeEUZo80GNmhOX3wn2jLzfA9neF8ERA=";
} + "/themes/${cfg.flavour}.ini"));
config.services.polybar.extraConfig = lib.mkIf enable (builtins.readFile (pkgs.fetchFromGitHub
{
owner = "catppuccin";
repo = "polybar";
rev = "9ee66f83335404186ce979bac32fcf3cd047396a";
sha256 = "sha256-bUbSgMg/sa2faeEUZo80GNmhOX3wn2jLzfA9neF8ERA=";
}
+ "/themes/${cfg.flavour}.ini"));
}
Loading

0 comments on commit 60a1d9b

Please sign in to comment.