mirror of
https://github.com/NixOS/nixpkgs.git
synced 2024-11-15 06:14:57 +01:00
ce29e4efc7
svn path=/nixos/trunk/; revision=7314
29 lines
953 B
Nix
29 lines
953 B
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.
|
|
|
|
lib: config:
|
|
|
|
rec {
|
|
|
|
# The option declarations, i.e., option names with defaults and
|
|
# documentation.
|
|
declarations = import ./options.nix;
|
|
|
|
# Get the option named `name' from the user configuration, using
|
|
# its default value if it's not defined.
|
|
get = name:
|
|
let
|
|
sameName = lib.filter (opt: lib.eqLists opt.name name) declarations;
|
|
default =
|
|
if sameName == []
|
|
then abort ("Undeclared option `" + printName name + "'.")
|
|
else if !builtins.head sameName ? default
|
|
then abort ("Option `" + printName name + "' has no default.")
|
|
else (builtins.head sameName).default;
|
|
in lib.getAttr name default config;
|
|
|
|
printName = name: lib.concatStrings (lib.intersperse "." name);
|
|
|
|
}
|