Module system tweaks#2540
Conversation
|
cc @edolstra |
|
^ latest commit notes an issue that exists on master too with the |
|
^ And this latest fixes that issue. |
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).
|
👍 |
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).
|
Rebased |
|
@edolstra @rbvermaa I've rebased this again. Is there anything stopping us from merging? It is blocking NixOS/nixops#187 from being useful |
|
@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. |
|
The NixOS module system is too much magic for me to judge if it can be merged, so I won't merge. @edolstra ? |
There was a problem hiding this comment.
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/...>.
|
Could you push all those |
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.
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.
|
Addressed both comments. |
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).
|
Closing as this doesn't seem wanted. |
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:
mkIfinside of an option that is a container. So if you have an optionfoothat istypes.attrsOf types.int, you can now havefoo.bar = mkIf cfg.useBar 2;for example. Note that currently all post-systemd nixos setups have an emptysynergy-client.serviceandsynergy-server.servicedue to this not working as expected on master.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.argsand__internal.check). The current interfaces in<nixpkgs/nixos/lib/eval-config.nix>/evalModulesstill 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
pkgsargument to get access to the module functions (mkOption,mkIf,types, etc) inpkgs.lib. Instead, they should use thelibargument 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 switchpkgs.libto justlib.