From ce29e4efc7f7986612be1f6cbd7598814545cdbe Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Mon, 11 Dec 2006 15:42:02 +0000 Subject: [PATCH] * More refactoring. svn path=/nixos/trunk/; revision=7314 --- configuration/boot-environment.nix | 35 +++++------------------------- configuration/config.nix | 29 +++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 30 deletions(-) create mode 100644 configuration/config.nix diff --git a/configuration/boot-environment.nix b/configuration/boot-environment.nix index dfab2b61670c..4d7f9d38d7b0 100644 --- a/configuration/boot-environment.nix +++ b/configuration/boot-environment.nix @@ -202,38 +202,13 @@ rec { }; - lib = pkgs.library; + config = import ./config.nix pkgs.library configData; - - config = rec { - - # The user configuration. - config = { - networking = { - hostname = "nixos"; - }; + # The user configuration. + configData = { + networking = { + hostname = "nixos"; }; - - # 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); - }; - } diff --git a/configuration/config.nix b/configuration/config.nix new file mode 100644 index 000000000000..705b44407af3 --- /dev/null +++ b/configuration/config.nix @@ -0,0 +1,29 @@ +# 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); + +}