Should we expose the type for modular services

Following @roberth’s call for feedback in the modular services PR (I think here is a better place to have open-ended discussion or simply asking questions):

In a project I want to say: this option holds a modular service. In order to do that, it would be nice to access the portable service module from an attribute. This would also make it slightly more convenient to build service management components – the systemd one directly imports by relative path, but external users shouldn’t have do that.

I imagine being able to do something along the lines of:

{ lib, ... }: {
  options.service = lib.mkOption {
    type = types.deferredModuleWith {
      staticModules = [ lib.nixos.types.portable-service ];
    };
  };
}

Anything that would speak against that? Except maybe that we don’t seem to have precedent for exposing entire modules for reuse as types. We don’t expose a lot of things in lib.nixos in the first place. I think portable services could warrant starting a lib.nixos.types, or at least a discussion how to expose modules that can also serve as submodule types.

Edit: I see it has become a bit more complicated than that since pkgs has been taken out of the module arguments.

Edit2: Ah scrap (most of) it, there’s the configure entry point I had overlooked on first read, which implements the type I was asking for. We can have a stare fight over names such as extraRootSpecialArgs though ಠ_ಠ. It puts the cherry on top of the classic extraSpecialArgs from Home Manager.

4 Likes

I would have one documentation request to better understand the proposed solution, so far all examples have been driven towards providing tasks-services, for running programs running in the background. This would work well to abstract tasks-services across module systems (NixOS, nix-darwin, home-manager).

However, the first times I felt the need for a generic service interface was for hosting-service (within a single module system instance), to abstract over similar virtual host interfaces of nginx and httpd (apache). Examples could include how to express gitweb / mediawiki / self-hosted-blog as hosting-service to be independent of either backend.

Note: I wish `} // lib.optionalAttrs (options ? systemd) {` had a more declarative solution. This is a leaky abstraction for people who never expected this attribute to exists.

Note 2: Thanks for working on this!

1 Like