From 2695bef0799d609349afa2451e31b0f666f3c04a Mon Sep 17 00:00:00 2001 From: Matt Sturgeon Date: Fri, 21 Nov 2025 12:23:42 +0000 Subject: [PATCH] lib/modules: init `buildNixvim` and `buildNixvimWith` Introduce thin wrappers around the `.config.build.package`, option intended to replace the legacy `makeNixvim` and `makeNixvimWithModule` functions. --- lib/modules.nix | 41 +++++++++++++++++++++++++++++++++++++++++ tests/lib-tests.nix | 5 +++++ 2 files changed, 46 insertions(+) diff --git a/lib/modules.nix b/lib/modules.nix index 74021171..09d12f7e 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -57,6 +57,47 @@ in } // extraSpecialArgs; }; + + /** + Build a Nixvim package. + + # Inputs + + `input` + : One of: + 1. A Nixvim module or a list of modules. + 2. A Nixvim configuration. + 3. A Nixvim package. + + # Output + + An installable Nixvim package. + */ + buildNixvim = + input: + if lib.isDerivation input then + lib.throwIfNot (input ? config.build.package) + "buildNixvim: received a derivation without the expected `config` attribute." + input.config.build.package + else if lib.isType "configuration" input then + lib.throwIfNot (input ? config.build.package) + "buildNixvim: received a configuration without the expected `build.package` option." + input.config.build.package + else + self.modules.buildNixvimWith { + modules = lib.toList input; + }; + + /** + Build a Nixvim package using the same interface as `evalNixvim`. + + # Output + + An installable Nixvim package. + */ + buildNixvimWith = lib.mirrorFunctionArgs self.modules.evalNixvim ( + args: (self.modules.evalNixvim args).config.build.package + ); } // lib.mapAttrs ( name: msg: diff --git a/tests/lib-tests.nix b/tests/lib-tests.nix index 694e2f5a..bbce4eaf 100644 --- a/tests/lib-tests.nix +++ b/tests/lib-tests.nix @@ -546,6 +546,11 @@ let "Nixvim (single-element): Trailing whitespaces" ]; }; + + buildNixvimWith_hasExpectedArgs = { + expr = lib.functionArgs lib.nixvim.modules.buildNixvimWith; + expected = lib.functionArgs lib.nixvim.modules.evalNixvim; + }; }; in if results == [ ] then