Repository navigation
Description
our modular services implementations have so far ported over service modules that consisted of a single systemd service.
many of our existing service modules however are not restricted to this, instead making further use of ancilliary services, such as reverse proxies (say services.nginx) or databases (say services.postgresql).
as such, to scale out or concept of modular services to cover, or even end up superseding, our incumbent service modules, we would need a method to elegantly handle such multi-service service modules as well.
to get feedback on my current train of thought there, i think we could go about this by giving each used service (e.g. an application's services.postgresql) its own modular service, so that e.g. the default modular service is the application itself, its postgresql modular service handles the services.postgresql bits, while a compatibility layer (see #475372) could wrap these all together, by default.
now, the challenge here is that modular services have options at the service level, whereas traditional service modules have a shared option set handling anything required (main service, ancilliary services, other NixOS configuration).
while we could attempt to explicitly configure everything for each service even accepting options duplicated across sibling services, the problem here is that some of the info normally coordinated across services may be calculated in non-trivial ways, whereas in case info flows in both directions we may also need to deal with preventing infinite recursion.
prior art on addressing scenarios like that seems using contracts (#506343).
(also works across nodes.)
contracts offer a mechanism that, from the perspective of the application service making a request:
- takes input (request parameters)
- yields outputs (result)
- may generate configuration on the side of the provider, rendering it effectful (unlike nix functions, which yield outputs from inputs without causing such side-effects for our purposes here)
- .. all without automatically invoking things
note that, while contracts' original motivation involved abstracting over providers (e.g. have a reverse proxy contract rather than something specific to just e.g. nginx), solving our current challenge i think would not require such abstractions yet necessarily.
further, while the contracts PR uses a dedicated folder to gather contract implementations, i think in my idea here, in case of services offering multiple systemd services specific to the service (say a package offering an API service and a web service with some interaction in configuration), we could end up with contracts specific to an application, in which case it could be sensible to bundle such code with the modular rather than with general-use contracts.
as an extra note here to inform alternative ideas, contracts' round-trip mechanism should be overkill when not each of input/output/configuration are needed:
- don't need configuration: should be able to settle for a nix function
- don't need both input and output: should be able to settle for module system (possibly with custom types)
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsTodo
Activity
KiaraGrouwstra commentedon Feb 19, 2026
a way to map from traditional to modular services would be maintaining the old cross-service option set to coordinate what each of them need and instantiate the modular services.
that might make for lower-hanging fruit for compatibility, though eventually supporting a distributed setting could require contracts still.
KiaraGrouwstra commentedon Feb 19, 2026
previous work on coordinating information across distributed services also includes clan's
exportsnixos-discourse commentedon Feb 24, 2026
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/nixifying-kubernetes-with-nix-csi-easykubenix-and-dinix/70899/33
KiaraGrouwstra commentedon Feb 24, 2026
one simple idea might be to request external modules like:
the idea would be that this in itself would not yet do anything, instead exposing relevant info to the service consumer so that they might load such requested services as desired (same environment, different environment, ...).
testing.hardcoded-secret: namespace instances
testing.hardcoded-secret: namespace instances
KiaraGrouwstra commentedon Apr 3, 2026
i added a test
nixos/tests/contracts/database-modular-services.nixdemonstrating this principle at #506343.KiaraGrouwstra commentedon Apr 28, 2026
from matrix:
kiara:
roberth:
KiaraGrouwstra commentedon Jul 23, 2026
(earlier i posted this on matrix:)
i might have mentioned i considered modular services' child services feature something i had mixed feelings on, figuring that at face value i considered it closer to nixos services' way of doing things than to keeping distributing services across nodes a first-class citizen the way i'd like. i now managed to do a PoC on defining services on the nixpkgs side in a somewhat more logistics-agnostics way, such that the consumer could kind of rearrange things the way they prefer. i'll admit this builds upon contracts (this wasn't a 1-commit branch), but at least i now maybe got something tangible to show for how i generally felt on direction there, i guess.
KiaraGrouwstra@c01bd01
i considered having the rearrangements generated as well, but module system wanted separate evals to like prevent some infinite recursions. so maybe room for improvement still, but contracts-wise, the idea would be to have services client-style indicate what they'd want from lower-level services they'd consume. for the sake of simplicity, this example sorta cheated there by pretending the whole db config (i.e. also 'server side') is wholesale configured as part of that as well (on top of.. not being a real db).
but yeah, i hope the idea sorta came across.
nixos-discourse commentedon Jul 24, 2026
This issue has been mentioned on NixOS Discourse. There might be relevant details there:
https://discourse.nixos.org/t/modular-services-meeting-5-2026-07-24/79145/1