1
Fork 0

feat: dynamic theming attempt

This commit is contained in:
Matei Adriel 2022-03-10 21:59:18 +02:00
parent 18c51ecc13
commit 2757c649b9
18 changed files with 120 additions and 30 deletions

View file

@ -33,7 +33,7 @@ function M.setup()
helpers.global("mapleader", "<Space>") helpers.global("mapleader", "<Space>")
-- Set theme -- Set theme
require('github-theme').setup({theme_style = "light", dark_float = true}) -- require('github-theme').setup({theme_style = "light", dark_float = true, transparent = true})
end end
return M return M

View file

@ -2,7 +2,7 @@ local M = {}
function M.setup() function M.setup()
require('lualine').setup({ require('lualine').setup({
theme = "github", theme = vim.g.lualineTheme,
-- Integration with other plugins -- Integration with other plugins
extensions = {"nvim-tree"} extensions = {"nvim-tree"}

View file

@ -1,29 +1,32 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let let
githubAlacrittyTheme = themes = pkgs.myThemes;
"${pkgs.githubNvimTheme}/terminal/alacritty/github_light.yml";
createTheme = (theme: {
xdg.configFile."alacritty/themes/${theme.name}.yml".text = builtins.toJSON
(lib.attrs.recursiveUpdate theme.alacritty.settings {
import = [ "~/.config/alacritty/alacritty.yml" ];
});
});
createThemeConfigs = lib.lists.foldr
(acc: theme: lib.attrs.recursiveUpdate acc (createTheme theme))
{ }
themes;
in in
{ {
imports = [
{
home-manager.users.adrielus = createThemeConfigs;
}
];
home-manager.users.adrielus.programs.alacritty = { home-manager.users.adrielus.programs.alacritty = {
enable = true; enable = true;
settings = { settings = {
import = [ githubAlacrittyTheme ]; window.decorations = "none";
window = {
decorations = "none";
padding = {
x = 8;
y = 8;
};
gtk_theme_variant = "light";
};
# transparent bg:)
# background_opacity = 0.6;
fonts.normal.family = "Nerd Font Source Code Pro"; fonts.normal.family = "Nerd Font Source Code Pro";
}; };
}; };

View file

@ -1,10 +1,30 @@
{ pkgs, ... }: { pkgs, lib, ... }:
let let
themes = pkgs.myThemes;
# config-nvim = "/etc/nixos/configuration/dotfiles/neovim"; # config-nvim = "/etc/nixos/configuration/dotfiles/neovim";
config-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix { config-nvim = pkgs.vimUtils.buildVimPluginFrom2Nix {
name = "config-nvim"; name = "config-nvim";
src = ../../dotfiles/neovim; src = ../../dotfiles/neovim;
}; };
themePlugins = lib.lists.concatMap (theme: theme.neovim.plugins) themes;
loadTheme = (theme: ''
if currentTheme = "${theme.name}" then
${theme.neovim.theme}
vim.g.lualineTheme = ${theme.neovim.lualineTheme}
end
'');
loadThemes = ''
local currentTheme = os.getenv("THEME");
${pkgs.myHelpers.mergeLines (lib.lists.forEach themes loadTheme)};
'';
in in
{ {
home-manager.users.adrielus.programs.neovim = { home-manager.users.adrielus.programs.neovim = {
@ -37,9 +57,8 @@ in
]; ];
plugins = with pkgs.vimPlugins; plugins = with pkgs.vimPlugins;
with pkgs.vimExtraPlugins; with pkgs.myVimPlugins; [ with pkgs.vimExtraPlugins; with pkgs.myVimPlugins; themePlugins + [
config-nvim # my neovim config config-nvim # my neovim config
github-nvim-theme # github theme for neovim
nvim-lspconfig # configures lsps for me nvim-lspconfig # configures lsps for me
nvim-autopairs # close pairs for me nvim-autopairs # close pairs for me
telescope-nvim # fuzzy search for say opening files telescope-nvim # fuzzy search for say opening files

View file

@ -23,4 +23,6 @@
# Render git repo using gource # Render git repo using gource
"git-render" = "gource -f -s 1 -c 4 --key"; "git-render" = "gource -f -s 1 -c 4 --key";
alacritty = "alacritty --config-file $XDG_CONFIG_HOME/alacritty/themes/$THEME.yml";
} }

View file

@ -8,6 +8,9 @@ let
# Sets neovim as default editor # Sets neovim as default editor
EDITOR = "nvim"; EDITOR = "nvim";
# Sets the current theme used by all programs
THEME = "github-light";
}; };
in in
{ {

View file

@ -1,4 +1,12 @@
{ pkgs, ... }: { { pkgs, lib, ... }:
let
sourceTmuxTheme = (theme: ''
# Only load this theme if it's the current one
if '[[ "$THEME" =~ ${theme.name} ]]' 'source ${theme.tmux.path}'
'');
tmuxThemes = pkgs.myHelpers.mergeLines (lib.lists.forEach pkgs.myThemes sourceTmuxTheme);
in
{
home-manager.users.adrielus.programs = { home-manager.users.adrielus.programs = {
# Add tmux-navigator plugin to neovim # Add tmux-navigator plugin to neovim
neovim.extraPackages = [ pkgs.vimPlugins.vim-tmux-navigator ]; neovim.extraPackages = [ pkgs.vimPlugins.vim-tmux-navigator ];
@ -16,8 +24,8 @@
]; ];
extraConfig = '' extraConfig = ''
# Use github light theme # Load every theme available
source-file ${pkgs.githubNvimTheme}/terminal/tmux/github_light.conf ${tmuxThemes}
# load the rest of the config # load the rest of the config
source-file ${../../dotfiles/tmux/tmux.conf} source-file ${../../dotfiles/tmux/tmux.conf}

View file

@ -95,7 +95,7 @@ main =
startup :: X () startup :: X ()
startup = do startup = do
spawn "xwallpaper --zoom ./background.jpg" spawn "xwallpaper --zoom ./picutres/portal.png"
-- spawn "Discord" -- spawn "Discord"
-- spawn "google-chrome-stable" -- spawn "google-chrome-stable"

View file

@ -2,7 +2,7 @@
imports = [ imports = [
./dev ./dev
./applications ./applications
./theme ./themes
./overlays ./overlays
./network.nix ./network.nix

8
modules/helpers.nix Normal file
View file

@ -0,0 +1,8 @@
{ lib, ... }: {
mergeLines = (lines: lib.foldr
(a: b: ''
${a}
${b}
'') ""
lines);
}

View file

@ -1,6 +1,7 @@
{ pkgs, ... }: { { pkgs, ... }: {
nixpkgs.overlays = [ nixpkgs.overlays = [
(import ./tweakSources.nix) (import ./tweakSources.nix)
(import ./myPackages.nix)
(import ./npm.nix) (import ./npm.nix)
# I hope this works (spoiler: it did not) # I hope this works (spoiler: it did not)

View file

@ -59,10 +59,11 @@ in
}; };
}; };
githubNvimTheme = githubNvimTheme;
# Vim plugins # Vim plugins
myVimPlugins = { myVimPlugins = {
githubNvimTheme = githubNvimTheme;
telescope-file-browser-nvim = telescope-file-browser-nvim =
plugin "file_browser" telescope-file-browser-nvim; plugin "file_browser" telescope-file-browser-nvim;

View file

@ -0,0 +1,5 @@
self: super:
with self; {
myHelpers = self.callPackage (import ../helpers.nix) { };
myThemes = self.callPackage (import ../themes/themes.nix) { };
}

View file

@ -0,0 +1,29 @@
variant: { pkgs, ... }: {
name = "github-${variant}";
neovim = {
plugins = [
pkgs.myVimPlugins.github-nvim-theme # github theme for neovim
];
theme = ''
require('github-theme').setup({theme_style = "light", dark_float = true, transparent = true})
'';
lualineTheme = "github";
};
tmux.path = "${pkgs.githubNvimTheme}/terminal/tmux/github_light.conf";
alacritty.settings = {
import = [ "${pkgs.githubNvimTheme}/terminal/alacritty/github_light.yml" ];
window = {
padding = {
x = 8;
y = 8;
};
# transparent bg:)
background_opacity = 0.8;
gtk_theme_variant = "light";
};
};
}

2
modules/themes/theme.nix Normal file
View file

@ -0,0 +1,2 @@

View file

@ -0,0 +1,9 @@
{ pkgs }:
let githubVariant = import ./githubVariant.nix;
in
lib.map (theme: pkgs.callPackage theme { }) [
githubVariant
"light"
githubVariant
"dark"
]