modules: fixups for documentation rendering

This commit is contained in:
DavHau 2023-10-11 22:38:53 +02:00 committed by mergify[bot]
parent dc43eeb495
commit 164b965b44
6 changed files with 66 additions and 64 deletions

View File

@ -32,7 +32,7 @@
in { in {
imports = [ imports = [
../core ../core
../package-func/implementation.nix ../package-func
]; ];
config.package-func.outputs = cfg.outputs; config.package-func.outputs = cfg.outputs;

View File

@ -42,7 +42,7 @@
in { in {
imports = [ imports = [
../core ../core
../package-func/implementation.nix ../package-func
]; ];
config.package-func.outputs = cfg.outputs; config.package-func.outputs = cfg.outputs;

View File

@ -1,6 +1,58 @@
# Module to provide an interface for integrating derivation builder functions
# like for example, mkDerivation, buildPythonPackage, etc...
{ {
config,
extendModules,
lib,
...
}: let
l = lib // builtins;
# outputs needed to assemble a package as proposed in
# https://github.com/NixOS/nix/issues/6507
outputs = l.unique config.package-func.outputs;
outputDrvs =
l.genAttrs outputs
(output: config.package-func.result.${output});
outputPaths = l.mapAttrs (_: drv: "${drv}") outputDrvs;
outputDrvsContexts =
l.mapAttrsToList (output: path: l.attrNames (l.getContext path)) outputPaths;
isSingleDrvPackage = (l.length (l.unique outputDrvsContexts)) == 1;
nonSingleDrvError = ''
The package ${config.name} consists of multiple outputs that are built by distinct derivations. It can't be understood as a single derivation.
This problem is causes by referencing the package directly. Instead, reference one of its output attributes:
- .${l.concatStringsSep "\n - ." outputs}
'';
throwIfMultiDrvOr = returnVal:
if isSingleDrvPackage
then returnVal
else throw nonSingleDrvError;
public =
# out, lib, bin, etc...
outputDrvs
# outputs, drvPath
// {
inherit outputs;
inherit config extendModules;
drvPath = throwIfMultiDrvOr outputDrvs.out.drvPath;
outPath = throwIfMultiDrvOr outputDrvs.out.outPath;
outputName = throwIfMultiDrvOr outputDrvs.out.outputName;
type = "derivation";
};
in {
imports = [ imports = [
./interface.nix ./interface.nix
./implementation.nix ../core/public
]; ];
# the final derivation
config.public = public;
config.package-func.result =
config.package-func.func config.package-func.args;
} }

View File

@ -1,59 +0,0 @@
# Module to provide an interface for integrating derivation builder functions
# like for example, mkDerivation, buildPythonPackage, etc...
{
config,
lib,
extendModules,
...
}: let
l = lib // builtins;
t = l.types;
# outputs needed to assemble a package as proposed in
# https://github.com/NixOS/nix/issues/6507
outputs = l.unique config.package-func.outputs;
outputDrvs =
l.genAttrs outputs
(output: config.package-func.result.${output});
outputPaths = l.mapAttrs (_: drv: "${drv}") outputDrvs;
outputDrvsContexts =
l.mapAttrsToList (output: path: l.attrNames (l.getContext path)) outputPaths;
isSingleDrvPackage = (l.length (l.unique outputDrvsContexts)) == 1;
nonSingleDrvError = ''
The package ${config.name} consists of multiple outputs that are built by distinct derivations. It can't be understood as a single derivation.
This problem is causes by referencing the package directly. Instead, reference one of its output attributes:
- .${l.concatStringsSep "\n - ." outputs}
'';
throwIfMultiDrvOr = returnVal:
if isSingleDrvPackage
then returnVal
else throw nonSingleDrvError;
public =
# out, lib, bin, etc...
outputDrvs
# outputs, drvPath
// {
inherit outputs;
inherit config extendModules;
drvPath = throwIfMultiDrvOr outputDrvs.out.drvPath;
outPath = throwIfMultiDrvOr outputDrvs.out.outPath;
outputName = throwIfMultiDrvOr outputDrvs.out.outputName;
type = "derivation";
};
in {
# add an option for each output, eg. out, bin, lib, etc...
options.public = l.genAttrs outputs (output:
l.mkOption {
type = t.path;
});
# the final derivation
config.public = public;
}

View File

@ -30,8 +30,17 @@ in {
The result of calling the final derivation function. The result of calling the final derivation function.
This is not necessarily the same as `final.package`. The function output might not be compatible to the interface of `final.package` and additional logic might be needed to create `final.package`. This is not necessarily the same as `final.package`. The function output might not be compatible to the interface of `final.package` and additional logic might be needed to create `final.package`.
''; '';
default = config.package-func.func config.package-func.args;
readOnly = true; readOnly = true;
}; };
# add an option for each output, eg. out, bin, lib, etc...
# TODO: these dynamic options cannot be rendered into a manual.
# -> removing them for now
# -> maybe refactor `public` to be a submodule which is dynamically created
# This would not improve the manual but allow for type checking
# options.public = l.genAttrs outputs (output:
# l.mkOption {
# type = t.path;
# });
}; };
} }

View File

@ -29,7 +29,7 @@
# "nodejs-package-json" # "nodejs-package-json"
# "nodejs-package-lock" # "nodejs-package-lock"
# "nodejs-package-lock-v3" # "nodejs-package-lock-v3"
# "package-func" "package-func"
"php-composer-lock" "php-composer-lock"
"php-granular" "php-granular"