summary refs log tree commit diff
path: root/nixos/modules/service-managers/trivial.nix
blob: 77e615d1e2e2f8ac3754876f5689a6933e3df633 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
{ config, lib, pkgs, ... }:

with lib;

let
  cfg = config.trivial-services;

  serviceModule.options = {
    script = mkOption {
      type = types.lines;
      description = "Shell commands executed as the service's main process.";
    };

    environment = mkOption {
      default = {};
      type = types.attrs; # FIXME
      example = { PATH = "/foo/bar/bin"; LANG = "nl_NL.UTF-8"; };
      description = "Environment variables passed to the service's processes.";
    };
  };

  launcher = name: value: pkgs.writeScript name ''
    #!${pkgs.stdenv.shell} -eu

    ${pkgs.writeScript "${name}-entry" value.script}
  '';
in {
  options.trivial-services = mkOption {
    default = {};
    type = with types; attrsOf (types.submodule serviceModule);
    description = "Definition of trivial services";
  };

  config.system.build.toplevel-trivial = lib.mapAttrs launcher cfg;
}