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