From 7c3253e519a572f90a907fc56bb6407da004b24c Mon Sep 17 00:00:00 2001 From: Dan Peebles Date: Wed, 24 May 2017 18:56:22 -0400 Subject: Simple proof of concept for how to do other types of services --- nixos/modules/module-list.nix | 2 ++ nixos/modules/service-managers/docker.nix | 29 ++++++++++++++++++ nixos/modules/service-managers/trivial.nix | 35 ++++++++++++++++++++++ .../modules/services/security/hologram-server.nix | 14 +++++++-- 4 files changed, 77 insertions(+), 3 deletions(-) create mode 100644 nixos/modules/service-managers/docker.nix create mode 100644 nixos/modules/service-managers/trivial.nix (limited to 'nixos') diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index a3405c069b34..7985d3a31058 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -129,6 +129,8 @@ ./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 diff --git a/nixos/modules/service-managers/docker.nix b/nixos/modules/service-managers/docker.nix new file mode 100644 index 000000000000..8e9c763b18af --- /dev/null +++ b/nixos/modules/service-managers/docker.nix @@ -0,0 +1,29 @@ +{ 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; +} diff --git a/nixos/modules/service-managers/trivial.nix b/nixos/modules/service-managers/trivial.nix new file mode 100644 index 000000000000..77e615d1e2e2 --- /dev/null +++ b/nixos/modules/service-managers/trivial.nix @@ -0,0 +1,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; +} diff --git a/nixos/modules/services/security/hologram-server.nix b/nixos/modules/services/security/hologram-server.nix index e267fed27955..8315c9ea5d61 100644 --- a/nixos/modules/services/security/hologram-server.nix +++ b/nixos/modules/services/security/hologram-server.nix @@ -23,6 +23,8 @@ let stats = cfg.statsAddress; listen = cfg.listenAddress; }); + + script = "${pkgs.hologram.bin}/bin/hologram-server --debug --conf ${cfgFile}"; in { options = { services.hologram-server = { @@ -94,9 +96,15 @@ in { 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; }; }; } -- cgit 1.4.1