Create service abstraction layer (proposal, prototype)

Idea
------

Let's abstract services, so they can be used independently by different process manager like supervisord, docker,... and not only by systemd.

Preface
----------

I really like nixos and module definition schema, and i really like to write nixos services. As a developer i want to make these services portable betwene systems independently of process managers if that is possible for speciffic service. Current systemd interface is not right approach and only results in hacks to support its interface(like https://github.com/kiberpipa/nix-rehash/tree/master/nix-services).

Problems with using systemd interface
---------------------------------------------------

Problem with using systemd interface as a base for service definitions for other process managers is that service definitions use all features of systemd, even that other process managers do not support them. There are not sufficient nixos options to support lack or presence of if:

- process manager can handle forking services
- process manager handles logs
- process manager handler logs from syslog
- ... your use case ...

Implementation
--------------------

Prototype implementation present in this pull request wants to solve this by abstracting services out of nixos. The reason for abstracting out is that services will not be only used in nixos, but also in other scearios with other process manager and with abscence of nixos on different systems, distros, process virtualization solutions like docker.

Because of lack of better idea i defined `sal`(service abstraction layer) interface abstracted into new `service` directory tree. There, service options/configurations are defined and process manager options are present. Real implementation of this schema is present in nixos systemd, which uses `sal` as a base for services.

I should mention that proposed solution is not usefull for all services and is not ment to replace systemd interface, which is by the way really nice and has a lot of features.

Alternative implemenations
------------------------------------

More straightforward solution would be to make something like `users.services` interface, for defining services. This has a downside, and does not take in account which features different process managers support.

I would really need this now
-------------------------------------

I want to ask you, whether you like the proposed implementation or if you have any better idea how to implement this. I would really like to solve the problem, because i need it to make user services and docker implementation using this or similar interface. Without this i can only make hacked implementations(that people use and depend on), like https://github.com/kiberpipa/nix-rehash/tree/master/nix-services, that i later don't want to support, because of hackiness involved.

**So please review the prototype and please propose better implementations and let's make nix services as portable as possible :)**

@edolstra @rbvermaa @nbp @iElectric @lethalman @wmertens
Yes, i'm adding a quite more flags, for different features.
On Dec 16, 2014 5:42 PM, "wmertens" <notifications@github.com> wrote:

> In services/services.nix
> <https://github.com/NixOS/nixpkgs/pull/5246#discussion-diff-21911916>:
>
> > +
> > +let
> > +in {
> > +  options = {
> > +    sal.services = mkOption {
> > +      default = {};
> > +      type = types.attrsOf types.optionSet;
> > +      options = [ serviceOptions ];
> > +      description = "Definition of systemd service units.";
> > +    };
> > +
> > +    sal.processManager = {
> > +      canFork = mkOption {
> > +        default = false;
> > +        type = types.bool;
> > +        description = "Whether process mananager can fork.";
>
> Do you mean "whether process manager can handle forking daemons."?
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/NixOS/nixpkgs/pull/5246/files#r21911916>.
>