2006-12-11 16:42:02 +01:00
|
|
|
# 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.
|
|
|
|
|
2007-01-08 23:41:41 +01:00
|
|
|
pkgs: config:
|
|
|
|
|
|
|
|
let lib = pkgs.library; in
|
2006-12-11 16:42:02 +01:00
|
|
|
|
|
|
|
rec {
|
|
|
|
|
|
|
|
# The option declarations, i.e., option names with defaults and
|
|
|
|
# documentation.
|
2007-01-08 23:41:41 +01:00
|
|
|
declarations = import ./options.nix {inherit pkgs;};
|
2006-12-11 16:42:02 +01:00
|
|
|
|
|
|
|
# Get the option named `name' from the user configuration, using
|
|
|
|
# its default value if it's not defined.
|
|
|
|
get = name:
|
|
|
|
let
|
2006-12-21 01:16:20 +01:00
|
|
|
decl =
|
|
|
|
lib.findSingle (decl: lib.eqLists decl.name name)
|
|
|
|
(abort ("Undeclared option `" + printName name + "'."))
|
2007-10-03 15:27:45 +02:00
|
|
|
(abort ("Multiple declarations for option `" + printName name + "'."))
|
2006-12-21 01:16:20 +01:00
|
|
|
declarations;
|
2006-12-11 16:42:02 +01:00
|
|
|
default =
|
2006-12-21 01:16:20 +01:00
|
|
|
if !decl ? default
|
2006-12-11 16:42:02 +01:00
|
|
|
then abort ("Option `" + printName name + "' has no default.")
|
2006-12-21 01:16:20 +01:00
|
|
|
else decl.default;
|
2006-12-11 16:42:02 +01:00
|
|
|
in lib.getAttr name default config;
|
|
|
|
|
|
|
|
printName = name: lib.concatStrings (lib.intersperse "." name);
|
|
|
|
|
|
|
|
}
|