docs: use lib.extend instead of patching nixpkgs

This speeds up evaluation and removes IFD. Additionally, this makes it
easier to maintain these library changes, as we don't have to maintain
static patches.

Signed-off-by: Sefa Eyeoglu <contact@scrumplex.net>
This commit is contained in:
Sefa Eyeoglu 2024-06-05 21:59:34 +02:00 committed by Matt Sturgeon
parent 04671a049a
commit aa4afbeac2
No known key found for this signature in database
GPG key ID: 4F91844CED1A8299
3 changed files with 36 additions and 63 deletions

View file

@ -4,19 +4,37 @@
pkgs, pkgs,
}: }:
let let
pkgsDoc = # Extend nixpkg's lib, so that we can handle recursive leaf types such as `either`
import lib = pkgs.lib.extend (
(pkgs.applyPatches { final: prev: {
name = "nixpkgs-nixvim-doc"; types = prev.types // {
src = pkgs.path; either =
patches = [ ./either_recursive.patch ]; t1: t2:
}) (prev.types.either t1 t2)
{ // {
inherit (pkgs) system; getSubOptions = prefix: (t1.getSubOptions prefix) // (t2.getSubOptions prefix);
config.allowUnfree = true; };
};
inherit (pkgsDoc) lib; eitherRecursive = t1: t2: (final.types.either t1 t2) // { getSubOptions = _: { }; };
oneOfRecursive =
ts:
let
head' =
if ts == [ ] then
throw "types.oneOfRecursive needs to get at least one type in its argument"
else
builtins.head ts;
tail' = builtins.tail ts;
in
builtins.foldl' final.types.eitherRecursive head' tail';
};
}
);
pkgsDoc = pkgs // {
inherit lib;
};
nixvimPath = toString ./..; nixvimPath = toString ./..;

View file

@ -1,49 +0,0 @@
commit e067eb1f6da7994150f10854e5fd635ca8bd0e92
Author: traxys <quentin+dev@familleboyer.net>
Date: Sun Jan 14 17:54:55 2024 +0100
lib.types: Include the suboptions of both types for either
This allows to correctly gather the sub options for types of the form
`either <type> (submodule {...})`.
This requires adding two new types: `eitherRecursive` and
`oneOfRecursive` that avoid infinite recursions for types like
configuration types that are often of the form `oneOf [atom (listOf
configType)]`
diff --git a/lib/types.nix b/lib/types.nix
index cea63c598321..d26982db6cc0 100644
--- a/lib/types.nix
+++ b/lib/types.nix
@@ -906,10 +906,16 @@ rec {
then functor.type mt1 mt2
else null;
functor = (defaultFunctor name) // { wrapped = [ t1 t2 ]; };
+ getSubOptions = prefix: (t1.getSubOptions prefix) // (t2.getSubOptions prefix);
nestedTypes.left = t1;
nestedTypes.right = t2;
};
+ # Handle recursive leaf types, avoiding an infinite recursion
+ eitherRecursive = t1: t2: (either t1 t2) // {
+ getSubOptions = _: {};
+ };
+
# Any of the types in the given list
oneOf = ts:
let
@@ -917,6 +923,13 @@ rec {
tail' = tail ts;
in foldl' either head' tail';
+ # Handle recursive leaf types, avoiding an infinite recursion
+ oneOfRecursive = ts:
+ let
+ head' = if ts == [] then throw "types.oneOfRecursive needs to get at least one type in its argument" else head ts;
+ tail' = tail ts;
+ in foldl' eitherRecursive head' tail';
+
# Either value of type `coercedType` or `finalType`, the former is
# converted to `finalType` using `coerceFunc`.
coercedTo = coercedType: coerceFunc: finalType:

View file

@ -1,14 +1,18 @@
{ {
perSystem = perSystem =
{ {
pkgs, pkgsUnfree,
config, config,
rawModules, rawModules,
helpers, helpers,
... ...
}: }:
{ {
packages = import ../docs { inherit rawModules pkgs helpers; }; packages = import ../docs {
inherit rawModules helpers;
# Building the docs evaluates each plugin's default package, some of which are unfree
pkgs = pkgsUnfree;
};
# Test that all packages build fine when running `nix flake check`. # Test that all packages build fine when running `nix flake check`.
checks = config.packages; checks = config.packages;