summary refs log tree commit diff
diff options
context:
space:
mode:
authorDan Peebles <pumpkin@me.com>2017-05-24 18:56:22 -0400
committerDan Peebles <pumpkin@me.com>2017-05-26 18:14:31 -0400
commit7c3253e519a572f90a907fc56bb6407da004b24c (patch)
treebdb31f059a3988521842d5b8ac2d92c7937d26ed
parent8a11612d502d8578d7828e21778dcf3391084095 (diff)
downloadnixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar.gz
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar.bz2
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar.lz
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar.xz
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.tar.zst
nixpkgs-7c3253e519a572f90a907fc56bb6407da004b24c.zip
Simple proof of concept for how to do other types of services
-rw-r--r--nixos/modules/module-list.nix2
-rw-r--r--nixos/modules/service-managers/docker.nix29
-rw-r--r--nixos/modules/service-managers/trivial.nix35
-rw-r--r--nixos/modules/services/security/hologram-server.nix14
4 files changed, 77 insertions, 3 deletions
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index a3405c069b3..7985d3a3105 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 00000000000..8e9c763b18a
--- /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 00000000000..77e615d1e2e
--- /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 e267fed2795..8315c9ea5d6 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;
     };
   };
 }