From b9f6dfe8c5c8da09b6c2d8a8e168bdcf50a0aabd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vladim=C3=ADr=20=C4=8Cun=C3=A1t?= Date: Wed, 13 Jan 2016 11:49:19 +0100 Subject: [PATCH] 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. --- lib/attrsets.nix | 2 +- nixos/release.nix | 28 +++++++++++++++++++++++----- 2 files changed, 24 insertions(+), 6 deletions(-) diff --git a/lib/attrsets.nix b/lib/attrsets.nix index 84f6cb3658b..e3721bd1e94 100644 --- a/lib/attrsets.nix +++ b/lib/attrsets.nix @@ -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. diff --git a/nixos/release.nix b/nixos/release.nix index 8a502ae2baa..780ac56edf1 100644 --- a/nixos/release.nix +++ b/nixos/release.nix @@ -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);