[Nix-dev] Re: [Nix-commits] SVN commit: nix - 15723 - eelco - nixos/branches/modular-nixos/system
Eelco Dolstra
e.dolstra at tudelft.nl
Tue May 26 13:42:34 CEST 2009
Hi,
Nicolas Pierron wrote:
> I would even say that you don't need a require stament in this case.
> You can just in-line the options instead of the " require = [ options
> ]; ".
>
> -{
> - require = [
> - options
> - ];
> -}
> +options
>
> A set of option declarations is a correct modules.
Yes. However, it still strikes me as somewhat odd that options declarations and
definitions (i.e. config values) are declared in the same set. What is the
motivation for having them in the same set? I would be inclined to separate
them, i.e.
{config, pkgs, ...}:
{
# Dependencies (just a list of filenames).
require =
[ ./filename.nix
];
# Option declarations.
options = {
foo.bar.enable = mkOption { ... };
};
# Option definitions.
config = {
xyzzy.fnord = 123;
};
# And maybe a module could have some other attributes, like...
name = "bla";
description = "...";
}
This should also make the config processing in options.nix a bit more readable
(compared to fixOptionsSetsFun) by untangling the chasing of the "require"
dependencies, combining the option declarations, and computing the final
configuration. Something like:
# Given: the set of top-level modules.
modules = [./foo.nix ./bar.nix ...];
# The closure of modules under the "require" relation. I.e. for each module
# m, add m.require to the list. It should be possible to do this efficiently
# using the genericClosure primop.
modulesClosed = builtins.genericClosure { startSet = module; ... };
# The set of options is the union of the "options" attributes of each module.
options = recursiveUnion (map (m: m.options) modulesClosed);
# Compute the final configuration by traversing the options and the
# corresponding values in each module's "config", merging them using the
# "merge" attributes of each option, checking the type of values, etc.
config = completeConfig options (map (m: m.config) modulesClosed);
--
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/
More information about the nix-dev
mailing list