@ -24,18 +24,25 @@
} :
let
# Replace functions by the string <function>
substFunction = x :
if builtins . isAttrs x then lib . mapAttrs ( name : substFunction ) x
else if builtins . isList x then map substFunction x
# Make a value safe for JSON. Functions are replaced by the string "<function>",
# derivations are replaced with an attrset
# { _type = "derivation"; name = <name of that derivation>; }.
# We need to handle derivations specially because consumers want to know about them,
# but we can't easily use the type,name subset of keys (since type is often used as
# a module option and might cause confusion). Use _type,name instead to the same
# effect, since _type is already used by the module system.
substSpecial = x :
if lib . isDerivation x then { _type = " d e r i v a t i o n " ; name = x . name ; }
else if builtins . isAttrs x then lib . mapAttrs ( name : substSpecial ) x
else if builtins . isList x then map substSpecial x
else if lib . isFunction x then " < f u n c t i o n > "
else x ;
optionsList = lib . flip map optionsListVisible
( opt : transformOptions opt
// lib . optionalAttrs ( opt ? example ) { example = substFunction opt . example ; }
// lib . optionalAttrs ( opt ? default ) { default = substFunction opt . default ; }
// lib . optionalAttrs ( opt ? type ) { type = substFunction opt . type ; }
// lib . optionalAttrs ( opt ? example ) { example = substSpecial opt . example ; }
// lib . optionalAttrs ( opt ? default ) { default = substSpecial opt . default ; }
// lib . optionalAttrs ( opt ? type ) { type = substSpecial opt . type ; }
// lib . optionalAttrs ( opt ? relatedPackages && opt . relatedPackages != [ ] ) { relatedPackages = genRelatedPackages opt . relatedPackages opt . name ; }
) ;
@ -72,11 +79,6 @@ let
# Remove invisible and internal options.
optionsListVisible = lib . filter ( opt : opt . visible && ! opt . internal ) ( lib . optionAttrSetToDocList options ) ;
# Convert the list of options into an XML file.
# This file is *not* sorted sorted to save on eval time, since the docbook XML
# and the manpage depend on it and thus we evaluate this on every system rebuild.
optionsXML = builtins . toFile " o p t i o n s . x m l " ( builtins . toXML optionsList ) ;
optionsNix = builtins . listToAttrs ( map ( o : { name = o . name ; value = removeAttrs o [ " n a m e " " v i s i b l e " " i n t e r n a l " ] ; } ) optionsList ) ;
in rec {
@ -110,7 +112,18 @@ in rec {
mkdir - p $ out/nix-support
echo " f i l e j s o n $ d s t / o p t i o n s . j s o n " > > $ out/nix-support/hydra-build-products
echo " f i l e j s o n - b r $ d s t / o p t i o n s . j s o n . b r " > > $ out/nix-support/hydra-build-products
'' ; # * /
'' ;
# Convert options.json into an XML file.
# The actual generation of the xml file is done in nix purely for the convenience
# of not having to generate the xml some other way
optionsXML = pkgs . runCommand " o p t i o n s . x m l " { } ''
$ { pkgs . nix } /bin/nix-instantiate \
- - store dummy:// \
- - eval - - xml - - strict $ { ./optionsJSONtoXML.nix } \
- - argstr file $ { optionsJSON } /share/doc/nixos/options.json \
> " $ o u t "
'' ;
optionsDocBook = pkgs . runCommand " o p t i o n s - d o c b o o k . x m l " { } ''
optionsXML = $ { optionsXML }