[Nix-dev] Re: [Nix-commits] SVN commit: nix - 12758 - raskin - nixpkgs/trunk/pkgs/lib

Nicolas Pierron nicolas.b.pierron at gmail.com
Thu Aug 28 00:23:02 CEST 2008


On Wed, Aug 27, 2008 at 23:23, Michael Raskin <7c6f434c at mail.ru> wrote:
> Modified: nixpkgs/trunk/pkgs/lib/default.nix
> ===================================================================
> --- nixpkgs/trunk/pkgs/lib/default.nix  2008-08-27 21:22:49 UTC (rev 12757)
> +++ nixpkgs/trunk/pkgs/lib/default.nix  2008-08-27 21:23:49 UTC (rev 12758)
> @@ -456,7 +456,7 @@
>       [({
>        #inherit (attrs) description;
>         description = if attrs ? description then attrs.description else
> -          throw ("No description ${toString l}");
> +          throw ("No description ${toString l} : ${whatis attrs}");
>       }
>       //(if attrs ? example then {inherit(attrs) example;} else {} )
>       //(if attrs ? default then {inherit(attrs) default;} else {} )

I suggest to remove the "l" argument in "optionAttrSetToDocList"
because options preprocessed with the "filterOptionSets" function
already have a "name" attribute like "services.xserver.enable".

By the way, a subset of the function "optionAttrSetToDocList" can
probably be rewritten like

exportOptionToDoc = attrs: (
  {name, default ? {}, example ? {}, description ? null, ...}:
    let description =
      if description != null then description
      else throw "No description ${name} : ${whatis attrs}";
    in
      { inherit name default example description; }
  ) attrs;

On the other hand, we can create a new function like
"filterOptionSets" and "mergeOptionSets" to create the flattened list
of options.

optionSetsToDocList = path: opts:
    if all __isAttrs opts then
      zip (attr: opts:
        let
          name = if path == "" then attr else path + "." + attr;
          test = partition isOption opts;
        in
          if test.right == [] then concatLists (flattenOptionSets name
test.wrong)
          else if tail test.right != [] then  throw "Multiple options
for '${name}'."
          else [ exportOptionToDoc ({ inherit name; } // (head test.right)) ]
      ) opts
    else [];

-- 
Nicolas Pierron
- If you are doing something twice then you should try to do it once.



More information about the nix-dev mailing list