1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-07 14:21:48 +02:00

Format .nix files

This does not include any automation for the release branch, but
is based on the configuration of https://github.com/NixOS/nix/pull/12349

    pre-commit run -a nixfmt-rfc-style
This commit is contained in:
Robert Hensing 2025-01-24 20:40:21 +01:00
parent 6cb17fd836
commit 32aed360b8
266 changed files with 7443 additions and 5118 deletions

View file

@ -1,3 +1,4 @@
/** A doc comment for a file that only contains a function */
{ ... }:
{ }
/**
A doc comment for a file that only contains a function
*/
{ ... }: { }

View file

@ -6,55 +6,106 @@
multiply 2 3
=> 6
```
*/
*/
multiply = x: y: x * y;
/**👈 precisely this wide 👉*/
/**
👈 precisely this wide 👉
*/
measurement = x: x;
floatedIn = /** This also works. */
floatedIn =
/**
This also works.
*/
x: y: x;
compact=/**boom*/x: x;
# https://github.com/NixOS/rfcs/blob/master/rfcs/0145-doc-strings.md#ambiguous-placement
/** Ignore!!! */
unambiguous =
/** Very close */
compact =
/**
boom
*/
x: x;
/** Firmly rigid. */
# https://github.com/NixOS/rfcs/blob/master/rfcs/0145-doc-strings.md#ambiguous-placement
/**
Ignore!!!
*/
unambiguous =
/**
Very close
*/
x: x;
/**
Firmly rigid.
*/
constant = true;
/** Immovably fixed. */
/**
Immovably fixed.
*/
lib.version = "9000";
/** Unchangeably constant. */
/**
Unchangeably constant.
*/
lib.attr.empty = { };
lib.attr.undocumented = { };
nonStrict = /** My syntax is not strict, but I'm strict anyway. */ x: x;
strict = /** I don't have to be strict, but I am anyway. */ { ... }: null;
nonStrict =
/**
My syntax is not strict, but I'm strict anyway.
*/
x: x;
strict =
/**
I don't have to be strict, but I am anyway.
*/
{ ... }: null;
# Note that pre and post are the same here. I just had to name them somehow.
strictPre = /** Here's one way to do this */ a@{ ... }: a;
strictPost = /** Here's another way to do this */ { ... }@a: a;
strictPre =
/**
Here's one way to do this
*/
a@{ ... }: a;
strictPost =
/**
Here's another way to do this
*/
{ ... }@a: a;
# TODO
/** You won't see this. */
/**
You won't see this.
*/
curriedArgs =
/** A documented function. */
/**
A documented function.
*/
x:
/** The function returned by applying once */
/**
The function returned by applying once
*/
y:
/** A function body performing summation of two items */
/**
A function body performing summation of two items
*/
x + y;
/** Documented formals (but you won't see this comment) */
/**
Documented formals (but you won't see this comment)
*/
documentedFormals =
/** Finds x */
{ /** The x attribute */
x
}: x;
/**
Finds x
*/
{
/**
The x attribute
*/
x,
}:
x;
}

View file

@ -25,14 +25,14 @@ rec {
makeOverridable = f: {
/**
This is a function that can be overridden.
*/
*/
__functor = self: f;
override = throw "not implemented";
};
/**
Compute x^2
*/
*/
square = x: x * x;
helper = makeOverridable square;
@ -41,8 +41,14 @@ rec {
makeVeryOverridable = f: {
/**
This is a function that can be overridden.
*/
__functor = self: arg: f arg // { override = throw "not implemented"; overrideAttrs = throw "not implemented"; };
*/
__functor =
self: arg:
f arg
// {
override = throw "not implemented";
overrideAttrs = throw "not implemented";
};
override = throw "not implemented";
};
@ -64,7 +70,6 @@ rec {
*/
helper3 = makeVeryOverridable (x: x * x * x);
# ------
# getDoc traverses a potentially infinite structure in case of __functor, so
@ -73,7 +78,7 @@ rec {
recursive = {
/**
This looks bad, but the docs are ok because of the eta expansion.
*/
*/
__functor = self: x: self x;
};
@ -81,21 +86,23 @@ rec {
/**
Docs probably won't work in this case, because the "partial" application
of self results in an infinite recursion.
*/
*/
__functor = self: self.__functor self;
};
diverging = let
/**
Docs probably won't work in this case, because the "partial" application
of self results in an diverging computation that causes a stack overflow.
It's not an infinite recursion because each call is different.
This must be handled by the documentation retrieval logic, as it
reimplements the __functor invocation to be partial.
*/
f = x: {
__functor = self: (f (x + 1));
};
in f null;
diverging =
let
/**
Docs probably won't work in this case, because the "partial" application
of self results in an diverging computation that causes a stack overflow.
It's not an infinite recursion because each call is different.
This must be handled by the documentation retrieval logic, as it
reimplements the __functor invocation to be partial.
*/
f = x: {
__functor = self: (f (x + 1));
};
in
f null;
}