diff --git a/README.md b/README.md index 7df6a5d7..f1305bd8 100644 --- a/README.md +++ b/README.md @@ -75,6 +75,25 @@ You can now access the module using `inputs.nixvim.homeManagerModules.nixvim`, for a home-manager instalation, and `inputs.nixvim.nixosModules.nixvim`, if you're not using it. +## Usage +NixVim can be used in three ways: through the home-manager and NixOS modules, +and through the `build` function. To use the modules, just import the +`nixvim.homeManagerModules.${system}.nixvim` and +`nixvim.nixosModules.${system}.nixvim` modules, depending on which system +you're using. + +If you want to use it standalone, you can use the `build` function: + +```nix +{ pkgs, nixvim, ... }: { + environment.systemModules = [ + (nixvim.build pkgs { + colorschemes.gruvbox.enable = true; + }) + ]; +} +``` + ## How does it work? When you build the module (probably using home-manager), it will install all your plugins and generate a lua config for NeoVim with all the options diff --git a/docs/default.nix b/docs/default.nix index e37ec223..5601e5f6 100644 --- a/docs/default.nix +++ b/docs/default.nix @@ -1,14 +1,10 @@ -{ pkgs ? import {} +{ pkgs ? import { } , lib ? import -, ... }: +, nmdSrc +, nixvimModules ? [ ] +, ... +}: let - nmdSrc = pkgs.fetchFromGitLab { - name = "nmd"; - owner = "rycee"; - repo = "nmd"; - rev = "527245ff605bde88c2dd2ddae21c6479bb7cf8aa"; - sha256 = "1zi0f9y3wq4bpslx1py3sfgrgd9av41ahpandvs6rvkpisfsqqlp"; - }; nmd = import nmdSrc { inherit pkgs lib; }; scrubbedPkgsModule = { imports = [{ @@ -22,14 +18,13 @@ let nmd.buildModulesDocs ({ moduleRootPaths = [ ./.. ]; mkModuleUrl = path: - "https://github.com/pta2002/nixvim/blob/master/${path}#blob-path"; + "https://github.com/pta2002/nixvim/blob/main/${path}#blob-path"; channelName = "nixvim"; } // args); nixvimDocs = buildModulesDocs { modules = [ - (import ../nixvim.nix {}) scrubbedPkgsModule - ]; + ] ++ nixvimModules; docBook.id = "nixvim-options"; }; @@ -39,12 +34,15 @@ let documentsDirectory = ./.; documentType = "book"; chunkToc = '' - - - - - - + + + + + + ''; }; -in docs.html +in +# TODO: Parse this json or something, since docbook isn't working (and it's kind of terrible anyway) +nixvimDocs.json + diff --git a/flake.lock b/flake.lock index ef3662b4..fd46cbc6 100644 --- a/flake.lock +++ b/flake.lock @@ -1,29 +1,42 @@ { "nodes": { - "nixpkgs": { + "flake-utils": { "locked": { - "lastModified": 1641710811, - "narHash": "sha256-yVJ+CtwWZY8BnkNIJ/ue5a28yrRM6CkDF1LvmGmqqwM=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "0ecf7d414811f831060cf55707c374d54fbb1dec", + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", + "owner": "numtide", + "repo": "flake-utils", "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1661353537, + "narHash": "sha256-1E2IGPajOsrkR49mM5h55OtYnU0dGyre6gl60NXKITE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "0e304ff0d9db453a4b230e9386418fd974d5804a", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, "nmdSrc": { "flake": false, "locked": { - "lastModified": 1637239786, - "narHash": "sha256-l2KsnY537mz0blZdqALZKrWXn9PD39CpvotgPnxyIP4=", + "lastModified": 1654807200, + "narHash": "sha256-RNLq09vfj21TyYuUCeD6BNTNC6Ew8bLhQULZytN4Xx8=", "owner": "rycee", "repo": "nmd", - "rev": "527245ff605bde88c2dd2ddae21c6479bb7cf8aa", + "rev": "91dee681dd1c478d6040a00835d73c0f4a4c5c29", "type": "gitlab" }, "original": { @@ -34,6 +47,7 @@ }, "root": { "inputs": { + "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", "nmdSrc": "nmdSrc" } diff --git a/flake.nix b/flake.nix index 7cadbc9c..c95032cd 100644 --- a/flake.nix +++ b/flake.nix @@ -1,102 +1,83 @@ { description = "A neovim configuration system for NixOS"; - inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.nmdSrc.url = "gitlab:rycee/nmd"; inputs.nmdSrc.flake = false; - outputs = { self, nixpkgs, nmdSrc, ... }@inputs: rec { - packages."x86_64-linux".docs = import ./docs { - pkgs = import nixpkgs { system = "x86_64-linux"; }; - lib = nixpkgs.lib; - }; + # TODO: Use flake-utils to support all architectures + outputs = { self, nixpkgs, nmdSrc, flake-utils, ... }@inputs: + with nixpkgs.lib; + with builtins; + let + # TODO: Support nesting + nixvimModules = map (f: ./modules + "/${f}") (attrNames (builtins.readDir ./modules)); - nixosModules.nixvim = import ./nixvim.nix { nixos = true; }; - homeManagerModules.nixvim = import ./nixvim.nix { homeManager = true; }; - - # This is a simple container for testing - nixosConfigurations.container = nixpkgs.lib.nixosSystem { - system = "x86_64-linux"; - modules = [ - ({ pkgs, ... }: { - boot.isContainer = true; - system.configurationRevision = nixpkgs.lib.mkIf (self ? rev) self.rev; - - users.users.test = { - isNormalUser = true; - password = ""; - }; - - imports = [ nixosModules.nixvim ]; - - programs.nixvim = { - enable = true; - package = pkgs.neovim; - colorschemes.tokyonight = { enable = true; }; - - extraPlugins = [ pkgs.vimPlugins.vim-nix ]; - - options = { - number = true; - mouse = "a"; - tabstop = 2; - shiftwidth = 2; - expandtab = true; - smarttab = true; - autoindent = true; - cindent = true; - linebreak = true; - hidden = true; + modules = pkgs: nixvimModules ++ [ + (rec { + _file = ./flake.nix; + key = _file; + config = { + _module.args = { + pkgs = mkForce pkgs; + lib = pkgs.lib; + helpers = import ./plugins/helpers.nix { lib = pkgs.lib; }; }; - - maps.normalVisualOp."รง" = ":"; - maps.normal."m" = { - silent = true; - action = "make"; - }; - - plugins.lualine = { - enable = true; - }; - - plugins.undotree.enable = true; - plugins.gitgutter.enable = true; - plugins.fugitive.enable = true; - plugins.commentary.enable = true; - plugins.startify = { - enable = true; - useUnicode = true; - }; - plugins.goyo = { - enable = true; - showLineNumbers = true; - }; - - plugins.lsp = { - enable = true; - servers.clangd.enable = true; - }; - - plugins.telescope = { - enable = true; - extensions = { frecency.enable = true; }; - }; - - plugins.nvim-autopairs = { enable = true; }; - - globals = { - vimsyn_embed = "l"; - mapleader = " "; - }; - - plugins.lspsaga.enable = true; - - plugins.treesitter.enable = true; - plugins.ledger.enable = true; }; }) + + ./plugins/default.nix ]; + + nixvimOption = pkgs: mkOption { + type = types.submodule ((modules pkgs) ++ [{ + options.enable = mkEnableOption "Enable nixvim"; + }]); + }; + + build = pkgs: + configuration: + let + eval = evalModules { + modules = modules pkgs ++ [ configuration ]; + }; + in + eval.config.output; + + flakeOutput = + flake-utils.lib.eachDefaultSystem + (system: rec { + packages.docs = import ./docs { + pkgs = import nixpkgs { inherit system; }; + lib = nixpkgs.lib; + nixvimModules = nixvimModules; + inherit nmdSrc; + }; + + nixosModules.nixvim = { pkgs, config, lib, ... }: { + options.programs.nixvim = nixvimOption pkgs; + config = mkIf config.programs.nixvim.enable { + environment.systemPackages = [ + config.programs.nixvim.output + ]; + }; + }; + + homeManagerModules.nixvim = { pkgs, config, lib, ... }: { + options.programs.nixvim = nixvimOption pkgs; + config = mkIf config.programs.nixvim.enable { + home.packages = [ + config.programs.nixvim.output + ]; + }; + }; + }); + in + flakeOutput // { + inherit build; + # TODO: Stuff for home-manager and nixos modules backwards compat, keeping the architecture as x86_64 if none is specified... + homeManagerModules.nixvim = flakeOutput.homeManagerModules.x86_64-linux.nixvim; + nixosModules.nixvim = flakeOutput.nixosModules.x86_64-linux.nixvim; }; - }; } diff --git a/modules/colorscheme.nix b/modules/colorscheme.nix new file mode 100644 index 00000000..8036d2ab --- /dev/null +++ b/modules/colorscheme.nix @@ -0,0 +1,17 @@ +{ config, lib, ... }: +with lib; +{ + options = { + colorscheme = mkOption { + type = types.nullOr types.str; + description = "The name of the colorscheme to use"; + default = null; + }; + }; + + config = { + extraConfigVim = optionalString (config.colorscheme != "" && config.colorscheme != null) '' + colorscheme ${config.colorscheme} + ''; + }; +} diff --git a/modules/keymaps.nix b/modules/keymaps.nix new file mode 100644 index 00000000..b6426a9b --- /dev/null +++ b/modules/keymaps.nix @@ -0,0 +1,131 @@ +{ config, lib, helpers, ... }: +with lib; +let + mapOption = types.oneOf [ + types.str + (types.submodule { + options = { + silent = mkOption { + type = types.bool; + description = "Whether this mapping should be silent. Equivalent to adding to a map."; + default = false; + }; + + nowait = mkOption { + type = types.bool; + description = "Whether to wait for extra input on ambiguous mappings. Equivalent to adding to a map."; + default = false; + }; + + script = mkOption { + type = types.bool; + description = "Equivalent to adding