[Nix-dev] Attribute selection with default

Eelco Dolstra e.dolstra at tudelft.nl
Thu Sep 24 12:51:34 CEST 2009


Hi all,

Currently there are many places in the Nixpkgs and NixOS expressions where we
have to select a possibly missing attribute from a set, e.g.

  attrByPath ["extraModules"] [] mainCfg

or

  getConfig ["python" "db4Support"] true

Writing `attrByPath ["a" "b" "c"] default as' is rather verbose and ugly
compared to selecting an attribute without a default, i.e. `as.a.b.c'.

Since this is fairly common, how about some special syntax for supplying a
default value to the "." selection operator?  I propose the optional "or"
keyword following an attribute selection "x.<attrpath>".  E.g.

  mainCfg.extraModules or []

or

  config.python.db4Support or true

Comments?

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list