NixOS / nixops

NixOps is a tool for deploying to NixOS machines in a network or cloud.
https://nixos.org/nixops
GNU Lesser General Public License v3.0
1.86k stars 365 forks source link

`require` -> `imports` #1486

Open roberth opened 3 years ago

roberth commented 3 years ago

I believe a custom require feature was chosen in order to solve a bootstrapping problem. This custom mechanism is not ideal because it adds to the growing list of "override", "overlay", "module", etc. It'd be better to reuse the module system. I suggest the following bootstrapping

  1. Load the raw network expressions as Nix functions
  2. Call them with bogus auto-arguments as in module (mapAttrs (k: v: throw k) (functionArgs module)
  3. This should give us module attrsets containing a few attributes of interest that we'll evaluated and a bunch of things we don't need and can't evaluate at this stage. That's ok.
  4. Use these partial modules to determine what lib should be.
  5. Call lib.evalModules on the network expressions.
  6. Have the module system at our disposal

A more radical approach, suitable for flakes, is to let the user inject lib manually. This would change the flake format to require a call like nixopsConfigurations.default = inputs.nixops.lib.mkNetwork { inherit lib; configuration = /* ... */; }, which is more robust than step 3 and 4. For non-flake nixops.nix we'll still want something like step 3 and 4 I think.

Pros:

Cons:

Myths:

Note to self: requires is not a recent addition; compatibility is needed and can be provided at next to no cost, because the module system still supports requires as a hardly known legacy feature.