nixos manuals: allow displaying package references

The manuals are now evaluated with each derivation in `pkgs` (recursively)
replaced by a fake with path "\${pkgs.path.to.the.attribute}".
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.
This commit is contained in:
Vladimír Čunát 2016-01-13 11:49:19 +01:00
parent 7dba3bafba
commit b9f6dfe8c5
2 changed files with 24 additions and 6 deletions

View file

@ -207,7 +207,7 @@ rec {
/* Like `mapAttrsRecursive', but it takes an additional predicate
function that tells it whether to recursive into an attribute
function that tells it whether to recurse into an attribute
set. If it returns false, `mapAttrsRecursiveCond' does not
recurse, but does apply the map function. It is returns true, it
does recurse, and does not apply the map function.

View file

@ -92,15 +92,33 @@ let
}).config));
cleanConfig = import ./lib/eval-config.nix {
system = "x86_64-linux";
modules = [ ];
pkgs = with pkgs.lib;
let
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 scrubDerivations "pkgs" pkgs;
};
docs = (import ./doc/manual) {
inherit pkgs version;
revision = versionModule.system.nixosRevision;
inherit (cleanConfig) options;
};
in rec {
channel = import lib/make-channel.nix { inherit pkgs nixpkgs version versionSuffix; };
manual = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manual);
manualPDF = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manualPDF)).x86_64-linux;
manpages = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.manpages);
options = (buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.manual.optionsJSON)).x86_64-linux;
inherit (docs) manual manualPDF manpages optionsJSON;
# Build the initial ramdisk so Hydra can keep track of its size over time.
initialRamdisk = buildFromConfig ({ pkgs, ... }: { }) (config: config.system.build.initialRamdisk);