diff --git a/README.md b/README.md index c93eddc..5314dde 100644 --- a/README.md +++ b/README.md @@ -80,13 +80,13 @@ various extensions for nix-darwin #### home -customization for kitty terminal and neovim +customization for kitty terminal and kakoune ### overlays #### colors -cross-application color configurations +pure nix colorscheme palettes ### pkgs diff --git a/home/default.nix b/home/default.nix index a66e4d1..1759f3c 100644 --- a/home/default.nix +++ b/home/default.nix @@ -7,7 +7,6 @@ ./git.nix ./kakoune.nix ./kitty.nix - ./neovim.nix ./shells.nix ]; @@ -35,7 +34,13 @@ fish = { functions = { set-bat-colors = { - body = ''set -xg BAT_THEME "Solarized ($term_background)"''; + body = '' + if test "$term_background" = light + set -xg BAT_THEME "OneHalfLight" + else + set -xg BAT_THEME "OneHalfDark" + end + ''; onVariable = "term_background"; }; }; @@ -44,6 +49,19 @@ set-bat-colors ''; }; + neovim = { + enable = true; + viAlias = true; + vimAlias = true; + vimdiffAlias = true; + extraConfig = builtins.readFile ../configs/init.vim; + plugins = with pkgs.vimPlugins; [ + neovim-sensible + tokyonight-nvim + lightline-vim + ctrlp + ]; + }; # vscode vscode = with pkgs; { enable = true; @@ -91,6 +109,7 @@ nix-tree ] ++ lib.optionals stdenv.isDarwin [ m-cli # useful macOS CLI commands + is-dark-mode # see /overlays/colors.nix ]; # }}} diff --git a/home/neovim.nix b/home/neovim.nix deleted file mode 100644 index a438903..0000000 --- a/home/neovim.nix +++ /dev/null @@ -1,106 +0,0 @@ -{ config, pkgs, lib, ... }: - -let - inherit (lib) getName mkIf optional; - # inherit (config.lib.file) mkOutOfStoreSymlink; - nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix"; - - # nvr = "${pkgs.neovim-remote}/bin/nvr"; - - pluginWithDeps = plugin: deps: plugin.overrideAttrs (_: { dependencies = deps; }); - - nonVSCodePlugin = plugin: { - plugin = plugin; - optional = true; - config = ''if !exists('g:vscode') | packadd ${plugin.pname} | endif''; - }; -in - -{ - # Neovim - # https://rycee.gitlab.io/home-manager/options.html#opt-programs.neovim.enable - programs.neovim = { - enable = true; - viAlias = true; - vimAlias = true; - vimdiffAlias = true; - }; - - # Config and plugins ------------------------------------------------------------------------- {{{ - - home.sessionVariables = { - EDITOR = "nvim"; - }; - - # TODO: migrate to lua config - # Minimal init.vim config to load Lua config. Nix and Home Manager don't currently support - # `init.lua`. - # xdg.configFile."nvim/lua".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/lua"; - # xdg.configFile."nvim/colors".source = mkOutOfStoreSymlink "${nixConfigDir}/configs/nvim/colors"; - # programs.neovim.extraConfig = "lua require('init')"; - programs.neovim.extraConfig = builtins.readFile ../configs/init.vim; - - programs.neovim.plugins = with pkgs.vimPlugins; [ - neovim-sensible - tabular - vim-commentary - vim-surround - tokyonight-nvim - lightline-vim - vim-fish - vim-nix - ctrlp - ] ++ map (p: { plugin = p; optional = true; }) [ - which-key-nvim - zoomwintab-vim - nvim-treesitter - ] ++ map nonVSCodePlugin [ - direnv-vim - vim-fugitive - dhall-vim - haskell-vim - ]; - # }}} - - # Shell related ------------------------------------------------------------------------------ {{{ - - # From personal addon module `./modules/programs/neovim/extras.nix` - programs.neovim.extras.termBufferAutoChangeDir = true; - programs.neovim.extras.nvrAliases.enable = true; - - # programs.fish.functions.set-nvim-background = mkIf config.programs.neovim.enable { - # # See `./shells.nix` for more on how this is used. - # body = '' - # # Set `background` of all running Neovim instances base on `$term_background`. - # for server in (${nvr} --serverlist) - # ${nvr} -s --nostart --servername $server -c "set background=$term_background" & - # end - # ''; - # onVariable = "term_background"; - # }; - - # programs.fish.interactiveShellInit = mkIf config.programs.neovim.enable '' - # # Run Neovim related functions on init for their effects, and to register them so they are - # # triggered when the relevant event happens or variable changes. - # set-nvim-background - # ''; - # }}} - - # Required packages -------------------------------------------------------------------------- {{{ - - programs.neovim.extraPackages = with pkgs; [ - # neovim-remote - gcc # needed for nvim-treesitter - tree-sitter # needed for nvim-treesitter - - # Language servers - # See `../configs/nvim/lua/init.lua` for configuration. - # ccls - nodePackages.bash-language-server - nodePackages.vim-language-server - nodePackages.vscode-langservers-extracted - nodePackages.yaml-language-server - rnix-lsp - ] ++ optional (pkgs.stdenv.system != "x86_64-darwin") sumneko-lua-language-server; - # }}} -} diff --git a/home/shells.nix b/home/shells.nix index 388c021..a39acac 100644 --- a/home/shells.nix +++ b/home/shells.nix @@ -71,8 +71,7 @@ # trigger when this variable changes. We use a universal variable so that all instances of Fish # have the same value for the variable. set-background-to-macOS.body = '' - # Returns 'Dark' if in dark mode fails otherwise. - if defaults read -g AppleInterfaceStyle &>/dev/null + if is-dark-mode set -U term_background dark else set -U term_background light @@ -102,7 +101,7 @@ alias btm "btm --color default" end # Set LS_COLORS - set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate solarized-$term_background) + set -xg LS_COLORS (${pkgs.vivid}/bin/vivid generate one-$term_background) # Set color variables if test "$term_background" = light set emphasized_text brgreen # base01 @@ -143,6 +142,16 @@ set -g fish_color_escape red # color of character escapes like '\n' and and '\x70' set -g fish_color_cancel red # color of the '^C' indicator on a canceled command ''; + + from-dir = { + argumentNames = [ "dir" ]; + body = '' + pushd $dir + set -e argv[1] + $argv + popd + ''; + }; }; # }}} @@ -152,18 +161,22 @@ programs.fish.shellAliases = let nixConfigDir = "${config.home.homeDirectory}/dotfiles.nix"; - inNix = cmd: "pushd ${nixConfigDir}/; ${cmd}; popd"; in with pkgs; { # Nix related - # drb = "pushd ${nixConfigDir}/; darwin-rebuild build --flake ${nixConfigDir}/; popd"; - drb = inNix "darwin-rebuild flake --flake ${nixConfigDir}/"; - # drs = "pushd ${nixConfigDir}/; darwin-rebuild switch --flake ${nixConfigDir}/; popd"; - drs = inNix "darwin-rebuild switch --flake ${nixConfigDir}/"; + from-nix = "from-dir ${nixConfigDir}"; + # darwin-rebuild build + drb = "from-nix darwin-rebuild build --flake ."; + # darwin-rebuild switch full + drsf = "from-nix darwin-rebuild switch --flake ."; + # darwin-rebuild switch (no homebrew) + drs = "from-nix darwin-rebuild switch --flake . --override-input homebrew-enabled github:boolean-option/false"; + # edit darwin-rebuild config in codium drc = "codium ${nixConfigDir}"; + # edit darwin-rebuild config in vim drv = "vim ${nixConfigDir}"; - # drk = "pushd ${nixConfigDir}/; kak ./flake.nix; popd"; - drk = inNix "kak flake.nix"; + # edit darwin-rebuild config in kakoune + drk = "from-nix kak flake.nix"; flakeup = "nix flake update ${nixConfigDir}/"; nb = "nix build"; nd = "nix develop"; @@ -171,6 +184,7 @@ nr = "nix run"; ns = "nix search nixpkgs"; nsh = "nix shell"; + nrp = "nix repl --expr '{pkgs=(import {});}'"; # Other ".." = "cd .."; @@ -178,17 +192,17 @@ cat = "${bat}/bin/bat"; du = "${du-dust}/bin/dust"; g = "${gitAndTools.git}/bin/git"; - la = "ll -a"; - ll = "ls -l --time-style long-iso --icons"; ls = "${exa}/bin/exa"; + ll = "ls -l --time-style long-iso --icons"; + la = "ll -a"; ps = "${procs}/bin/procs"; + code = "${vscodium}/bin/codium"; + http = "${xh}/bin/xh"; + https = "${xh}/bin/xhs"; + top = "${bottom}/bin/btm"; + htop = "${bottom}/bin/btm"; tb = "toggle-background"; sb = "set-background-to-macOS"; - code = "codium"; - http = "xh"; - https = "xhs"; - top = "btm"; - htop = "btm"; }; # Configuration that should be above `loginShellInit` and `interactiveShellInit`. diff --git a/modules/home/programs/neovim/extras.nix b/modules/home/programs/neovim/extras.nix deleted file mode 100644 index 4cbf5ad..0000000 --- a/modules/home/programs/neovim/extras.nix +++ /dev/null @@ -1,168 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; - -let - cfg = config.programs.neovim.extras; - nvr = "${pkgs.neovim-remote}/bin/nvr"; - - shellConfig = with cfg.nvrAliases; '' - # START programs.neovim.extras config ---------------------------------------------------------- - '' + optionalString cfg.termBufferAutoChangeDir '' - # If shell is running in a Neovim terminal buffer, set the PWD of the buffer to `$PWD`. - if test -n "$NVIM_LISTEN_ADDRESS"; nvim-sync-term-buffer-pwd; end - '' + optionalString cfg.nvrAliases.enable '' - # Neovim Remote aliases - if test -n "$NVIM_LISTEN_ADDRESS" - alias ${edit} "${nvr}" - alias ${split} "${nvr} -o" - alias ${vsplit} "${nvr} -O" - alias ${tabedit} "${nvr} --remote-tab" - alias ${nvim} "command nvim" - alias nvim "echo 'This shell is running in a Neovim termainal buffer. Use \'${nvim}\' to a nested instance of Neovim, otherwise use ${edit}, ${split}, ${vsplit}, or ${tabedit} to open files in the this Neovim instance.'" - else - alias ${edit} "nvim" - end - '' + '' - # END programs.neovim.extras config ------------------------------------------------------------ - ''; -in -{ - options.programs.neovim.extras = { - termBufferAutoChangeDir = mkOption { - type = types.bool; - default = false; - description = '' - When enabled, the pwd of terminal buffers in Neovim are automatically - updated to match $PWD of the shell running inside them. - Note that you cannot use this option if you are using - , use - and instead. - (Currently only works with Fish shell.) - ''; - }; - - nvrAliases = { - enable = mkOption { - type = types.bool; - default = false; - description = '' - When enabled, shell aliases for helpful Neovim Remote commands are created if the shell is - running inside a Neovim terminal buffer. Additionally, running nvim - won't open a nested Neovim instance but instead print a message listing the available - nvr aliases, as well as the command to run if you actually want to open - a nested Neovim instance. - Note that you cannot use this option if you are using - , use - and - instead. - (Currently only works with Fish shell.) - ''; - }; - - edit = mkOption { - type = types.str; - default = "n"; - description = '' - Equivalent to Neovim's :edit command, i.e., running - n [file] will open the file in the current window. - When not in Neovim this also acts as an alias for nvim. - (Alias for nvr.) - ''; - }; - - split = mkOption { - type = types.str; - default = "ns"; - description = '' - Equivalent to Neovim's :split/command> command. - (Alias for nvr -o.) - ''; - }; - - vsplit = mkOption { - type = types.str; - default = "nv"; - description = '' - Equivalent to Neovim's :vsplit/command> command. - (Alias for nvr -O.) - ''; - }; - - tabedit = mkOption { - type = types.str; - default = "nt"; - description = '' - Equivalent to Neovim's :tabedit command. - (Alias for nvr --remote-tab.) - ''; - }; - - nvim = mkOption { - type = types.str; - default = "neovim"; - description = '' - Opens a nested Neovim instance. - ''; - }; - }; - - luaPackages = mkOption { - type = with types; listOf package; - default = [ ]; - example = [ pkgs.luajitPackages.busted pkgs.luajitPackages.luafilesystem ]; - description = '' - Lua packages to make available in Neovim Lua environment. - Note that you cannot use this option if you are using - , use - and instead. - ''; - }; - }; - - config = mkIf config.programs.neovim.enable { - programs.fish.functions.nvim-sync-term-buffer-pwd = mkIf cfg.termBufferAutoChangeDir { - body = '' - if test -n "$NVIM_LISTEN_ADDRESS" - ${nvr} -c "let g:term_buffer_pwds.$fish_pid = '$PWD' | call Set_term_buffer_pwd() " - end - ''; - onVariable = "PWD"; - }; - - programs.neovim.extraConfig = mkIf cfg.termBufferAutoChangeDir '' - " START programs.neovim.extras.termBufferAutoChangeDir config -------------------------------- - " Dictionary used to track the PWD of terminal buffers. Keys should be PIDs and values are is - " PWD of the shell with that PID. These values are updated from the shell using `nvr`. - let g:term_buffer_pwds = {} - " Function to call to update the PWD of the current terminal buffer. - function Set_term_buffer_pwd() abort - if &buftype == 'terminal' && exists('g:term_buffer_pwds[b:terminal_job_pid]') - execute 'lchd ' . g:term_buffer_pwds[b:terminal_job_pid] - endif - endfunction - " Sometimes the PWD the shell in a terminal buffer will change when in another buffer, so - " when entering a terminal buffer we update try to update it's PWD. - augroup NvimTermPwd - au! - au BufEnter * if &buftype == 'terminal' | call Set_term_buffer_pwd() | endif - augroup END - " END programs.neovim.extras.termBufferAutoChangeDir config ---------------------------------- - ''; - - programs.fish.interactiveShellInit = mkIf - (cfg.termBufferAutoChangeDir || cfg.nvrAliases.enable) - shellConfig; - - programs.neovim.plugins = lib.singleton ( - pkgs.vimUtils.buildVimPluginFrom2Nix { - name = "lua-env"; - src = pkgs.linkFarm "neovim-lua-env" ( - lib.forEach cfg.luaPackages ( - p: { name = "lua"; path = "${p}/lib/lua/${p.lua.luaversion}"; } - ) - ); - } - ); - }; -} diff --git a/overlays/colors.nix b/overlays/colors.nix index 31ba7b5..9e16800 100644 --- a/overlays/colors.nix +++ b/overlays/colors.nix @@ -1,10 +1,10 @@ -# Used in Kitty terminal config: `./kitty-configs.nix` - final: prev: { lib = prev.lib // { colors = { - solarized = import ./colors/solarized.nix; tokyonight = import ./colors/tokyonight.nix; }; }; + is-dark-mode = prev.writeShellScriptBin "is-dark-mode" '' + defaults read -g AppleInterfaceStyle &>/dev/null + ''; } diff --git a/overlays/colors/solarized.nix b/overlays/colors/solarized.nix deleted file mode 100644 index 758413b..0000000 --- a/overlays/colors/solarized.nix +++ /dev/null @@ -1,118 +0,0 @@ -# Colors from: https://ethanschoonover.com/solarized - -# SOLARIZED HEX 16/8 TERMCOL XTERM/HEX L*A*B RGB HSB -# --------- ------- ---- ------- ----------- ---------- ----------- ----------- -# base03 #002b36 8/4 brblack 234 #1c1c1c 15 -12 -12 0 43 54 193 100 21 -# base02 #073642 0/4 black 235 #262626 20 -12 -12 7 54 66 192 90 26 -# base01 #586e75 10/7 brgreen 240 #585858 45 -07 -07 88 110 117 194 25 46 -# base00 #657b83 11/7 bryellow 241 #626262 50 -07 -07 101 123 131 195 23 51 -# base0 #839496 12/6 brblue 244 #808080 60 -06 -03 131 148 150 186 13 59 -# base1 #93a1a1 14/4 brcyan 245 #8a8a8a 65 -05 -02 147 161 161 180 9 63 -# base2 #eee8d5 7/7 white 254 #e4e4e4 92 -00 10 238 232 213 44 11 93 -# base3 #fdf6e3 15/7 brwhite 230 #ffffd7 97 00 10 253 246 227 44 10 99 -# yellow #b58900 3/3 yellow 136 #af8700 60 10 65 181 137 0 45 100 71 -# orange #cb4b16 9/3 brred 166 #d75f00 50 50 55 203 75 22 18 89 80 -# red #dc322f 1/1 red 160 #d70000 50 65 45 220 50 47 1 79 86 -# magenta #d33682 5/5 magenta 125 #af005f 50 65 -05 211 54 130 331 74 83 -# violet #6c71c4 13/5 brmagenta 61 #5f5faf 50 15 -45 108 113 196 237 45 77 -# blue #268bd2 4/4 blue 33 #0087ff 55 -10 -45 38 139 210 205 82 82 -# cyan #2aa198 6/6 cyan 37 #00afaf 60 -35 -05 42 161 152 175 74 63 -# green #859900 2/2 green 64 #5f8700 60 -20 65 133 153 0 68 100 60 - -rec { - colors = { - darkBase = "002b36"; # base03 - darkBasehl = "073642"; # base02 - darkestTone = "586e75"; # base01 - darkTone = "657b83"; # base00 - lightTone = "839496"; # base0 - lightestTone = "93a1a1"; # base1 - lightBasehl = "eee8d5"; # base2 - lightBase = "fdf6e3"; # base3 - yellow = "b58900"; - orange = "cb4b16"; - red = "dc322f"; - magenta = "d33682"; - violet = "6c71c4"; - blue = "268bd2"; - cyan = "2aa198"; - green = "859900"; - }; - - _light = with colors; { - base = lightBase; - basehl = lightBasehl; - invbase = darkBase; - invbasehl = darkBasehl; - main = darkTone; - faded = lightTone; - muted = lightestTone; - strong = darkestTone; - inherit (colors) yellow orange red megenta violet blue cyan green; - }; - - _dark = with colors; { - base = darkBase; - basehl = darkBasehl; - invbase = lightBase; - invbasehl = lightBasehl; - main = lightTone; - faded = darkTone; - muted = darkestTone; - strong = lightestTone; - inherit (colors) yellow orange red megenta violet blue cyan green; - }; - - backgroundDependentColors = colors: with colors; { - background = "#${base}"; - foreground = "#${main}"; - - # Cursor - cursor = "#${blue}"; - cursor_text_color = "#${base}"; - - # Selection - selection_background = "#${muted}"; - selection_foreground = "#${base}"; - - # Tab bar - tab_bar_background = "#${basehl}"; - inactive_tab_background = "#${strong}"; - }; - - dark = backgroundDependentColors _dark; - light = backgroundDependentColors _light; - - common = with colors; { - # black - color0 = "#${darkBasehl}"; - color8 = "#${darkBase}"; - # red - color1 = "#${red}"; - color9 = "#${orange}"; - # green - color2 = "#${green}"; - color10 = "#${darkestTone}"; - # yellow - color3 = "#${yellow}"; - color11 = "#${darkTone}"; - # blue - color4 = "#${blue}"; - color12 = "#${lightTone}"; - # magenta - color5 = "#${magenta}"; - color13 = "#${violet}"; - # cyan - color6 = "#${cyan}"; - color14 = "#${lightestTone}"; - # white - color7 = "#${lightBasehl}"; - color15 = "#${lightBase}"; - # url underline color to fit colors - url_color = "#${blue}"; - # tab bar - active_tab_foreground = "#${lightBase}"; - active_tab_background = "#${green}"; - inactive_tab_foreground = "#${lightBase}"; - }; -} diff --git a/pkgs/default.nix b/pkgs/default.nix index 74bd4b4..4cb1215 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -4,6 +4,11 @@ let callPackage (./. + "/${name}.nix") { "${name}-src" = inputs."${name}-src"; }; - pkgs = [ "dark-mode-notify" "luar" "smarttab-kak" ]; + pkgs = [ + "dark-mode-notify" + "luar" + "smarttab-kak" + "kitty-themes" + ]; in genAttrs pkgs buildPkg diff --git a/pkgs/kitty-themes.nix b/pkgs/kitty-themes.nix new file mode 100644 index 0000000..b105adc --- /dev/null +++ b/pkgs/kitty-themes.nix @@ -0,0 +1,13 @@ +{ kitty-themes-src, stdenv, ... }: + +stdenv.mkDerivation { + name = "kitty-themes"; + src = kitty-themes-src; + dontBuild = true; + + installPhase = '' + mkdir -p $out + + cp themes/* $out + ''; +}