diff --git a/README.md b/README.md index 44238b4..acd3eb3 100644 --- a/README.md +++ b/README.md @@ -38,6 +38,7 @@ customize to your liking both by removing and adding tools that you prefer. * `win32yank` is used to ensure perfect bi-directional copying and pasting to and from Windows GUI applications and LunarVim running in WSL * The default shell is `zsh` +* Native `docker` (ie. Linux, not Windows) is enabled by default * The prompt is [Starship](https://starship.rs/) * [`fzf`](https://github.com/junegunn/fzf), [`lsd`](https://github.com/lsd-rs/lsd), @@ -45,7 +46,7 @@ customize to your liking both by removing and adding tools that you prefer. [`broot`](https://github.com/Canop/broot) are integrated into `zsh` by default * These can all be disabled easily by setting `enable = false` in - [home.nix](home.nix) or just removing the lines all together + [home.nix](home.nix), or just removing the lines all together * [`direnv`](https://github.com/direnv/direnv) is integrated into `zsh` by default * `git` config is generated in [home.nix](home.nix) with options provided to @@ -60,7 +61,7 @@ customize to your liking both by removing and adding tools that you prefer. installer](https://github.com/nix-community/NixOS-WSL) * Install it (tweak the command to your desired paths): ```powershell -wsl --import NixOS .\NixOS\ .\nixos-wsl-installer.tar.gz --version 2 +wsl --import NixOS .\NixOS\ .\nixos-wsl.tar.gz --version 2 ``` @@ -69,44 +70,51 @@ wsl --import NixOS .\NixOS\ .\nixos-wsl-installer.tar.gz --version 2 wsl -d NixOs ``` -* Get a copy of this repo: +* Set up a channel: ```bash -cd ~ -nix-shell -p busybox -curl -L https://github.com/LGUG2Z/nixos-wsl-starter/archive/refs/heads/master.zip | unzip - -mv nixos-wsl-starter-master configuration +sudo nix-channel --add https://nixos.org/channels/nixos-23.05 nixos +sudo nix-channel --update ``` -* Change the username to your desired username in `flake.nix` +* Get a copy of this repo (you'll probably want to fork it eventually): +```bash +nix-shell -p git neovim +git clone https://github.com/LGUG2Z/nixos-wsl-starter.git /tmp/configuration +cd /tmp/configuration +``` + +* Change the username to your desired username in `flake.nix` with `nvim` (or whichever editor you prefer) * Apply the configuration ```bash -sudo nixos-rebuild switch --flake ~/configuration +sudo nixos-rebuild switch --flake /tmp/configuration +``` + +* Restart and reconnect to the current WSL shell +```bash +wsl -t NixOS +wsl -d NixOS ``` -* Disconnect from your current WSL shell and then reconnect again with `wsl -d - NixOS` * `cd ~` and then `pwd` should now show `/home/` -* Do this bit again because the temporary initial home directory was blown away - when we applied our configuration +* Move the configuration to your new home directory ```bash -cd ~ -nix-shell -p busybox -curl -L https://github.com/LGUG2Z/nixos-wsl-starter/archive/refs/heads/master.zip | unzip - -mv nixos-wsl-starter-master configuration +mv /tmp/configuration ~/configuration ``` + * Install LunarVim (select "no" for all dependency prompts) ```bash LV_BRANCH='release-1.3/neovim-0.9' bash <(curl -s https://raw.githubusercontent.com/LunarVim/LunarVim/release-1.3/neovim-0.9/utils/installer/install.sh) ``` -* Change the username to your desired username in `flake.nix` one last time +* Run `lvim` once and let it the long first-time setup run to completion +* You can now set `sessionVariables.EDITOR = "lvim";` in [home.nix](home.nix) * Go through all the `FIXME:` notices in `~/configuration` and make changes wherever you want * Apply the configuration ```bash -sudo nixos-rebuild switch --flake ~/configuration +sudo nixos-rebuild switch --flake ~/configuration ``` -Note: If you will be developing in Rust, you'll still be managing your toolchains and components like `rust-analyzer` with `rustup`! +Note: If developing in Rust, you'll still be managing your toolchains and components like `rust-analyzer` with `rustup`! ## Project Layout diff --git a/flake.lock b/flake.lock index 2192bf7..cbc2427 100644 --- a/flake.lock +++ b/flake.lock @@ -79,14 +79,16 @@ "inputs": { "flake-compat": "flake-compat", "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": [ + "nixpkgs" + ] }, "locked": { - "lastModified": 1696022753, - "narHash": "sha256-4qoyorpwqQqbtxWFBOjWqfmDl6Ds8B8wjKAxizn+ovY=", + "lastModified": 1696053802, + "narHash": "sha256-8TTbJbtGDz1MstExrVQe56eXZpovvZv6G6L6q/4NOKg=", "owner": "nix-community", "repo": "NixOS-WSL", - "rev": "8735bdfa5fdfa6e90d944ff9f5f806668b53eacb", + "rev": "cadde47d123d1a534c272b04a7582f1d11474c48", "type": "github" }, "original": { @@ -99,13 +101,13 @@ "locked": { "lastModified": 1695825837, "narHash": "sha256-4Ne11kNRnQsmSJCRSSNkFRSnHC4Y5gPDBIQGjjPfJiU=", - "owner": "NixOS", + "owner": "nixos", "repo": "nixpkgs", "rev": "5cfafa12d57374f48bcc36fda3274ada276cf69e", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", "ref": "nixos-23.05", "repo": "nixpkgs", "type": "github" @@ -127,29 +129,13 @@ "type": "github" } }, - "nixpkgs_2": { - "locked": { - "lastModified": 1695825837, - "narHash": "sha256-4Ne11kNRnQsmSJCRSSNkFRSnHC4Y5gPDBIQGjjPfJiU=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "5cfafa12d57374f48bcc36fda3274ada276cf69e", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "nixos-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, "nur": { "locked": { - "lastModified": 1696023918, - "narHash": "sha256-nE9Zv3POG3oqZPtAmojBC3Ji+0fzZ8AR7MVHSYJFMxk=", + "lastModified": 1696089289, + "narHash": "sha256-NT4yGSZWj6z6mPb8Ik0HPJHYmm+46H9HvjLdBGOOOqo=", "owner": "nix-community", "repo": "NUR", - "rev": "f0fb9ad92aa3d00c59423e82681c9ffa5734abd9", + "rev": "9098ede076f5cf5a00e611778710e24f3c8db308", "type": "github" }, "original": { @@ -163,7 +149,7 @@ "home-manager": "home-manager", "nix-index-database": "nix-index-database", "nixos-wsl": "nixos-wsl", - "nixpkgs": "nixpkgs_2", + "nixpkgs": "nixpkgs", "nixpkgs-unstable": "nixpkgs-unstable", "nur": "nur" } diff --git a/flake.nix b/flake.nix index b30a98f..078cb19 100644 --- a/flake.nix +++ b/flake.nix @@ -10,6 +10,7 @@ inputs.nur.url = "github:nix-community/NUR"; inputs.nixos-wsl.url = "github:nix-community/NixOS-WSL"; + inputs.nixos-wsl.inputs.nixpkgs.follows = "nixpkgs"; inputs.nix-index-database.url = "github:Mic92/nix-index-database"; inputs.nix-index-database.inputs.nixpkgs.follows = "nixpkgs"; @@ -76,7 +77,7 @@ nixosConfigurations.nixos = mkNixosConfiguration { hostname = "nixos"; - username = "example-user"; # FIXME: replace with your own username! + username = "nixos"; # FIXME: replace with your own username! modules = [ nixos-wsl.nixosModules.wsl ./wsl.nix diff --git a/home.nix b/home.nix index 31d9cd3..0e9fc1d 100644 --- a/home.nix +++ b/home.nix @@ -1,5 +1,5 @@ { - # FIXME: uncomment this if you want to reference your GitHub/GitLab access tokens and other secrets + # FIXME: uncomment the next line if you want to reference your GitHub/GitLab access tokens and other secrets # secrets, config, pkgs, @@ -104,9 +104,18 @@ in { sessionVariables.SHELL = "/etc/profiles/per-user/${username}/bin/zsh"; }; - home.packages = stable-packages ++ unstable-packages; + home.packages = + stable-packages + ++ unstable-packages + ++ + # FIXME: you can add anything else that doesn't fit into the above two lists in here + [ + # pkgs.some-package + # pkgs.unstable.some-other-package + ]; - home.file.".config/lvim/config.lua".source = ./lvim_config.lua; + # FIXME: if you want to version your LunarVim config, add it to the root of this repo and uncomment the next line + # home.file.".config/lvim/config.lua".source = ./lvim_config.lua; programs = { home-manager.enable = true; @@ -156,7 +165,7 @@ in { userEmail = ""; # FIXME: set your git email userName = ""; #FIXME: set your git username extraConfig = { - # FIXME: uncomment this if you want to be able to clone private https repos + # FIXME: uncomment the next lines if you want to be able to clone private https repos # url = { # "https://oauth2:${secrets.github_token}@github.com" = { # insteadOf = "https://github.com"; diff --git a/lvim_config.lua b/lvim_config.lua deleted file mode 100644 index 2f96a22..0000000 --- a/lvim_config.lua +++ /dev/null @@ -1,296 +0,0 @@ --- https://github.com/LunarVim/LunarVim/issues/2986 -vim.opt.title = false - -vim.opt.timeoutlen = 200 -vim.opt.relativenumber = true -vim.opt.wrap = true -vim.opt.spell = false -vim.opt.spelllang = "en" - -lvim.log.level = "warn" -lvim.format_on_save.enabled = true - -local function close_floating() - for _, win in ipairs(vim.api.nvim_list_wins()) do - local config = vim.api.nvim_win_get_config(win) - if config.relative ~= "" then - vim.api.nvim_win_close(win, false) - end - end -end - --- keymappings [view all the defaults by pressing Lk] -lvim.leader = "space" - -lvim.lsp.buffer_mappings.normal_mode["K"] = nil -vim.diagnostic.config({ - virtual_text = false -}) - -lvim.keys.normal_mode[""] = close_floating - -lvim.keys.normal_mode["o"] = "o" -lvim.keys.normal_mode["O"] = "O" -lvim.keys.normal_mode[""] = ":bnext" -lvim.keys.visual_mode["p"] = "\"_dP" -lvim.keys.normal_mode["|"] = ":vsplit" -lvim.keys.normal_mode["-"] = ":split" - -lvim.keys.visual_mode[",s"] = ":sort" -lvim.keys.normal_mode[",s"] = ":SymbolsOutline" -lvim.keys.normal_mode[",d"] = ":Bdelete" - -lvim.lsp.buffer_mappings.normal_mode[",b"] = { vim.lsp.buf.hover, "Show hover" } -lvim.lsp.buffer_mappings.normal_mode[",B"] = { vim.lsp.buf.declaration, "Goto declaration" } -lvim.lsp.buffer_mappings.normal_mode[",r"] = { vim.lsp.buf.declaration, "Goto references" } -lvim.lsp.buffer_mappings.normal_mode[",,"] = { vim.lsp.buf.rename, "Rename" } -lvim.lsp.buffer_mappings.normal_mode[",w"] = { ':lua vim.diagnostic.goto_prev({float = false})', - "Goto next diagnostic" } -lvim.lsp.buffer_mappings.normal_mode[",w"] = { ':lua vim.diagnostic.goto_next({float = false})', - "Goto prev diagnostic" } - --- Change Telescope navigation to use j and k for navigation and n and p for history in both input and normal mode. --- we use protected-mode (pcall) just in case the plugin wasn't loaded yet. -local _, actions = pcall(require, "telescope.actions") -lvim.builtin.telescope.defaults.mappings = { - -- for input mode - i = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - [""] = actions.cycle_history_next, - [""] = actions.cycle_history_prev, - }, - -- for normal mode - n = { - [""] = actions.move_selection_next, - [""] = actions.move_selection_previous, - }, -} - -lvim.builtin.terminal.open_mapping = [[]] -lvim.builtin.terminal.shell = "zsh" --- To get into normal mode from the terminal to copy and paste -vim.keymap.set('t', "", "") - --- Use which-key to add extra bindings with the leader-key prefix -lvim.builtin.which_key.mappings["P"] = { "Telescope projects", "Projects" } - --- TODO: User Config for predefined plugins --- After changing plugin config exit and reopen LunarVim, Run :PackerInstall :PackerCompile -lvim.builtin.alpha.active = true -lvim.builtin.alpha.mode = "dashboard" -lvim.builtin.terminal.active = true -lvim.builtin.nvimtree.setup.view.side = "left" -lvim.builtin.nvimtree.setup.renderer.icons.show.git = true -lvim.builtin.cmp.formatting.max_width = 30 -lvim.builtin.cmp.sources = { - { name = "nvim_lsp" }, - { name = "path" }, - { name = "crates" }, - { name = "treesitter" }, - { name = "nvim_lua" }, - { name = "calc" }, -} - -lvim.builtin.treesitter.auto_install = true; --- if you don't want all the parsers change this to a table of the ones you want -lvim.builtin.treesitter.ensure_installed = { - "bash", - "comment", - "c", - "cpp", - "dockerfile", - "dot", - "css", - "go", - "gomod", - "hcl", - "hjson", - "html", - "http", - "javascript", - "jsdoc", - "json", - "json5", - "lua", - "make", - "markdown", - "nix", - "python", - "regex", - "rust", - "scss", - "toml", - "tsx", - "typescript", - "vim", - "yaml", -} --- ---@usage disable automatic installation of servers -lvim.lsp.installer.setup.automatic_installation = false - -lvim.builtin.treesitter.highlight.enable = true - --- -- nil is better than rnix for .nix files but needs to be manually configured -vim.list_extend(lvim.lsp.automatic_configuration.skipped_servers, { "nil_ls" }) -require("lvim.lsp.manager").setup("nil_ls", {}) - - -local formatters = require "lvim.lsp.null-ls.formatters" -formatters.setup { - { - command = "alejandra", - filetypes = { "nix" } - }, -} - -local linters = require "lvim.lsp.null-ls.linters" -linters.setup { - { command = "statix", filetypes = { "nix" } }, - { command = "deadnix", filetypes = { "nix" } }, -} - -vim.api.nvim_create_augroup("LspAttach_inlayhints", {}) -vim.api.nvim_create_autocmd("LspAttach", { - group = "LspAttach_inlayhints", - callback = function(args) - if not (args.data and args.data.client_id) then - return - end - - local bufnr = args.buf - local client = vim.lsp.get_client_by_id(args.data.client_id) - require("lsp-inlayhints").on_attach(client, bufnr) - end, -}) - -lvim.plugins = { - { "tpope/vim-surround" }, - - { "tpope/vim-repeat" }, - - { 'famiu/bufdelete.nvim' }, - - { 'NoahTheDuke/vim-just' }, - - { - "romgrk/nvim-treesitter-context", - config = function() - require("treesitter-context").setup { - enable = true, -- Enable this plugin (Can be enabled/disabled later via commands) - throttle = true, -- Throttles plugin updates (may improve performance) - max_lines = 0, -- How many lines the window should span. Values <= 0 mean no limit. - patterns = { - -- Match patterns for TS nodes. These get wrapped to match at word boundaries. - -- For all filetypes - -- Note that setting an entry here replaces all other patterns for this entry. - -- By setting the 'default' entry below, you can control which nodes you want to - -- appear in the context window. - default = { - 'class', - 'function', - 'method', - }, - }, - } - end - }, - - { - "ray-x/lsp_signature.nvim", - event = "BufRead", - config = function() require "lsp_signature".on_attach() end, - }, - - { - "ruifm/gitlinker.nvim", - event = "BufRead", - config = function() - require("gitlinker").setup { - opts = { - add_current_line_on_normal_mode = true, - action_callback = require("gitlinker.actions").open_in_browser, - print_true, - mappings = "gy", - }, - } - end, - }, - - { - "saecki/crates.nvim", - event = { "BufRead Cargo.toml" }, - config = function() require('crates').setup() end, - }, - - { - "ethanholz/nvim-lastplace", - event = "BufRead", - config = function() - require("nvim-lastplace").setup({ - lastplace_ignore_buftype = { "quickfix", "nofile", "help" }, - lastplace_ignore_filetype = { - "gitcommit", "gitrebase", "svn", "hgcommit", - }, - lastplace_open_folds = true, - }) - end, - }, - - { - "folke/todo-comments.nvim", - event = "BufRead", - config = function() - require("todo-comments").setup() - end, - }, - - { - "itchyny/vim-cursorword", - event = { "BufEnter", "BufNewFile" }, - config = function() - vim.api.nvim_command("augroup user_plugin_cursorword") - vim.api.nvim_command("autocmd!") - vim.api.nvim_command("autocmd FileType NvimTree,lspsagafinder,dashboard,vista let b:cursorword = 0") - vim.api.nvim_command("autocmd WinEnter * if &diff || &pvw | let b:cursorword = 0 | endif") - vim.api.nvim_command("autocmd InsertEnter * let b:cursorword = 0") - vim.api.nvim_command("autocmd InsertLeave * let b:cursorword = 1") - vim.api.nvim_command("augroup END") - end - }, - - { - "simrat39/symbols-outline.nvim", - config = function() - require('symbols-outline').setup() - end - }, - - { - "windwp/nvim-ts-autotag", - config = function() - require("nvim-ts-autotag").setup() - end, - }, - - { - url = "https://git.sr.ht/~whynothugo/lsp_lines.nvim", - config = function() - require("lsp_lines").setup() - end, - }, - - { - "lvimuser/lsp-inlayhints.nvim", - config = function() - require("lsp-inlayhints").setup({ - inlayHints = { - typeHints = { - prefix = "=> " - }, - } - }) - end, - }, - -} diff --git a/wsl.nix b/wsl.nix index 8f73dbf..0a3882c 100644 --- a/wsl.nix +++ b/wsl.nix @@ -1,5 +1,5 @@ { - # FIXME: uncomment this if you want to reference your GitHub/GitLab access tokens and other secrets + # FIXME: uncomment the next line if you want to reference your GitHub/GitLab access tokens and other secrets # secrets, username, hostname, @@ -17,7 +17,7 @@ security.sudo.wheelNeedsPassword = false; - # FIXME: uncomment this to enable SSH + # FIXME: uncomment the next line to enable SSH # services.openssh.enable = true; users.users.${username} = { @@ -26,7 +26,7 @@ shell = pkgs.zsh; extraGroups = [ "wheel" - # FIXME: uncomment if you want to run docker without sudo + # FIXME: uncomment the next line if you want to run docker without sudo # "docker" ]; # FIXME: add your own hashed password