Simple proof of concept for how to do other types of services

Changed files
+77 -3
nixos
modules
service-managers
services
+2
nixos/modules/module-list.nix
···
./security/rtkit.nix
./security/wrappers/default.nix
./security/sudo.nix
+
./service-managers/docker.nix
+
./service-managers/trivial.nix
./services/admin/salt/master.nix
./services/admin/salt/minion.nix
./services/amqp/activemq/default.nix
+29
nixos/modules/service-managers/docker.nix
···
+
{ config, lib, pkgs, ... }:
+
+
with lib;
+
+
let
+
cfg = config.docker-containers;
+
+
containerModule = {
+
script = mkOption {
+
type = types.lines;
+
description = "Shell commands executed as the service's main process.";
+
};
+
};
+
+
toContainer = name: value: pkgs.dockerTools.buildImage {
+
inherit name;
+
config = {
+
Cmd = [ value.script ];
+
};
+
};
+
in {
+
options.docker-containers = mkOption {
+
default = {};
+
type = with types; attrsOf (types.submodule containerModule);
+
description = "Definition of docker containers";
+
};
+
+
config.system.build.toplevel-docker = lib.mapAttrs toContainer cfg;
+
}
+35
nixos/modules/service-managers/trivial.nix
···
+
{ 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;
+
}
+11 -3
nixos/modules/services/security/hologram-server.nix
···
stats = cfg.statsAddress;
listen = cfg.listenAddress;
});
+
+
script = "${pkgs.hologram.bin}/bin/hologram-server --debug --conf ${cfgFile}";
in {
options = {
services.hologram-server = {
···
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
-
serviceConfig = {
-
ExecStart = "${pkgs.hologram.bin}/bin/hologram-server --debug --conf ${cfgFile}";
-
};
+
inherit script;
+
};
+
+
docker-containers.hologram-server = {
+
inherit script;
+
};
+
+
trivial-services.hologram-server = {
+
inherit script;
};
};
}