mirror of
https://github.com/nix-community/nixvim.git
synced 2025-06-22 08:53:28 +02:00
docs: Use a nixpkgs patch instead of copy/pasting nixpkgs functions (#1011)
This makes the code more maintainable, as it only depends on our small patch, instead of a large number of internals of nixpkgs.
This commit is contained in:
parent
2294a12b0b
commit
507ff5b142
7 changed files with 97 additions and 251 deletions
49
docs/either_recursive.patch
Normal file
49
docs/either_recursive.patch
Normal file
|
@ -0,0 +1,49 @@
|
|||
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:
|
Loading…
Add table
Add a link
Reference in a new issue