diff --git a/flake.nix b/flake.nix index 31db939b..4b1aef0d 100644 --- a/flake.nix +++ b/flake.nix @@ -6,7 +6,6 @@ inputs.nmdSrc.url = "gitlab:rycee/nmd"; inputs.nmdSrc.flake = false; - # TODO: Use flake-utils to support all architectures outputs = { self, nixpkgs, nmdSrc, flake-utils, ... }@inputs: with nixpkgs.lib; with builtins; @@ -30,66 +29,25 @@ ./plugins/default.nix ]; - nixvimOption = pkgs: mkOption { - type = types.submodule ((modules pkgs) ++ [{ - options.enable = mkEnableOption "Enable nixvim"; - }]); - }; - helperOption = pkgs: mkOption { - type = mkOptionType { - name = "helpers"; - description = "Helpers that can be used when writing nixvim configs"; - check = builtins.isAttrs; - }; - description = "Use this option to access the helpers"; - default = import ./plugins/helpers.nix { inherit (pkgs) lib; }; - }; - - build = pkgs: - configuration: - let - eval = evalModules { - modules = modules pkgs ++ [{ config = configuration; }]; - }; - in - eval.config.output; - flakeOutput = flake-utils.lib.eachDefaultSystem - (system: rec { - packages.docs = import ./docs { + (system: + let pkgs = import nixpkgs { inherit system; }; - lib = nixpkgs.lib; - nixvimModules = nixvimModules; - inherit nmdSrc; - }; - }); + in + { + packages.docs = import ./docs { + pkgs = import nixpkgs { inherit system; }; + lib = nixpkgs.lib; + nixvimModules = nixvimModules; + inherit nmdSrc; + }; + + legacyPackages.makeNixvim = import ./wrappers/standalone.nix pkgs (modules pkgs); + }); in - flakeOutput // rec { - inherit build; - - nixosModules.nixvim = { pkgs, config, lib, ... }: { - options = { - programs.nixvim = nixvimOption pkgs; - nixvim.helpers = helperOption pkgs; - }; - config = mkIf config.programs.nixvim.enable { - environment.systemPackages = [ - config.programs.nixvim.output - ]; - }; - }; - - homeManagerModules.nixvim = { pkgs, config, lib, ... }: { - options = { - programs.nixvim = nixvimOption pkgs; - nixvim.helpers = helperOption pkgs; - }; - config = mkIf config.programs.nixvim.enable { - home.packages = [ - config.programs.nixvim.output - ]; - }; - }; + flakeOutput // { + nixosModules.nixvim = import ./wrappers/nixos.nix modules; + homeManagerModules.nixvim = import ./wrappers/hm.nix modules; }; } diff --git a/modules/output.nix b/modules/output.nix index 21e45657..3db8120f 100644 --- a/modules/output.nix +++ b/modules/output.nix @@ -65,9 +65,21 @@ in description = "Extra contents for init.vim"; }; - output = mkOption { + wrapRc = mkOption { + type = types.bool; + description = "Should the config be included in the wrapper script"; + default = false; + }; + + finalPackage = mkOption { type = types.package; - description = "Final package built by nixvim"; + description = "Wrapped neovim"; + readOnly = true; + }; + + initContent = mkOption { + type = types.str; + description = "The content of the init.vim file"; readOnly = true; visible = false; }; @@ -75,13 +87,18 @@ in config = let - customRC = config.extraConfigVim + (optionalString (config.extraConfigLua != "" || config.extraConfigLuaPre != "" || config.extraConfigLuaPost != "") '' - lua <m" = { - silent = true; - action = "make"; - }; # Same as nnoremap m make - }; - ''; - }; - }; - }; - - imports = [ - ./plugins - ]; - - config = - let - neovimConfig = pkgs.neovimUtils.makeNeovimConfig { - configure = cfg.configure; - plugins = cfg.extraPlugins; - }; - - extraWrapperArgs = optionalString (cfg.extraPackages != [ ]) - ''--prefix PATH : "${makeBinPath cfg.extraPackages}"''; - - package = if (cfg.package != null) then cfg.package else pkgs.neovim; - - wrappedNeovim = pkgs.wrapNeovimUnstable package (neovimConfig // { - wrapperArgs = lib.escapeShellArgs neovimConfig.wrapperArgs + " " - + extraWrapperArgs; - }); - - luaGlobals = optionalString (cfg.globals != { }) '' - -- Set up globals {{{ - local __nixvim_globals = ${helpers.toLuaObject cfg.globals} - - for k,v in pairs(__nixvim_globals) do - vim.g[k] = v - end - -- }}} - '' + optionalString (cfg.options != { }) '' - -- Set up options {{{ - local __nixvim_options = ${helpers.toLuaObject cfg.options} - - for k,v in pairs(__nixvim_options) do - vim.o[k] = v - end - -- }}} - '' + optionalString (mappings != [ ]) '' - -- Set up keybinds {{{ - local __nixvim_binds = ${helpers.toLuaObject mappings} - - for i, map in ipairs(__nixvim_binds) do - vim.api.nvim_set_keymap(map.mode, map.key, map.action, map.config) - end - -- }}} - ''; - - configure = { - # Make sure that globals are set before plugins are setup. - # This is becuase you might want to define variables or global functions - # that the plugin configuration depend upon. - customRC = cfg.extraConfigVim + '' - lua <