From de20ff2c5176bf4b27ab436c091983b4a34eb1a2 Mon Sep 17 00:00:00 2001 From: diniamo <55629891+diniamo@users.noreply.github.com> Date: Sun, 11 Aug 2024 21:10:55 +0000 Subject: [PATCH 1/2] style: improve modules/default.nix code, rename helper scripts (#351) Co-authored-by: raf --- docs/release-notes/rl-0.7.md | 6 +-- modules/default.nix | 84 +++++++++++++++--------------------- 2 files changed, 37 insertions(+), 53 deletions(-) diff --git a/docs/release-notes/rl-0.7.md b/docs/release-notes/rl-0.7.md index 21edbdd..0d607f9 100644 --- a/docs/release-notes/rl-0.7.md +++ b/docs/release-notes/rl-0.7.md @@ -143,10 +143,10 @@ configuration formats. - Add [neo-tree.nvim] as an alternative file-tree plugin. It will be available under `vim.filetree.neo-tree`, similar to nvimtree. -- Add `print-nvf-config` & `print-nvf-config-path` helper scripts to Neovim +- Add `nvf-print-config` & `nvf-print-config-path` helper scripts to Neovim closure. Both of those scripts have been automatically added to your PATH upon using neovimConfig or `programs.nvf.enable`. - - `print-nvf-config` will display your `init.lua`, in full. - - `print-nvf-config-path` will display the path to _a clone_ of your + - `nvf-print-config` will display your `init.lua`, in full. + - `nvf-print-config-path` will display the path to _a clone_ of your `init.lua`. This is not the path used by the Neovim wrapper, but an identical clone. diff --git a/modules/default.nix b/modules/default.nix index 227cf20..9cf9b70 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -7,11 +7,9 @@ inputs: { extraModules ? [], }: let inherit (pkgs) vimPlugins; - inherit (pkgs.vimUtils) buildVimPlugin; inherit (lib.strings) isString toString; inherit (lib.lists) filter map concatLists; - inherit (lib.attrsets) recursiveUpdate getAttr; - inherit (lib.asserts) assertMsg; + inherit (lib.attrsets) recursiveUpdate; # import modules.nix with `check`, `pkgs` and `lib` as arguments # check can be disabled while calling this file is called @@ -33,12 +31,21 @@ inputs: { # build a vim plugin with the given name and arguments # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # instead - buildPlug = {pname, ...} @ attrs: let - src = getAttr ("plugin-" + pname) inputs; + buildPlug = attrs: let + src = inputs."plugin-${attrs.pname}"; in pkgs.stdenvNoCC.mkDerivation ({ - inherit src; version = src.shortRev or src.shortDirtyRev or "dirty"; + + inherit src; + + nativeBuildInputs = with pkgs.vimUtils; [ + vimCommandCheckHook + vimGenDocHook + neovimRequireCheckHook + ]; + passthru.vimPlugin = true; + installPhase = '' runHook preInstall @@ -50,41 +57,27 @@ inputs: { } // attrs); - noBuildPlug = {pname, ...} @ attrs: let - input = getAttr ("plugin-" + pname) inputs; - in - { - version = input.shortRev or input.shortDirtyRev or "dirty"; - outPath = getAttr ("plugin-" + pname) inputs; - } - // attrs; - buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); + pluginBuilders = { + nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars; + flutter-tools-patched = + buildPlug + { + pname = "flutter-tools"; + patches = [../patches/flutter-tools.patch]; + }; + }; + buildConfigPlugins = plugins: map - (plug: ( - if (isString plug) - then - ( - if (plug == "nvim-treesitter") - then (buildTreesitterPlug vimOptions.treesitter.grammars) - else if (plug == "flutter-tools-patched") - then - ( - buildPlug - { - pname = "flutter-tools"; - patches = [../patches/flutter-tools.patch]; - } - ) - else noBuildPlug {pname = plug;} - ) - else plug - )) - (filter - (f: f != null) - plugins); + ( + plug: + if (isString plug) + then pluginBuilders.${plug} or (buildPlug {pname = plug;}) + else plug + ) + (filter (f: f != null) plugins); # built (or "normalized") plugins that are modified builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; @@ -114,20 +107,11 @@ inputs: { inherit extraLuaPackages extraPython3Packages; }; + dummyInit = pkgs.writeText "nvf-init.lua" vimOptions.builtLuaConfigRC; # Additional helper scripts for printing and displaying nvf configuration # in your commandline. - printConfig = pkgs.writers.writeDashBin "print-nvf-config" '' - cat << EOF - ${vimOptions.builtLuaConfigRC} - EOF - ''; - - printConfigPath = pkgs.writers.writeDashBin "print-nvf-config-path" '' - realpath ${pkgs.writeTextFile { - name = "nvf-init.lua"; - text = vimOptions.builtLuaConfigRC; - }} - ''; + printConfig = pkgs.writers.writeDashBin "nvf-print-config" "cat ${dummyInit}"; + printConfigPath = pkgs.writers.writeDashBin "nvf-print-config-path" "echo -n ${dummyInit}"; in { inherit (module) options config; inherit (module._module.args) pkgs; @@ -137,7 +121,7 @@ in { neovim = pkgs.symlinkJoin { name = "nvf-with-helpers"; paths = [neovim-wrapped printConfig printConfigPath]; - postBuild = "echo helpers added"; + postBuild = "echo Helpers added"; meta = { description = "Wrapped version of Neovim with additional helper scripts"; From 7d824d6711bba12c399cd0d254b89a6984396ba1 Mon Sep 17 00:00:00 2001 From: Gerg-L <88247690+Gerg-L@users.noreply.github.com> Date: Mon, 12 Aug 2024 00:08:53 +0000 Subject: [PATCH 2/2] modules: fix build (#353) * flake.lock: lock * remove ussage of mapAttrsFlatten * flake.lock: update mnw * modules/default.nix makeNeovimConfig -> mnw * modules/default.nix use buildVimPlugin (sad) dont build when possible --- flake.lock | 23 +++++++++++-- modules/default.nix | 62 ++++++++++++++--------------------- modules/wrapper/rc/config.nix | 5 ++- 3 files changed, 47 insertions(+), 43 deletions(-) diff --git a/flake.lock b/flake.lock index de29be3..1851eb7 100644 --- a/flake.lock +++ b/flake.lock @@ -69,11 +69,11 @@ }, "mnw": { "locked": { - "lastModified": 1722191188, - "narHash": "sha256-YF//iMALbrd2Ni9aju7w8NniH16Qz6RFTRD6md5UkDc=", + "lastModified": 1723419050, + "narHash": "sha256-Eb8jBUgHwpte+bGsqeXNbKMBfZaDB7RiPQwyb1vzJK8=", "owner": "Gerg-L", "repo": "mnw", - "rev": "c7b289f3f5a31b6e744be37d83fc231816621231", + "rev": "e625f5965567f16102bc52897c7600dcde53c6c3", "type": "github" }, "original": { @@ -939,6 +939,22 @@ "type": "github" } }, + "plugin-new-file-template-nvim": { + "flake": false, + "locked": { + "lastModified": 1721518222, + "narHash": "sha256-g0IjJrHRXw7U9goVLzVYUyHBSsDZGHMpi3YZPhg64zA=", + "owner": "otavioschwanck", + "repo": "new-file-template.nvim", + "rev": "6ac66669dbf2dc5cdee184a4fe76d22465ca67e8", + "type": "github" + }, + "original": { + "owner": "otavioschwanck", + "repo": "new-file-template.nvim", + "type": "github" + } + }, "plugin-noice-nvim": { "flake": false, "locked": { @@ -1862,6 +1878,7 @@ "plugin-neo-tree-nvim": "plugin-neo-tree-nvim", "plugin-neocord": "plugin-neocord", "plugin-neodev-nvim": "plugin-neodev-nvim", + "plugin-new-file-template-nvim": "plugin-new-file-template-nvim", "plugin-noice-nvim": "plugin-noice-nvim", "plugin-none-ls": "plugin-none-ls", "plugin-nui-nvim": "plugin-nui-nvim", diff --git a/modules/default.nix b/modules/default.nix index 9cf9b70..1ae3b03 100644 --- a/modules/default.nix +++ b/modules/default.nix @@ -9,75 +9,63 @@ inputs: { inherit (pkgs) vimPlugins; inherit (lib.strings) isString toString; inherit (lib.lists) filter map concatLists; - inherit (lib.attrsets) recursiveUpdate; # import modules.nix with `check`, `pkgs` and `lib` as arguments # check can be disabled while calling this file is called # to avoid checking in all modules - nvimModules = import ./modules.nix { - inherit pkgs check lib; - }; + nvimModules = import ./modules.nix {inherit pkgs check lib;}; # evaluate the extended library with the modules # optionally with any additional modules passed by the user module = lib.evalModules { - specialArgs = recursiveUpdate {modulesPath = toString ./.;} extraSpecialArgs; + specialArgs = extraSpecialArgs // {modulesPath = toString ./.;}; modules = concatLists [[configuration] nvimModules extraModules]; }; # alias to the internal configuration vimOptions = module.config.vim; + noBuildPlug = {pname, ...} @ attrs: let + src = inputs."plugin-${attrs.pname}"; + in + { + version = src.shortRev or src.shortDirtyRev or "dirty"; + outPath = src; + passthru.vimPlugin = false; + } + // attrs; + # build a vim plugin with the given name and arguments # if the plugin is nvim-treesitter, warn the user to use buildTreesitterPlug # instead buildPlug = attrs: let src = inputs."plugin-${attrs.pname}"; in - pkgs.stdenvNoCC.mkDerivation ({ + pkgs.vimUtils.buildVimPlugin ( + { version = src.shortRev or src.shortDirtyRev or "dirty"; - inherit src; - - nativeBuildInputs = with pkgs.vimUtils; [ - vimCommandCheckHook - vimGenDocHook - neovimRequireCheckHook - ]; - passthru.vimPlugin = true; - - installPhase = '' - runHook preInstall - - mkdir -p $out - cp -r . $out - - runHook postInstall - ''; } - // attrs); + // attrs + ); buildTreesitterPlug = grammars: vimPlugins.nvim-treesitter.withPlugins (_: grammars); pluginBuilders = { nvim-treesitter = buildTreesitterPlug vimOptions.treesitter.grammars; - flutter-tools-patched = - buildPlug - { - pname = "flutter-tools"; - patches = [../patches/flutter-tools.patch]; - }; + flutter-tools-patched = buildPlug { + pname = "flutter-tools"; + patches = [../patches/flutter-tools.patch]; + }; }; buildConfigPlugins = plugins: - map - ( + map ( plug: if (isString plug) - then pluginBuilders.${plug} or (buildPlug {pname = plug;}) + then pluginBuilders.${plug} or (noBuildPlug {pname = plug;}) else plug - ) - (filter (f: f != null) plugins); + ) (filter (f: f != null) plugins); # built (or "normalized") plugins that are modified builtStartPlugins = buildConfigPlugins vimOptions.startPlugins; @@ -87,7 +75,7 @@ inputs: { }) (buildConfigPlugins vimOptions.optPlugins); # additional Lua and Python3 packages, mapped to their respective functions - # to conform to the format makeNeovimConfig expects. end user should + # to conform to the format mnw expects. end user should # only ever need to pass a list of packages, which are modified # here extraLuaPackages = ps: map (x: ps.${x}) vimOptions.luaPackages; @@ -97,7 +85,7 @@ inputs: { # generate a wrapped Neovim package. neovim-wrapped = inputs.mnw.lib.wrap pkgs { neovim = vimOptions.package; - plugins = concatLists [builtStartPlugins builtOptPlugins]; + plugins = builtStartPlugins ++ builtOptPlugins; appName = "nvf"; extraBinPath = vimOptions.extraPackages; initLua = vimOptions.builtLuaConfigRC; diff --git a/modules/wrapper/rc/config.nix b/modules/wrapper/rc/config.nix index be299f3..78edb59 100644 --- a/modules/wrapper/rc/config.nix +++ b/modules/wrapper/rc/config.nix @@ -5,9 +5,8 @@ }: let inherit (builtins) map mapAttrs filter; inherit (lib.options) mkOption; - inherit (lib.attrsets) filterAttrs getAttrs attrValues attrNames; + inherit (lib.attrsets) mapAttrsToList filterAttrs getAttrs attrValues attrNames; inherit (lib.strings) concatLines concatMapStringsSep; - inherit (lib.misc) mapAttrsFlatten; inherit (lib.trivial) showWarnings; inherit (lib.types) str nullOr; inherit (lib.generators) mkLuaInline; @@ -83,7 +82,7 @@ in { config = let filterNonNull = attrs: filterAttrs (_: value: value != null) attrs; globalsScript = - mapAttrsFlatten (name: value: "vim.g.${name} = ${toLuaObject value}") + mapAttrsToList (name: value: "vim.g.${name} = ${toLuaObject value}") (filterNonNull cfg.globals); extraPluginConfigs = resolveDag {