diff options
author | Vladimír Čunát <vcunat@gmail.com> | 2016-02-03 13:19:48 +0100 |
---|---|---|
committer | Vladimír Čunát <vcunat@gmail.com> | 2016-02-03 14:47:14 +0100 |
commit | e0feace5cde328a8f7478b2cf762991316d4c07c (patch) | |
tree | 6b848b6ff2203d2b2ec337169192b1ffee401e9e /nixos/modules/services/misc/nixos-manual.nix | |
parent | 889351af8b8a9e8bb39dbd09dc56691a28b9d823 (diff) | |
download | nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar.gz nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar.bz2 nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar.lz nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar.xz nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.tar.zst nixlib-e0feace5cde328a8f7478b2cf762991316d4c07c.zip |
nixos docs: allow displaying package references
This is an improved version of original #12357. For the purpose of generating docs, evaluate options with each derivation in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". It isn't perfect, but it seems to cover a vast majority of use cases. Caveat: even if the package is reached by a different means, the path above will be shown and not e.g. `${config.services.foo.package}`. As before, defaults created by `mkDefault` aren't displayed, but documentation shouldn't (mostly) be a reason to use that anymore. Note: t wouldn't be enough to just use `lib.mapAttrsRecursive`, because derivations are also (special) attribute sets.
Diffstat (limited to 'nixos/modules/services/misc/nixos-manual.nix')
-rw-r--r-- | nixos/modules/services/misc/nixos-manual.nix | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/nixos/modules/services/misc/nixos-manual.nix b/nixos/modules/services/misc/nixos-manual.nix index 3e1f53e79f3e..8ef1b035ca6f 100644 --- a/nixos/modules/services/misc/nixos-manual.nix +++ b/nixos/modules/services/misc/nixos-manual.nix @@ -17,16 +17,32 @@ let nixpkgs.system = config.nixpkgs.system; }; - eval = evalModules { - modules = [ versionModule ] ++ baseModules; - args = (config._module.args) // { modules = [ ]; }; - }; - + /* For the purpose of generating docs, evaluate options with each derivation + in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}". + It isn't perfect, but it seems to cover a vast majority of use cases. + Caveat: even if the package is reached by a different means, + the path above will be shown and not e.g. `${config.services.foo.package}`. */ manual = import ../../../doc/manual { inherit pkgs; version = config.system.nixosVersion; revision = config.system.nixosRevision; - options = eval.options; + options = + let + scrubbedEval = evalModules { + modules = [ versionModule ] ++ baseModules; + args = (config._module.args) // { modules = [ ]; }; + specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; }; + }; + scrubDerivations = namePrefix: pkgSet: mapAttrs + (name: value: + let wholeName = "${namePrefix}.${name}"; in + if isAttrs value then + scrubDerivations wholeName value + // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; }) + else value + ) + pkgSet; + in scrubbedEval.options; }; entry = "${manual.manual}/share/doc/nixos/index.html"; |