From 9ec34da2ee947930621f68b1856a636b46391ed4 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Wed, 12 May 2010 11:07:49 +0000 Subject: [PATCH] * In the generation of the `options.xml' file used to produce the NixOS manual and manpages, remove all derivation attributes except the `name' attribute. This cuts the size of `options.xml' from 7.0 MiB to 473 KiB, and more importantly, cuts evaluation time of the system derivation from 1.63s to 1.10s on my laptop (a 32% improvement). svn path=/nixpkgs/trunk/; revision=21739 --- pkgs/lib/options.nix | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/pkgs/lib/options.nix b/pkgs/lib/options.nix index d975f904085f..38dfb106ff5c 100644 --- a/pkgs/lib/options.nix +++ b/pkgs/lib/options.nix @@ -262,8 +262,8 @@ rec { declarations = map (x: toString x.source) opt.declarations; definitions = map (x: toString x.source) opt.definitions; } - // optionalAttrs (opt ? example) { example = opt.example; } - // optionalAttrs (opt ? default) { default = opt.default; }; + // optionalAttrs (opt ? example) { example = scrubOptionValue opt.example; } + // optionalAttrs (opt ? default) { default = scrubOptionValue opt.default; }; subOptions = if opt ? options then @@ -275,4 +275,16 @@ rec { ) [] options; + /* This function recursively removes all derivation attributes from + `x' except for the `name' attribute. This is to make the + generation of `options.xml' much more efficient: the XML + representation of derivations is very large (on the order of + megabytes) and is not actually used by the manual generator. */ + scrubOptionValue = x: + if isDerivation x then { type = "derivation"; drvPath = x.name; name = x.name; } + else if isList x then map scrubOptionValue x + else if isAttrs x then mapAttrs (n: v: scrubOptionValue v) x + else x; + + }