1{ config, lib, pkgs, ... }:
2
3with lib;
4
5let
6 cfg = config.trivial-services;
7
8 serviceModule.options = {
9 script = mkOption {
10 type = types.lines;
11 description = "Shell commands executed as the service's main process.";
12 };
13
14 environment = mkOption {
15 default = {};
16 type = types.attrs; # FIXME
17 example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
18 description = "Environment variables passed to the service's processes.";
19 };
20 };
21
22 launcher = name: value: pkgs.writeScript name ''
23 #!${pkgs.stdenv.shell} -eu
24
25 ${pkgs.writeScript "${name}-entry" value.script}
26 '';
27in {
28 options.trivial-services = mkOption {
29 default = {};
30 type = with types; attrsOf (types.submodule serviceModule);
31 description = "Definition of trivial services";
32 };
33
34 config.system.build.toplevel-trivial = lib.mapAttrs launcher cfg;
35}