Skip to content

Module system tweaks#2540

Closed
shlevy wants to merge 13 commits into
NixOS:masterfrom
shlevy:module-system-tweaks
Closed

Module system tweaks#2540
shlevy wants to merge 13 commits into
NixOS:masterfrom
shlevy:module-system-tweaks

Conversation

@shlevy

@shlevy shlevy commented May 6, 2014

Copy link
Copy Markdown
Member

This branch includes some improvements to the module system, which are of general interest I believe but will also make my forthcoming work on NixOS/nixops#78 cleaner. There are two fundamental user-visible changes here:

  • By refactoring the merge code, it's now possible to use properties like mkIf inside of an option that is a container. So if you have an option foo that is types.attrsOf types.int, you can now have foo.bar = mkIf cfg.useBar 2; for example. Note that currently all post-systemd nixos setups have an empty synergy-client.service and synergy-server.service due to this not working as expected on master.
  • The set of extra arguments passed to each module (e.g. pkgs, modulesPath, etc. that is currently passed everywhere in nixos) and the configuration knob to determine whether or not to allow definitions of options that aren't yet declared are now governed by internal options (__internal.args and __internal.check). The current interfaces in <nixpkgs/nixos/lib/eval-config.nix>/evalModules still work, but they use this under the hood. This makes the set of modules plus the version of <nixpkgs/lib> a full specification of the configuration, which is especially helpful in cases (like NixOS containers or modular nixops) where we want to make one config a submodule of a larger setup.

This introduces one backwards-incompatibility: Due to the change in how arguments are handled, modules shouldn't use the pkgs argument to get access to the module functions (mkOption, mkIf, types, etc) in pkgs.lib. Instead, they should use the lib argument that is passed to all modules, or they may result in an infinite recursion. This is already fixed for all in-tree modules, and unless you define options your personal configurations will probably not need to change, but if you run into an infinite recursion this is why, and the fix is to switch pkgs.lib to just lib.

@shlevy

shlevy commented May 6, 2014

Copy link
Copy Markdown
Member Author

cc @edolstra

@shlevy

shlevy commented May 7, 2014

Copy link
Copy Markdown
Member Author

^ latest commit notes an issue that exists on master too with the environment.checkConfigurationOptions option.

@shlevy

shlevy commented May 7, 2014

Copy link
Copy Markdown
Member Author

^ And this latest fixes that issue.

@shlevy shlevy mentioned this pull request May 7, 2014
shlevy added a commit to shlevy/nixops that referenced this pull request May 14, 2014
With the --modular-expressions flag, nixops will now treat the
expressions as a module, with machines and resources being evaluated as
submodules. This allows defining deployment-level options/configuration,
as well as reducing duplication between eval-machine-info.nix and
eval-config.nix.

Machines are now defined as attributes in resources.machines, and the
network.* configuration are now in the top-level config namespace (so
there's an enableRollback option, a description option, etc.). For
convenience, the top-level configuration can be accessed as the
'deployment' argument to each module.

Depends on NixOS/nixpkgs#2540 (though deployments without the
--modular-expressions flag will work without it).

Fixes NixOS#78 (see issue for more details on motivation).
@aszlig

aszlig commented May 14, 2014

Copy link
Copy Markdown
Member

👍

shlevy added a commit to shlevy/nixops that referenced this pull request May 20, 2014
With the --modular-expressions flag, nixops will now treat the
expressions as a module, with machines and resources being evaluated as
submodules. This allows defining deployment-level options/configuration,
as well as reducing duplication between eval-machine-info.nix and
eval-config.nix.

Machines are now defined as attributes in resources.machines, and the
network.* configuration are now in the top-level config namespace (so
there's an enableRollback option, a description option, etc.). For
convenience, the top-level configuration can be accessed as the
'deployment' argument to each module.

Depends on NixOS/nixpkgs#2540 (though deployments without the
--modular-expressions flag will work without it).

Fixes NixOS#78 (see issue for more details on motivation).
@shlevy

shlevy commented May 30, 2014

Copy link
Copy Markdown
Member Author

Rebased

@shlevy

shlevy commented Jun 10, 2014

Copy link
Copy Markdown
Member Author

@edolstra @rbvermaa I've rebased this again. Is there anything stopping us from merging? It is blocking NixOS/nixops#187 from being useful

@aszlig

aszlig commented Jun 21, 2014

Copy link
Copy Markdown
Member

@edolstra, @rbvermaa: I'd like to know as well what's the blocker against merging this, especially because I have several deployments that would benefit from NixOS/nixops#187 as well.

@rbvermaa

rbvermaa commented Jul 1, 2014

Copy link
Copy Markdown
Member

The NixOS module system is too much magic for me to judge if it can be merged, so I won't merge. @edolstra ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is incorrect - IIRC, amazon-config.nix is copied to /etc/nixos/configuration.nix, so it cannot use ./amazon-image.nix. But probably it can use <nixpkgs/nixos/modules/...>.

@edolstra

edolstra commented Jul 2, 2014

Copy link
Copy Markdown
Member

Could you push all those pkgs.lib -> lib changes to master and rebase? That will make this PR a bit easier to review.

shlevy added 13 commits July 2, 2014 12:29
This makes the relationship between property types clearer, and more
importantly will let option types parameterized by other option types
reuse the code for delegated type checking and merging.
This simplifies typechecking and allows properties to be used inside the lists
This simplifes typechecking and allows properties to be used inside of
the attribute sets.

This fixes the empty synergy-client and synergy-server services
previously generated on systems with synergy disabled.
With 1ebb6f4 this is no longer needed.

This reverts commit 9ae3654.
This symplifies typechecking and allows properties to be used inside the
function body. It also makes possible checking the type of the result.
This allows for module arguments to be handled modularly, in particular
allowing the nixpkgs module to handle the nixpkgs import internally.
This creates the __internal option namespace, which should only be added
to by the module system itself.
Ideally the module system could be configured pretty much completely by
the contents of the modules themselves, so add comments about avoiding
complicating it further and possibly removing now-redundant
configurability from the existing interface.
@shlevy

shlevy commented Jul 2, 2014

Copy link
Copy Markdown
Member Author

Addressed both comments.

shlevy added a commit to shlevy/nixops that referenced this pull request Jul 8, 2014
With the --modular-expressions flag, nixops will now treat the
expressions as a module, with machines and resources being evaluated as
submodules. This allows defining deployment-level options/configuration,
as well as reducing duplication between eval-machine-info.nix and
eval-config.nix.

Machines are now defined as attributes in resources.machines, and the
network.* configuration are now in the top-level config namespace (so
there's an enableRollback option, a description option, etc.). For
convenience, the top-level configuration can be accessed as the
'deployment' argument to each module.

Depends on NixOS/nixpkgs#2540 (though deployments without the
--modular-expressions flag will work without it).

Fixes NixOS#78 (see issue for more details on motivation).
@shlevy

shlevy commented Aug 26, 2014

Copy link
Copy Markdown
Member Author

Closing as this doesn't seem wanted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants