diff --git a/lib/modules.nix b/lib/modules.nix index 74021171b9..95cf5f8218 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -57,6 +57,88 @@ 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 + ); + + /** + Build a Nixvim test derivation. + + # Inputs + + `input` + : One of: + 1. A Nixvim module or a list of modules. + 2. A Nixvim configuration. + 3. A Nixvim package. + + # Output + + A buildable Nixvim test. + */ + testNixvim = + input: + if lib.isDerivation input then + lib.throwIfNot (input ? config.build.test) + "testNixvim: received a derivation without the expected `config` attribute." + input.config.build.test + else if lib.isType "configuration" input then + lib.throwIfNot (input ? config.build.test) + "testNixvim: received a configuration without the expected `build.test` option." + input.config.build.test + else + self.modules.testNixvimWith { + modules = lib.toList input; + }; + + /** + Build a Nixvim test derivation using the same interface as `evalNixvim`. + + # Output + + A buildable Nixvim test. + */ + testNixvimWith = lib.mirrorFunctionArgs self.modules.evalNixvim ( + args: (self.modules.evalNixvim args).config.build.test + ); } // lib.mapAttrs ( name: msg: diff --git a/modules/top-level/output.nix b/modules/top-level/output.nix index e41be4161d..df59014983 100644 --- a/modules/top-level/output.nix +++ b/modules/top-level/output.nix @@ -1,6 +1,7 @@ { pkgs, config, + options, lib, ... }: @@ -319,6 +320,9 @@ in printInitPackage ]; meta.mainProgram = "nvim"; + passthru = { + inherit config options; + }; }; printInitPackage = pkgs.writeShellApplication { diff --git a/tests/lib-tests.nix b/tests/lib-tests.nix index 694e2f5af2..f273463468 100644 --- a/tests/lib-tests.nix +++ b/tests/lib-tests.nix @@ -546,6 +546,16 @@ let "Nixvim (single-element): Trailing whitespaces" ]; }; + + buildNixvimWith_hasExpectedArgs = { + expr = lib.functionArgs lib.nixvim.modules.buildNixvimWith; + expected = lib.functionArgs lib.nixvim.modules.evalNixvim; + }; + + testNixvimWith_hasExpectedArgs = { + expr = lib.functionArgs lib.nixvim.modules.testNixvimWith; + expected = lib.functionArgs lib.nixvim.modules.evalNixvim; + }; }; in if results == [ ] then