git.iko.soy/typeable/nixpkgs
on master help sign in
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.

commite0feace5cde328a8f7478b2cf762991316d4c07c authorVladimír Čunát <vcunat@gmail.com> dateWed 3 Feb 2016, 13:19 (11 years ago) parent889351a
1 file changed+22−6
nixos/modules/services/misc/nixos-manual.nix+22−6
nixos/modules/services/misc/nixos-manual.nix+22−6
@@ -17,16 +17,32 @@ let
1717 nixpkgs.system = config.nixpkgs.system;
1818 };
1919
20− eval = evalModules {
21− modules = [ versionModule ] ++ baseModules;
22− args = (config._module.args) // { modules = [ ]; };
23− };
24−
20+ /* For the purpose of generating docs, evaluate options with each derivation
21+ in `pkgs` (recursively) replaced by a fake with path "\${pkgs.attribute.path}".
22+ It isn't perfect, but it seems to cover a vast majority of use cases.
23+ Caveat: even if the package is reached by a different means,
24+ the path above will be shown and not e.g. `${config.services.foo.package}`. */
2525 manual = import ../../../doc/manual {
2626 inherit pkgs;
2727 version = config.system.nixosVersion;
2828 revision = config.system.nixosRevision;
29− options = eval.options;
29+ options =
30+ let
31+ scrubbedEval = evalModules {
32+ modules = [ versionModule ] ++ baseModules;
33+ args = (config._module.args) // { modules = [ ]; };
34+ specialArgs = { pkgs = scrubDerivations "pkgs" pkgs; };
35+ };
36+ scrubDerivations = namePrefix: pkgSet: mapAttrs
37+ (name: value:
38+ let wholeName = "${namePrefix}.${name}"; in
39+ if isAttrs value then
40+ scrubDerivations wholeName value
41+ // (optionalAttrs (isDerivation value) { outPath = "\${${wholeName}}"; })
42+ else value
43+ )
44+ pkgSet;
45+ in scrubbedEval.options;
3046 };
3147
3248 entry = "${manual.manual}/share/doc/nixos/index.html";