Skip to content

Commit

Permalink
docs: improve module reference rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
DavHau authored and mergify[bot] committed Oct 11, 2023
1 parent 585b98c commit af64cc5
Show file tree
Hide file tree
Showing 8 changed files with 99 additions and 64 deletions.
2 changes: 1 addition & 1 deletion modules/dream2nix/builtins-derivation/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
l = lib // builtins;
t = l.types;

common-options = import ../derivation-common/options.nix {inherit lib;};
common-options = import ./derivation-common/options.nix {inherit lib;};

builtin-derivation-options = {
# basic arguments
Expand Down
2 changes: 2 additions & 0 deletions modules/dream2nix/core/lock/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,8 @@
in {
imports = [
./interface.nix
../assertions.nix
../deps
];

config = {
Expand Down
4 changes: 4 additions & 0 deletions modules/dream2nix/mkDerivation/implementation.nix
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ in {
inherit (config.public) version;
pname = config.name;
};

config.deps = {nixpkgs, ...}: {
stdenv = lib.mkOverride 1050 nixpkgs.stdenv;
};
}
2 changes: 1 addition & 1 deletion modules/dream2nix/mkDerivation/interface.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
l = lib // builtins;
t = l.types;

common-options = import ../derivation-common/options.nix {inherit lib;};
common-options = import ../builtins-derivation/derivation-common/options.nix {inherit lib;};

derivationType = t.oneOf [t.str t.path t.package];

Expand Down
92 changes: 40 additions & 52 deletions modules/flake-parts/render/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,20 @@ in {
};

eval = evalWith {
modules = concatLists (mapAttrsToList (name: inputCfg: inputCfg.getModules inputCfg.flake) cfg.inputs);
modules = concatLists (mapAttrsToList (name: inputCfg: [inputCfg.module]) cfg.inputs);
};
evalWith = {modules}:
lib.evalModules {
modules = modules;
specialArgs.dream2nix.modules = self.modules;
specialArgs.packageSets = {};
modules =
modules
++ [
# {
# name = "dummy-name";
# version = "dummy-version";
# }
];
specialArgs.dream2nix = self;
specialArgs.packageSets.nixpkgs = pkgs;
};
# inputs.flake-parts.lib.evalFlakeModule
# {
Expand Down Expand Up @@ -123,44 +130,40 @@ in {
in [
{
url = baseUrl + subpath;
name = sourceName + subpath;
name = "dream2nix" + subpath;
}
]
else []
)
opt.declarations;
in
# if
# declarations
# == []
# || (
# # sourceName != "flake-parts" && coreOptDecls ? ${lib.showOption opt.loc}
# sourceName != "flake-parts"
# )
# then opt // {visible = false;}
# else opt // {inherit declarations;};
opt // {inherit declarations;};
if
declarations
== []
|| (
(lib.head opt.loc) != sourceName
)
then opt // {visible = false;}
else opt // {inherit declarations;};

inputModule = {
config,
name,
...
}: {
options = {
flake = mkOption {
module = mkOption {
type = types.raw;
description = ''
A flake.
A Module.
'';
default = inputs.${name};
};

sourcePath = mkOption {
type = types.path;
description = ''
Source path in which the modules are contained.
'';
default = config.flake.outPath;
};

title = mkOption {
Expand Down Expand Up @@ -224,29 +227,13 @@ in {
default = ''
## Installation
${
if config.installationDeclareInput
then ''
To use these options, add to your flake inputs:
```nix
${config.sourceName}.url = "${config.flakeRef}";
```
and inside the `mkFlake`:
''
else ''
To use these options, add inside the `mkFlake`:
''
}
To import this module into your dream2nix package:
```nix
imports = [
inputs.${config.sourceName}.${lib.concatMapStringsSep "." lib.strings.escapeNixIdentifier config.attributePath}
${lib.concatMapStringsSep "." lib.strings.escapeNixIdentifier config.attributePath}
];
```
Run `nix flake lock` and you're set.
'';
};

Expand All @@ -265,19 +252,6 @@ in {
'';
};

getModules = mkOption {
type = types.functionTo (types.listOf types.raw);
description = ''
Get the modules to render.
'';
default = flake: [
(
builtins.addErrorContext "while getting modules for input '${name}'"
(lib.getAttrFromPath config.attributePath flake)
)
];
};

attributePath = mkOption {
type = types.listOf types.str;
description = ''
Expand Down Expand Up @@ -325,7 +299,7 @@ in {
if config.separateEval
then
(evalWith {
modules = config.getModules config.flake;
modules = [config.module];
})
.options
else opts;
Expand All @@ -334,7 +308,7 @@ in {
inherit (config) sourceName baseUrl sourcePath;
# inherit coreOptDecls;
};
warningsAreErrors = true; # not sure if feasible long term
warningsAreErrors = false; # not sure if feasible long term
markdownByDefault = true;
};
rendered =
Expand Down Expand Up @@ -375,6 +349,20 @@ in {
})
cfg.inputs
// {
# generate markdown file like:
# Summary
# - [Reference Documentation]()
# - [core (built in)](./options/core.md)
generated-summary-md = pkgs.writeText "SUMMARY.md" ''
# Summary
- [Reference Documentation]()
${
lib.concatStringsSep "\n"
(lib.mapAttrsToList
(name: inputCfg: " - [${inputCfg.sourceName}](./options/${name}.md)")
cfg.inputs)
}
'';
generated-docs =
pkgs.runCommand "generated-docs"
{
Expand Down
6 changes: 4 additions & 2 deletions modules/flake-parts/site/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
pkgs.runCommand "linkcheck"
{
nativeBuildInputs = [pkgs.linkchecker pkgs.python3];
site = config.packages.default;
site = config.packages.website;
} ''
# https://linkchecker.github.io/linkchecker/man/linkcheckerrc.html
cat >>$TMPDIR/linkcheckrc <<EOF
Expand All @@ -52,6 +52,7 @@
runHook preBuild
cp ${self + /docs/theme/highlight.js} ./src/highlight.js
cp ${self'.packages.generated-summary-md} ./src/SUMMARY.md
mkdir -p ./theme
cp ${self + /modules/dream2nix/core/docs/theme/favicon.png} ./theme/favicon.png
Expand All @@ -77,7 +78,8 @@
cp -r $TMPDIR/out/html $out
cp _redirects $out
echo '<html><head><script>window.location.pathname = window.location.pathname.replace(/options.html$/, "") + "options/flake-parts.html"</script></head><body><a href="options/flake-parts.html">to the options</a></body></html>' \
# TODO: point to something else than public.html
echo '<html><head><script>window.location.pathname = window.location.pathname.replace(/options.html$/, "") + "options/public.html"</script></head><body><a href="options/public.html">to the options</a></body></html>' \
>$out/options.html
runHook postBuild
Expand Down
55 changes: 47 additions & 8 deletions modules/flake-parts/website.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,54 @@
pkgs,
...
}: {
render.inputs = {
core = {
title = "core";
flake.module = self.modules.dream2nix.core;
flake.outPath = self;
attributePath = ["module"];
render.inputs =
lib.flip lib.mapAttrs
(lib.filterAttrs (name: module:
lib.elem name [
# "buildPythonPackage"
# "buildRustPackage"
# "builtins-derivation"
# "core"
# "groups"
# "mkDerivation"
# "mkDerivation-sane-defaults"
# "nixpkgs-overrides"
# "nodejs-devshell"
# "nodejs-granular"
# "nodejs-granular-v3"
# "nodejs-node-modules"
# "nodejs-package-json"
# "nodejs-package-lock"
# "nodejs-package-lock-v3"
# "package-func"
# "php-composer-lock"
# "php-granular"
# "pip"
# "pip-hotfixes"
# "rust-cargo-lock"
# "rust-crane"
# "_template"
# "WIP-python-pdm"
# "WIP-python-pyproject"
# "WIP-spago"

# "lock"
"mkDerivation"
"public"
]) (self.modules.dream2nix))
(name: module: {
title = name;
module = self.modules.dream2nix.${name};
sourcePath = self;
attributePath = [
"dream2nix"
"modules"
"dream2nix"
(lib.strings.escapeNixIdentifier name)
];
intro = "intro";
baseUrl = "https://github.com/nix-community/dream2nix/blob/master";
};
};
separateEval = true;
});
};
}

0 comments on commit af64cc5

Please sign in to comment.