lib: add nixdoc docstrings

This commit is contained in:
Gabriel Arazas 2025-01-13 09:33:30 +08:00
parent f48ff49635
commit fc4866826c
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360
4 changed files with 215 additions and 7 deletions

View File

@ -1,11 +1,85 @@
rec {
/*
/**
Given the attrset for evaluating a wrapper-manager module, return a
derivation containing the wrapper.
# Arguments
It has the same arguments as
[`wrapperManagerLib.env.eval`](#function-library-wrapperManagerLib.env.eval).
# Type
```
build :: Attr -> Derivation
```
# Example
```
build {
pkgs = import <nixpkgs> { };
modules = [
./wrapper-manager-config.nix
./modules/wrapper-manager
];
}
=>
<drv>
```
*/
build = args: (eval args).config.build.toplevel;
# Evaluate a wrapper-manager configuration.
/**
Evaluate a wrapper-manager configuration.
# Arguments
Its argument only expects a sole attribute set with the following
attributes:
pkgs
: A nixpkgs instance.
lib
: The nixpkgs library subset. Defaults to `pkgs.lib` from the given nixpkgs
instance.
modules
: A list of additional wrapper-manager modules to be imported (typically
the wrapper-manager configuration and additional modules) for the final
configuration.
specialArgs
: An additional set of module arguments that can be used in `imports`.
# Type
```
eval :: Attr -> Attr
```
# Example
```
eval {
pkgs = import <nixpkgs> { };
modules = [
./wrapper-manager-config.nix
./modules/wrapper-manager
];
}
=>
{
_module = { ... };
_type = "configuration";
class = null;
config = { ... };
options = { ... };
extendModules = <func>;
}
```
*/
eval =
{
pkgs,

View File

@ -11,10 +11,55 @@
}:
rec {
/*
/**
Make a wrapper-manager wrapper config containing a sub-wrapper that wraps
another program. Several examples of this includes sudo, Bubblewrap, and
Gamescope.
# Arguments
Its arguments is a sole attribute set with the following expected
attributes:
arg0
: Similar to `wrappers.<name>.arg0` from wrapper-manager module, it is a
store path containing an executable used as the main program of the wrapper.
under
: Similar to `arg0` but for the wraparound (e.g., sudo, doas, Bubblewrap).
underFlags
: Arguments of the wraparound. Defaults to an empty list.
underSeparator
: An optional string acting as the separator between the wraparound's
arguments and the arg0's arguments.
Note that the argument attrset can contain any attribute. The attrset is
then separated as a module and an additional module using the above
attributes.
# Type
```
makeWraparound :: Attr -> Module
```
# Example
```
makeWraparound {
arg0 = lib.getExe' pkgs.hello "hello";
appendArgs = [ "--traditional" ];
under = lib.getExe' pkgs.sudo "sudo";
underFlags = [ "-u" "admin" ];
}
=>
{
_type = "merge";
contents = [ ... ];
}
```
*/
makeWraparound =
{

View File

@ -5,27 +5,115 @@
}:
rec {
/*
/**
Given a list of derivations, return a list of the store path with the `bin`
output (or at least with "/bin" in each of the paths).
# Arguments
drvs
: A list of derivations.
# Type
```
getBin :: [ Derivation ] -> [ Path ]
```
# Examples
```
getBin (with pkgs; [ hello coreutils ])
=>
[
"/nix/store/HASH-hello/bin"
"/nix/store/HASH-coreutils/bin"
]
```
*/
getBin = drvs: builtins.map (v: lib.getBin v) drvs;
/*
/**
Given a list of derivations, return a list of the store paths with the
`libexec` appended.
# Arguments
drvs
: A list of derivations.
# Type
```
getLibexec :: [ Derivation ] -> [ Path ]
```
# Examples
```
getLibexec (with pkgs; [ hello coreutils ])
=>
[
"/nix/store/HASH-hello/libexec"
"/nix/store/HASH-coreutils/libexec"
]
```
*/
getLibexec = drvs: builtins.map (v: "${v}/libexec") drvs;
/*
/**
Given a list of derivations, return a list of the store paths appended with
`/etc/xdg` suitable as part of the XDG_CONFIG_DIRS environment variable.
# Arguments
drvs
: A list of derivations.
# Type
```
getXdgConfigDirs :: [ Derivation ] -> [ Path ]
```
# Examples
```
getXdgConfigDirs (with pkgs; [ hello coreutils ])
=>
[
"/nix/store/HASH-hello/etc/xdg"
"/nix/store/HASH-coreutils/etc/xdg"
]
```
*/
getXdgConfigDirs = drvs: builtins.map (v: "${v}/etc/xdg") drvs;
/*
/**
Given a list of derivations, return a list of store paths appended with
`/share` suitable as part of the XDG_DATA_DIRS environment variable.
# Arguments
drvs
: A list of derivations.
# Type
```
getXdgDataDirs :: [ Derivation ] -> [ Path ]
```
# Examples
```
getXdgDataDirs (with pkgs; [ hello coreutils ])
=>
[
"/nix/store/HASH-hello/share"
"/nix/store/HASH-coreutils/share"
]
```
*/
getXdgDataDirs = drvs: builtins.map (v: "${v}/share") drvs;
}

View File

@ -16,6 +16,7 @@ pkgs.mkShell {
npins
treefmt
nixfmt-rfc-style
nixdoc
# For easy validation of the test suite.
yajsv