NixNG icon indicating copy to clipboard operation
NixNG copied to clipboard

Implement a interface-like system

Open MagicRB opened this issue 3 years ago • 2 comments

Some options are commonly shared between different services. For example:

{
  # ...
  envsubst = {
    enable = mkEnableOption "Enable envsubst";
  
    variables = mkOption {
      type = with types; attrsOf (oneOf [ string int bool ]);
      # ...
    };
  };
  # ...
}

These options should be available for all services, but they should be implemented differently, each service has different config files. The next step may be making a system where the environmental substitution of configuration files is delegated to a common implementation, so that one can rely on original config files being in /run/<service-name>/orig and the modified version being in /run/<service-name>/subst.

Another example may be "user-group" handling, almost all services have a user and group options. The semantics of these options are not well defined, while I personally try to adhere to some semantics, it would be best if this was formalized in an implementation external to individual modules.

MagicRB avatar Nov 18 '21 10:11 MagicRB

I think the common interface can be implemented in lib.types.deferredModule since https://github.com/NixOS/nixpkgs/pull/163617

Atry avatar May 01 '24 23:05 Atry

Indeed, the problem is deciding what to make default and precisely how it should work :) but thanks for the pointer deferredSubmodule will be useful for another thing im working on. I didn't know abiut that type somehow.

MagicRB avatar May 02 '24 06:05 MagicRB