nixpkgs/system/config.nix
Eelco Dolstra f402fd73f2 * Print a sensible error message if there are multiple declarations
for an option.
* Removed double declaration for services.xserver.layout.

svn path=/nixos/trunk/; revision=9398
2007-10-03 13:27:45 +00:00

34 lines
1 KiB
Nix

# Given a configuration, this function returns an object with a `get'
# method for retrieving the values of options, falling back to the
# defaults declared in options.nix if no value is given for an
# option.
pkgs: config:
let lib = pkgs.library; in
rec {
# The option declarations, i.e., option names with defaults and
# documentation.
declarations = import ./options.nix {inherit pkgs;};
# Get the option named `name' from the user configuration, using
# its default value if it's not defined.
get = name:
let
decl =
lib.findSingle (decl: lib.eqLists decl.name name)
(abort ("Undeclared option `" + printName name + "'."))
(abort ("Multiple declarations for option `" + printName name + "'."))
declarations;
default =
if !decl ? default
then abort ("Option `" + printName name + "' has no default.")
else decl.default;
in lib.getAttr name default config;
printName = name: lib.concatStrings (lib.intersperse "." name);
}