From a5186b204c3bb42c82da289bed05155c24213574 Mon Sep 17 00:00:00 2001 From: Hung Date: Sun, 11 Jun 2023 21:21:01 -0700 Subject: [PATCH] feat: idempotent installation with WPlug --- flake.lock | 18 ++--- flake.nix | 1 + native_configs/neovim/init.lua | 126 +++++++++++++++++------------ nix-conf/home-manager/base/ssh.nix | 2 +- nix-conf/home-manager/flake.lock | 24 +++--- nix-conf/home-manager/flake.nix | 28 ++----- nix/cells/repo/home-modules.nix | 9 +++ 7 files changed, 110 insertions(+), 98 deletions(-) create mode 100644 nix/cells/repo/home-modules.nix diff --git a/flake.lock b/flake.lock index f175de8..d3ddfd1 100644 --- a/flake.lock +++ b/flake.lock @@ -301,11 +301,11 @@ "paisano": "paisano" }, "locked": { - "lastModified": 1682269418, - "narHash": "sha256-0fdUrQMkXMuK1/6D1Y+gbGXIWChiIRnlbYvo4dmNfVE=", + "lastModified": 1686502488, + "narHash": "sha256-sLSiDkU9oNpcl1QEge0xVviD7N87iVdrwl7l9i+6mxQ=", "owner": "divnix", "repo": "hive", - "rev": "669cdfcf61823d33f11a4fe5ee1f3c34903f4eaa", + "rev": "e8b46fa4d2917dfd456f3f040e9761262b4648d2", "type": "github" }, "original": { @@ -504,11 +504,11 @@ }, "nixpkgs_3": { "locked": { - "lastModified": 1686020360, - "narHash": "sha256-Wee7lIlZ6DIZHHLiNxU5KdYZQl0iprENXa/czzI6Cj4=", + "lastModified": 1686412476, + "narHash": "sha256-inl9SVk6o5h75XKC79qrDCAobTD1Jxh6kVYTZKHzewA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4729ffac6fd12e26e5a8de002781ffc49b0e94b7", + "rev": "21951114383770f96ae528d0ae68824557768e81", "type": "github" }, "original": { @@ -804,11 +804,11 @@ "yants": "yants_2" }, "locked": { - "lastModified": 1686006649, - "narHash": "sha256-6sdvFtQyx7SZoki1MlO2+3Xns4jmR34FEjlXawQdwhk=", + "lastModified": 1686337240, + "narHash": "sha256-JedAsyUIbSIhVrRWSl0R3lSWemVWsHg0w3MuzW7h4tg=", "owner": "divnix", "repo": "std", - "rev": "d6bcee9c35fb4a905b51c39e4d5ca842e9a421eb", + "rev": "1bd99cec90a5cee8575f45dbc193d6dd860a5f35", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 10f81b4..a20d8cf 100644 --- a/flake.nix +++ b/flake.nix @@ -37,5 +37,6 @@ devShells = std.harvest [ [ "dotfiles" "devshells" ] ]; # nixosConfigurations = std.pick [ [ "dotfiles" "nixos" ] ]; # homeConfigurations = std.pick [ [ "dotfiles" "home" ] ]; + homeModules = std.pick [["repo" "home-modules"]]; }; } diff --git a/native_configs/neovim/init.lua b/native_configs/neovim/init.lua index df1e4c8..ffab27e 100644 --- a/native_configs/neovim/init.lua +++ b/native_configs/neovim/init.lua @@ -8,6 +8,7 @@ -- - zk @ https://github.com/mickael-menu/zk -- - prettierd @ npm install -g @fsouza/prettierd +-- Auto-installs vim-plug vim.cmd([[ let data_dir = has('nvim') ? stdpath('data') . '/site' : '~/.vim' let plug_path = data_dir . '/autoload/plug.vim' @@ -20,83 +21,102 @@ endif -- vim-plug local Plug = vim.fn['plug#'] +-- prepare a list of installed plugins from rtp +local installed_plugins = {} +-- NOTE: nvim_list_runtime_paths will expand wildcard paths for us. +for _, path in ipairs(vim.api.nvim_list_runtime_paths()) do + local last_folder_start = path:find("/[^/]*$") + if last_folder_start then + local plugin_name = path:sub(last_folder_start + 1) + installed_plugins[plugin_name] = true + end +end + +-- Do Plug if plugin not yet linked in `rtp`. This takes care of Nix-compatibility +local function WPlug(plugin_path, ...) + local plugin_name = plugin_path:match("/([^/]+)$") + if not installed_plugins[plugin_name] then + Plug(plugin_path, ...) + end +end + vim.call('plug#begin') -- libs and dependencies -- Plug('nvim-lua/plenary.nvim') -- The base of all plugins -- plugins --- Plug('tjdevries/nlua.nvim') -- adds symbols of vim stuffs in init.lua --- Plug('nvim-treesitter/nvim-treesitter') -- language parser engine for highlighting --- Plug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects --- Plug('nvim-telescope/telescope.nvim', { branch = '0.1.x' }) -- file browser +WPlug('tjdevries/nlua.nvim') -- adds symbols of vim stuffs in init.lua +WPlug('nvim-treesitter/nvim-treesitter') -- language parser engine for highlighting +WPlug('nvim-treesitter/nvim-treesitter-textobjects') -- more text objects +WPlug('nvim-telescope/telescope.nvim', { branch = '0.1.x' }) -- file browser -- TODO: this might need to be taken extra care in our Nix config --- What this Plug declaration means is this repo needs to be built on our running environment +-- What this WPlug declaration means is this repo needs to be built on our running environment -- ----- -- What to do: -- - Run `make` at anytime before Nix is done on this repository -- - Might mean that we fetch this repository, run make, and copy to destination folder --- - Make sure that if we run `make` at first Plug run, that `make` is idempotent +-- - Make sure that if we run `make` at first WPlug run, that `make` is idempotent -- OR --- Make sure that Plug does not run `make` and use the output it needs --- Plug('nvim-telescope/telescope-fzf-native.nvim', --- { ['do'] = 'make >> /tmp/log 2>&1' }) --- Plug('nvim-telescope/telescope-file-browser.nvim') +-- Make sure that WPlug does not run `make` and use the output it needs +WPlug('nvim-telescope/telescope-fzf-native.nvim', + { ['do'] = 'make >> /tmp/log 2>&1' }) +WPlug('nvim-telescope/telescope-file-browser.nvim') -- cmp: auto-complete/suggestions --- Plug('neovim/nvim-lspconfig') -- built-in LSP configurations --- Plug('hrsh7th/cmp-nvim-lsp') --- Plug('hrsh7th/cmp-path') --- Plug('hrsh7th/cmp-buffer') --- Plug('hrsh7th/cmp-cmdline') --- Plug('hrsh7th/nvim-cmp') --- Plug('onsails/lspkind-nvim') -Plug('yioneko/nvim-yati', { tag = '*' }) -- copium: fix Python indent auto-correct from smart-indent -Plug('nathanalderson/yang.vim') --- Plug('tzachar/cmp-tabnine', { ['do'] = './install.sh' }) +WPlug('neovim/nvim-lspconfig') -- built-in LSP configurations +WPlug('hrsh7th/cmp-nvim-lsp') +WPlug('hrsh7th/cmp-path') +WPlug('hrsh7th/cmp-buffer') +WPlug('hrsh7th/cmp-cmdline') +WPlug('hrsh7th/nvim-cmp') +WPlug('onsails/lspkind-nvim') +WPlug('yioneko/nvim-yati', { tag = '*' }) -- copium: fix Python indent auto-correct from smart-indent +WPlug('nathanalderson/yang.vim') +-- WPlug('tzachar/cmp-tabnine', { ['do'] = './install.sh' }) -- DevExp --- Plug('windwp/nvim-autopairs') -- matches pairs like [] (),... --- Plug('windwp/nvim-ts-autotag') -- matches tags hello --- Plug('NMAC427/guess-indent.nvim') -- guesses the indentation of an opened buffer --- Plug('j-hui/fidget.nvim') -- Progress bar for LSP -Plug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines -Plug('lewis6991/gitsigns.nvim') -- add git info to sign columns -Plug('tpope/vim-fugitive') -- git commands in nvim -Plug('williamboman/mason.nvim') -- LSP, debuggers,... package manager -Plug('williamboman/mason-lspconfig.nvim') -- lsp config for mason --- Plug('ThePrimeagen/harpoon') -- 1-click through marked files per project -Plug('TimUntersberger/neogit') -- Easy-to-see git status -Plug('folke/trouble.nvim') -- File-grouped workspace diagnostics -Plug('tpope/vim-dispatch') -- Allows quick build/compile/test vim commands -Plug('clojure-vim/vim-jack-in') -- Clojure: ":Boot", ":Clj", ":Lein" -Plug('radenling/vim-dispatch-neovim') -- Add support for neovim's terminal emulator --- Plug('Olical/conjure') -- REPL on the source for Clojure (and other LISPs) -Plug('gennaro-tedesco/nvim-jqx') -- JSON formatter (use :Jqx*) -Plug('kylechui/nvim-surround') -- surrounds with tags/parenthesis -Plug('simrat39/rust-tools.nvim') -- config rust-analyzer and nvim integration +WPlug('windwp/nvim-autopairs') -- matches pairs like [] (),... +WPlug('windwp/nvim-ts-autotag') -- matches tags hello +WPlug('NMAC427/guess-indent.nvim') -- guesses the indentation of an opened buffer +WPlug('j-hui/fidget.nvim') -- Progress bar for LSP +WPlug('numToStr/Comment.nvim') -- "gc" to comment visual regions/lines +WPlug('lewis6991/gitsigns.nvim') -- add git info to sign columns +WPlug('tpope/vim-fugitive') -- git commands in nvim +WPlug('williamboman/mason.nvim') -- LSP, debuggers,... package manager +WPlug('williamboman/mason-lspconfig.nvim') -- lsp config for mason +WPlug('ThePrimeagen/harpoon') -- 1-click through marked files per project +WPlug('TimUntersberger/neogit') -- Easy-to-see git status +WPlug('folke/trouble.nvim') -- File-grouped workspace diagnostics +WPlug('tpope/vim-dispatch') -- Allows quick build/compile/test vim commands +WPlug('clojure-vim/vim-jack-in') -- Clojure: ":Boot", ":Clj", ":Lein" +WPlug('radenling/vim-dispatch-neovim') -- Add support for neovim's terminal emulator +-- WPlug('Olical/conjure') -- REPL on the source for Clojure (and other LISPs) +WPlug('gennaro-tedesco/nvim-jqx') -- JSON formatter (use :Jqx*) +WPlug('kylechui/nvim-surround') -- surrounds with tags/parenthesis +WPlug('simrat39/rust-tools.nvim') -- config rust-analyzer and nvim integration -- UI & colorscheme -Plug('simrat39/inlay-hints.nvim') -- type-hints with pseudo-virtual texts --- Plug('gruvbox-community/gruvbox') -- theme provider -Plug('nvim-lualine/lualine.nvim') -- fancy status line -Plug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines -Plug('kyazdani42/nvim-web-devicons') -- icons for folder and filetypes -Plug('m-demare/hlargs.nvim') -- highlights arguments; great for func prog -Plug('folke/todo-comments.nvim') -- Highlights TODO +WPlug('simrat39/inlay-hints.nvim') -- type-hints with pseudo-virtual texts +WPlug('gruvbox-community/gruvbox') -- theme provider +WPlug('nvim-lualine/lualine.nvim') -- fancy status line +WPlug('lukas-reineke/indent-blankline.nvim') -- identation lines on blank lines +WPlug('kyazdani42/nvim-web-devicons') -- icons for folder and filetypes +WPlug('m-demare/hlargs.nvim') -- highlights arguments; great for func prog +WPlug('folke/todo-comments.nvim') -- Highlights TODO -- other utilities -Plug('nvim-treesitter/nvim-treesitter-context') -- Top one-liner context of func/class scope -Plug('nvim-treesitter/playground') -- Sees Treesitter AST - less hair pulling, more PRs -Plug('saadparwaiz1/cmp_luasnip') -- snippet engine --- Plug('L3MON4D3/LuaSnip') -- snippet engine --- Plug('mickael-menu/zk-nvim') -- Zettelkasten +WPlug('nvim-treesitter/nvim-treesitter-context') -- Top one-liner context of func/class scope +WPlug('nvim-treesitter/playground') -- Sees Treesitter AST - less hair pulling, more PRs +WPlug('saadparwaiz1/cmp_luasnip') -- snippet engine +WPlug('L3MON4D3/LuaSnip') -- snippet engine +WPlug('mickael-menu/zk-nvim') -- Zettelkasten -- Switch cases: -- `gsp` -> PascalCase (classes), `gsc` -> camelCase (Java), `gs_` -> snake_case (C/C++/Rust) -- `gsu` -> UPPER_CASE (CONSTs), `gsk` -> kebab-case (Clojure), `gsK` -> Title-Kebab-Case -- `gs.` -> dot.case (R) -Plug('arthurxavierx/vim-caser') -- switch cases -Plug('~/local_repos/ts-ql') -- workspace code intelligence +WPlug('arthurxavierx/vim-caser') -- switch cases +WPlug('~/local_repos/ts-ql') -- workspace code intelligence --------- vim.call('plug#end') diff --git a/nix-conf/home-manager/base/ssh.nix b/nix-conf/home-manager/base/ssh.nix index dd02bdf..c95b3c0 100644 --- a/nix-conf/home-manager/base/ssh.nix +++ b/nix-conf/home-manager/base/ssh.nix @@ -17,7 +17,7 @@ in config.programs.ssh = { inherit (cfg) enable; forwardAgent = true; - extraConfig = builtins.readFile "${proj_root.config.path}/ssh/config"; + includes = ["${proj_root.config.path}/ssh/config"]; }; } diff --git a/nix-conf/home-manager/flake.lock b/nix-conf/home-manager/flake.lock index f66ecce..f5c7820 100644 --- a/nix-conf/home-manager/flake.lock +++ b/nix-conf/home-manager/flake.lock @@ -818,11 +818,11 @@ ] }, "locked": { - "lastModified": 1686142265, - "narHash": "sha256-IP0xPa0VYqxCzpqZsg3iYGXarUF+4r2zpkhwdHy9WsM=", + "lastModified": 1686391840, + "narHash": "sha256-5S0APl6Mfm6a37taHwvuf11UHnAX0+PnoWQbsYbMUnc=", "owner": "nix-community", "repo": "home-manager", - "rev": "39c7d0a97a77d3f31953941767a0822c94dc01f5", + "rev": "0144ac418ef633bfc9dbd89b8c199ad3a617c59f", "type": "github" }, "original": { @@ -953,11 +953,11 @@ "topiary": "topiary" }, "locked": { - "lastModified": 1686147433, - "narHash": "sha256-KqDqUGNfXcOwh6fkHMbH4a2W6k/W7S7wC/mxstlORwo=", + "lastModified": 1686315162, + "narHash": "sha256-KZZRTXSpxJDDGVbEdyTR/4Mu2COSMtrim+5iL7qwDTw=", "owner": "tweag", "repo": "nickel", - "rev": "dc6804acd123257460eef60d615da2eb0a8aca78", + "rev": "9fed1326c9306d7c339884584702ce570764beaf", "type": "github" }, "original": { @@ -1197,11 +1197,11 @@ }, "nixpkgs_12": { "locked": { - "lastModified": 1686020360, - "narHash": "sha256-Wee7lIlZ6DIZHHLiNxU5KdYZQl0iprENXa/czzI6Cj4=", + "lastModified": 1686412476, + "narHash": "sha256-inl9SVk6o5h75XKC79qrDCAobTD1Jxh6kVYTZKHzewA=", "owner": "nixos", "repo": "nixpkgs", - "rev": "4729ffac6fd12e26e5a8de002781ffc49b0e94b7", + "rev": "21951114383770f96ae528d0ae68824557768e81", "type": "github" }, "original": { @@ -1768,11 +1768,11 @@ "nixpkgs": "nixpkgs_13" }, "locked": { - "lastModified": 1686105195, - "narHash": "sha256-tBTKW+oqfT86Mvq/nm8Tkk3pzhJFXJWXJrj71cTF7lE=", + "lastModified": 1686537156, + "narHash": "sha256-mJD80brS6h6P4jzwdKID0S9RvfyiruxgJbXvPPIDqF0=", "owner": "oxalica", "repo": "rust-overlay", - "rev": "1279a72003f5e4b08c8eca1101d8f57452a539f9", + "rev": "e75da5cfc7da874401decaa88f4ccb3b4d64d20d", "type": "github" }, "original": { diff --git a/nix-conf/home-manager/flake.nix b/nix-conf/home-manager/flake.nix index 84c87ed..b4da2d7 100644 --- a/nix-conf/home-manager/flake.nix +++ b/nix-conf/home-manager/flake.nix @@ -80,11 +80,10 @@ nerd_font_module = { config, pkgs, ... }: { fonts.fontconfig.enable = true; home.packages = [ - (pkgs.nerdfonts.override { fonts = [ "DroidSansMono" ]; }) + # list of fonts are available at https://github.com/NixOS/nixpkgs/blob/nixos-unstable/pkgs/data/fonts/nerdfonts/shas.nix + (pkgs.nerdfonts.override { fonts = [ "Hack" ]; }) ]; - # For some reasons, Windows es in the font name as DroidSansMono NF - # so we need to override this - base.alacritty.font.family = "DroidSansMono Nerd Font"; + base.alacritty.font.family = "Hack Nerd Font Mono"; }; in { @@ -184,14 +183,14 @@ { base.private_chromium.enable = false; } + nerd_font_module { base.graphics.enable = false; # don't want to deal with GL stuffs on mac yet :/ base.graphics.useNixGL.defaultPackage = null; # FIXME: this actually does not exist - base.keepass.path = "/Users/htran/keepass.kdbx"; + # base.keepass.path = "/Users/htran/keepass.kdbx"; base.alacritty.font.size = 11.0; - base.alacritty.font.family = "DroidSansM Nerd Font"; base.git.name = "Hung"; base.git.email = "htran@egihosting.com"; } @@ -232,23 +231,6 @@ }; }; }; - # NOTE: This is never actually tested. This is for Ubuntu@Felia - # "ubuntu_admin" = home-manager.lib.homeManagerConfiguration { - # inherit pkgs; - # modules = [ - # ./home.nix - # ]; - # extraSpecialArgs = { - # myLib = lib; - # myHome = { - # username = "ubuntu_admin"; - # homeDirectory = "/home/ubuntu_admin"; - # shellInitExtra = '' - # '' + x11_wsl; - # }; - # }; - # }; - # Personal laptop hwtr = home-manager.lib.homeManagerConfiguration { inherit pkgs; diff --git a/nix/cells/repo/home-modules.nix b/nix/cells/repo/home-modules.nix new file mode 100644 index 0000000..73e8273 --- /dev/null +++ b/nix/cells/repo/home-modules.nix @@ -0,0 +1,9 @@ +{inputs, cell}: { + nerd_font_module = {config, pkgs, ...}: { + fonts.fontconfig.enable = true; + home.packages = [ + (pkgs.nerdfonts.override { fonts = [ "Hack" ]; }) + ]; + base.alacritty.font.family = "Hack Nerd Font Mono"; + }; +}