From 88bdcca926de3a5fd5dd63adcb631399a4ca143a Mon Sep 17 00:00:00 2001 From: joygnu Date: Wed, 3 Jul 2024 22:57:23 +0200 Subject: [PATCH] rb --- home/default.nix | 20 +----- home/my_nvchad_config | 1 - home/neovim/default.nix | 114 +++++++++++++++++++++++++++++++ home/neovim/populate-nvim-env.py | 87 +++++++++++++++++++++++ modules/packages/default.nix | 1 + 5 files changed, 204 insertions(+), 19 deletions(-) delete mode 160000 home/my_nvchad_config create mode 100644 home/neovim/default.nix create mode 100644 home/neovim/populate-nvim-env.py diff --git a/home/default.nix b/home/default.nix index 342ff0b..e204367 100644 --- a/home/default.nix +++ b/home/default.nix @@ -9,28 +9,12 @@ ./gtk ./git ./ags + ./neovim inputs.nix-colors.homeManagerModules.default inputs.ags.homeManagerModules.default ]; - programs.neovim.enable = true; - - xdg.configFile."nvim".source = pkgs.stdenv.mkDerivation { - name = "NvChad"; - src = pkgs.fetchFromGitHub { - owner = "NvChad"; - repo = "NvChad"; - rev = "f17e83010f25784b58dea175c6480b3a8225a3e9"; - hash = "sha256-P5TRjg603/7kOVNFC8nXfyciNRLsIeFvKsoRCIwFP3I="; - }; - installPhase = '' - mkdir -p $out - cp -r ./* $out/ - cd $out/ - cp -r ${./my_nvchad_config} $out/lua/custom - ''; - }; - + home.username = "joy"; home.homeDirectory = "/home/joy"; home.stateVersion = "23.11"; diff --git a/home/my_nvchad_config b/home/my_nvchad_config deleted file mode 160000 index 82c9711..0000000 --- a/home/my_nvchad_config +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 82c9711f62025c16d138c0bc6e8b7cf46ca6ccc5 diff --git a/home/neovim/default.nix b/home/neovim/default.nix new file mode 100644 index 0000000..f34d069 --- /dev/null +++ b/home/neovim/default.nix @@ -0,0 +1,114 @@ +{ flake +, config +, pkgs +, lib +, ... +}: + + +let + inherit (lib) concatStringsSep optional; + inherit (config.lib.file) mkOutOfStoreSymlink; + + cfg = config.programs.neovim; + + home = config.home.homeDirectory; + populateEnv = ./populate-nvim-env.py; + + populateEnvScript = openapi_path: '' + mkdir -p ${config.xdg.dataHome}/nvim/site/plugin + ${pkgs.python39}/bin/python ${populateEnv} -o ${config.xdg.dataHome}/nvim/site/plugin --openapi_path "${openapi_path}" + ''; +in +{ + # Neovim + + # https://rycee.gitlab.io/home-manager/options.html#opt-programs.neovim.enable + programs.neovim = { + enable = true; + viAlias = true; + vimAlias = true; + defaultEditor = true; + package = pkgs.neovim-nightly; + extraLuaPackages = ps: [ ps.magick ]; + }; + + # xdg.configFile."nvim" = { + # source = config.lib.file.mkOutOfStoreSymlink "${home}/.config/nvim"; + # recursive = true; + # }; + + home.packages = with pkgs.unstable; [ + tree-sitter + lua-language-server + stylua + shfmt + + # python + python311Packages.flake8 + python311Packages.black + python311Packages.python-lsp-server + + # web stuff + nodePackages_latest.prettier + nodePackages_latest.eslint_d + nodePackages_latest.vscode-langservers-extracted + nodePackages_latest.typescript-language-server + + # rust + rust-analyzer + rustfmt + + # config + taplo + + # nix + nixpkgs-fmt + rnix-lsp + + (pkgs.writeShellScriptBin "update-nvim-env" '' + # + # update-nvim-env + # + # Update neovim env such that it can be used in neovide or other GUIs. + + ${populateEnvScript config.sops.secrets.openapi-key.path} + '') + (pkgs.writeShellScriptBin "clean-nvim-all" '' + rm -rf ${config.xdg.dataHome}/nvim + rm -rf ${config.xdg.cacheHome}/nvim + rm -rf ${config.xdg.stateHome}/nvim + rm -rf ${config.xdg.configHome}/nvim + '') + (pkgs.writeShellScriptBin "clean-nvim" '' + rm -rf ${config.xdg.dataHome}/nvim + rm -rf ${config.xdg.stateHome}/nvim + rm -rf ${config.xdg.cacheHome}/nvim + '') + ]; + + home.activation.neovim = lib.hm.dag.entryAfter [ "writeBoundary" ] '' + echo "Populating neovim env..." + ${populateEnvScript config.sops.secrets.openapi-key.path} + ''; + + programs.zsh.initExtra = lib.mkIf cfg.enable (lib.mkAfter '' + # alias n="${pkgs.neovim}/bin/nvim" + ''); + + + sops = { + age.keyFile = "${home}/.config/sops/age/keys.txt"; + age.generateKey = true; + secrets = { + openapi-key = { + # owner = "rayandrew"; + mode = "0440"; + sopsFile = ../../secrets.yaml; + # path = "%r/openapi-key.txt"; + path = "${config.home.homeDirectory}/.openai_api_key"; + # neededForUsers = true; + }; + }; + }; +} diff --git a/home/neovim/populate-nvim-env.py b/home/neovim/populate-nvim-env.py new file mode 100644 index 0000000..46c43bd --- /dev/null +++ b/home/neovim/populate-nvim-env.py @@ -0,0 +1,87 @@ +#!/bin/env python3 + +import os +from collections import OrderedDict +import argparse +from pathlib import Path + +KEYS = [ + # PATH + "PATH", + "CS154_ADMIN", + "BREW_PREFIX", + "CONDA_PYTHON_EXE", + "SPACESHIP_ROOT", + "COLORFGBG", + "XPC_SERVICE_NAME", + "_CE_M", + "XPC_FLAGS", + "LANG", + # terminal + "VISUAL", + "LESS", + "LOGNAME", + "COLORTERM", + "HISTFILE", + "LC_TERMINAL", + "LC_TERMINAL_VERSION", + "ITERM_SESSION_ID", + "ITERM_PROFILE", + "TERM_SESSION_ID", + "TERM_PROGRAM", + "STARSHIP_SESSION_KEY", + "STARSHIP_CONFIG", + "VI_MODE_SET_CURSOR", + "_", + "LSCOLORS", + "ZSH", + "EDITOR", + # XDG + "XDG_DATA_HOME", + "XDG_STATE_HOME", + "XDG_CACHE_HOME", + "XDG_CONFIG_HOME", +] + + +def main(args): + env = os.environ.copy() + env = OrderedDict(sorted(env.items())) + dst_file = "{}/env.lua".format(args.output_path) + + openapi_key = None + + if args.openapi_path != "": + openapi_path = Path(args.openapi_path) + if openapi_path.exists(): + with open(openapi_path, "r") as f: + openapi_key = f.readline().strip("\n") + + with open(dst_file, "w") as f: + for key, value in env.items(): + if key in KEYS: + if key == "PATH": + f.write('vim.env.PATH = vim.env.PATH .. ":{}"\n'.format(value)) + continue + f.write('vim.fn.setenv("{}", "{}")\n'.format(key, value)) + + if openapi_key is not None: + f.write('vim.fn.setenv("OPENAI_API_KEY", "{}")\n'.format(openapi_key)) + + f.close() + + +if __name__ == "__main__": + home_directory = os.path.expanduser("~") + parser = argparse.ArgumentParser("Neovim Populate Env") + parser.add_argument("--openapi_path", required=False, type=str, default="") + parser.add_argument( + "-o", + "--output_path", + required=False, + help="Output Path", + type=str, + default="{}/.config/nvim/lua/rayandrew".format(home_directory), + ) + args = parser.parse_args() + main(args) diff --git a/modules/packages/default.nix b/modules/packages/default.nix index 7efef71..70abe30 100644 --- a/modules/packages/default.nix +++ b/modules/packages/default.nix @@ -55,6 +55,7 @@ boxbuddy distrobox neovim + python3 cl ]; }