Remove test services, add README.md

This commit is contained in:
Sander van der Burg 2021-02-07 14:30:49 +01:00 committed by Sander van der Burg
parent 327540ecaa
commit f088f8b2bb
34 changed files with 19 additions and 1063 deletions

13
README.md Normal file
View File

@ -0,0 +1,13 @@
Nix-based process management framework service repository
=========================================================
This repository contains a collection of services that can be deployed with the
experimental
[Nix process management framework](https://github.com/svanderburg/nix-processmgmt).
You can deploy them with multiple process managers, use them as unprivileged
user, and run multiple instances of them on the same machine.
License
=======
The contents of this package is available under the same license as Nixpkgs --
the [MIT](https://opensource.org/licenses/MIT) license.

View File

@ -1,18 +0,0 @@
{ pkgs ? import <nixpkgs> { inherit system; }
, system ? builtins.currentSystem
, processManager ? "supervisord"
, forceDisableUserChange ? false
}:
let
createMultiProcessImage = import ../../nixproc/create-multi-process-image/create-multi-process-image-universal.nix {
inherit pkgs system;
inherit (pkgs) dockerTools stdenv;
};
in
createMultiProcessImage {
name = "multiprocess";
tag = "test";
exprFile = ../webapps-agnostic/processes.nix;
inherit processManager forceDisableUserChange;
}

View File

@ -1,4 +1,5 @@
{ pkgs
{ nix-processmgmt ? ../../nix-processmgmt
, pkgs
, stateDir
, logDir
, runtimeDir
@ -11,7 +12,7 @@
let
constructors = import ../services-agnostic/constructors.nix {
inherit pkgs stateDir logDir runtimeDir cacheDir tmpDir forceDisableUserChange processManager ids;
inherit nix-processmgmt pkgs stateDir logDir runtimeDir cacheDir tmpDir forceDisableUserChange processManager ids;
};
in
{

View File

@ -1,4 +1,5 @@
{ pkgs
{ nix-processmgmt ? ../../nix-processmgmt
, pkgs
, stateDir
, logDir
, runtimeDir
@ -10,7 +11,7 @@
}:
let
createManagedProcess = import ../../nixproc/create-managed-process/universal/create-managed-process-universal.nix {
createManagedProcess = import "${nix-processmgmt}/nixproc/create-managed-process/universal/create-managed-process-universal.nix" {
inherit pkgs runtimeDir stateDir logDir tmpDir forceDisableUserChange processManager ids;
};
in

View File

@ -1,25 +0,0 @@
{ pkgs
, stateDir
, logDir
, runtimeDir
, tmpDir
, forceDisableUserChange
, processManager
, webappMode # set to 'foreground' to make them all foreground process, 'daemon' to make them all daemons. null is to pick best option for the selected processManager
, ids ? {}
}:
let
createManagedProcess = import ../../nixproc/create-managed-process/universal/create-managed-process-universal.nix {
inherit pkgs runtimeDir stateDir logDir tmpDir forceDisableUserChange processManager ids;
};
webappExpr = if webappMode == "foreground" then ./webapp-fg.nix
else if webappMode == "daemon" then ./webapp-daemon.nix
else ./webapp.nix;
in
{
webapp = import webappExpr {
inherit createManagedProcess tmpDir;
};
}

View File

@ -1,5 +0,0 @@
{infrastructure}:
{
}

View File

@ -1,7 +0,0 @@
{infrastructure}:
{
webapp = [ infrastructure.test1 ];
webapp2 = [ infrastructure.test2 ];
nginx = [ infrastructure.test2 ];
}

View File

@ -1,18 +0,0 @@
rec {
webappPorts = {
min = 5000;
max = 6000;
};
nginxPorts = {
min = 8080;
max = 9000;
};
uids = {
min = 2000;
max = 3000;
};
gids = uids;
}

View File

@ -1,42 +0,0 @@
{
"ids" = {
"gids" = {
"nginx" = 2000;
"nginx2" = 2002;
"webapp1" = 2003;
"webapp2" = 2004;
"webapp3" = 2005;
"webapp4" = 2006;
"webapp5" = 2007;
"webapp6" = 2008;
};
"nginxPorts" = {
"nginx" = 8080;
"nginx2" = 8081;
};
"uids" = {
"nginx" = 2000;
"nginx2" = 2002;
"webapp1" = 2003;
"webapp2" = 2004;
"webapp3" = 2005;
"webapp4" = 2006;
"webapp5" = 2007;
"webapp6" = 2008;
};
"webappPorts" = {
"webapp1" = 5001;
"webapp2" = 5002;
"webapp3" = 5003;
"webapp4" = 5004;
"webapp5" = 5005;
"webapp6" = 5006;
};
};
"lastAssignments" = {
"gids" = 2008;
"nginxPorts" = 8081;
"uids" = 2008;
"webappPorts" = 5006;
};
}

View File

@ -1,24 +0,0 @@
{
"ids" = {
"gids" = {
"nginx" = 2000;
"webapp" = 2001;
};
"nginxPorts" = {
"nginx" = 8080;
};
"uids" = {
"nginx" = 2000;
"webapp" = 2001;
};
"webappPorts" = {
"webapp" = 5000;
};
};
"lastAssignments" = {
"gids" = 2001;
"nginxPorts" = 8080;
"uids" = 2001;
"webappPorts" = 5000;
};
}

View File

@ -1,4 +0,0 @@
{
test1.properties.hostname = "test1";
test2.properties.hostname = "test2";
}

View File

@ -1,41 +0,0 @@
let
nixproc-generate-config = (import ../../tools {}).generate-config;
in
{
test1 = {pkgs, ...}:
{
dysnomia = {
extraContainerProperties = {
managed-process = {
processManager = "systemd";
NIX_PATH = "/root/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels";
};
};
};
services.disnix.enable = true;
services.openssh.enable = true;
networking.firewall.enable = false;
environment.systemPackages = [ pkgs.pythonPackages.supervisor nixproc-generate-config ];
};
test2 = {pkgs, ...}:
{
dysnomia = {
extraContainerProperties = {
managed-process = {
processManager = "sysvinit";
NIX_PATH = "/root/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels";
};
};
};
services.disnix.enable = true;
services.openssh.enable = true;
networking.firewall.enable = false;
environment.systemPackages = [ pkgs.pythonPackages.supervisor nixproc-generate-config ];
};
}

View File

@ -1,14 +0,0 @@
{
test1 = {pkgs, ...}:
{
deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 4096; # megabytes
};
test2 = {pkgs, ...}:
{
deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 4096; # megabytes
};
}

View File

@ -1,119 +0,0 @@
{ pkgs ? import <nixpkgs> { inherit system; }
, system ? builtins.currentSystem
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, logDir ? "${stateDir}/log"
, cacheDir ? "${stateDir}/cache"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, processManager
, webappMode ? null
}:
let
ids = if builtins.pathExists ./ids-advanced.nix then (import ./ids-advanced.nix).ids else {};
sharedConstructors = import ../services-agnostic/constructors.nix {
inherit pkgs stateDir runtimeDir logDir cacheDir tmpDir forceDisableUserChange processManager ids;
};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir tmpDir forceDisableUserChange processManager webappMode ids;
};
in
rec {
webapp1 = rec {
port = ids.webappPorts.webapp1 or 0;
dnsName = "webapp1.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "1";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp2 = rec {
port = ids.webappPorts.webapp2 or 0;
dnsName = "webapp2.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "2";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp3 = rec {
port = ids.webappPorts.webapp3 or 0;
dnsName = "webapp3.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "3";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp4 = rec {
port = ids.webappPorts.webapp4 or 0;
dnsName = "webapp4.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "4";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx = rec {
port = ids.nginxPorts.nginx or 0;
pkg = sharedConstructors.nginxReverseProxyHostBased {
webapps = [ webapp1 webapp2 webapp3 webapp4 ];
inherit port;
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
webapp5 = rec {
port = ids.webappPorts.webapp5 or 0;
dnsName = "webapp5.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "5";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp6 = rec {
port = ids.webappPorts.webapp6 or 0;
dnsName = "webapp6.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "6";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx2 = rec {
port = ids.nginxPorts.nginx2 or 0;
pkg = sharedConstructors.nginxReverseProxyHostBased {
webapps = [ webapp5 webapp6 ];
inherit port;
instanceSuffix = "2";
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,46 +0,0 @@
{ pkgs ? import <nixpkgs> { inherit system; }
, system ? builtins.currentSystem
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, logDir ? "${stateDir}/log"
, cacheDir ? "${stateDir}/cache"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, processManager
, webappMode ? null
}:
let
ids = if builtins.pathExists ./ids.nix then (import ./ids.nix).ids else {};
sharedConstructors = import ../services-agnostic/constructors.nix {
inherit pkgs stateDir runtimeDir logDir cacheDir tmpDir forceDisableUserChange processManager ids;
};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir tmpDir forceDisableUserChange processManager webappMode ids;
};
in
rec {
webapp = rec {
port = ids.webappPorts.webapp or 0;
dnsName = "webapp.local";
pkg = constructors.webapp {
inherit port;
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx = rec {
port = ids.nginxPorts.nginx or 0;
pkg = sharedConstructors.nginxReverseProxyHostBased {
webapps = [ webapp ];
inherit port;
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,53 +0,0 @@
{ pkgs, distribution, invDistribution, system
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, logDir ? "${stateDir}/log"
, cacheDir ? "${stateDir}/cache"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
, processManager ? "sysvinit"
}:
let
ids = if builtins.pathExists ./ids.nix then (import ./ids.nix).ids else {};
sharedConstructors = import ../services-agnostic/constructors.nix {
inherit pkgs stateDir runtimeDir logDir cacheDir tmpDir forceDisableUserChange processManager ids;
};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir tmpDir forceDisableUserChange processManager ids;
webappMode = null;
};
processType = import ../../nixproc/derive-dysnomia-process-type.nix {
inherit processManager;
};
in
rec {
webapp = rec {
name = "webapp";
port = ids.webappPorts.webapp or 0;
dnsName = "webapp.local";
pkg = constructors.webapp {
inherit port;
};
type = processType;
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx = rec {
name = "nginx";
port = ids.nginxPorts.nginx or 0;
pkg = sharedConstructors.nginxReverseProxyHostBased {
inherit port;
};
dependsOn = {
inherit webapp;
};
type = processType;
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,42 +0,0 @@
{createManagedProcess, tmpDir}:
{port, instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}"}:
let
webapp = import ../../webapp;
pidFile = "${tmpDir}/${instanceName}.pid";
in
createManagedProcess {
name = instanceName;
description = "Simple web application";
inherit instanceName;
# This expression only specifies how to run webapp in daemon mode
daemon = "${webapp}/bin/webapp";
daemonArgs = [ "-D" ];
environment = {
PORT = port;
PID_FILE = pidFile;
};
inherit pidFile;
user = instanceName;
credentials = {
groups = {
"${instanceName}" = {};
};
users = {
"${instanceName}" = {
group = instanceName;
description = "Webapp";
};
};
};
overrides = {
sysvinit = {
runlevels = [ 3 4 5 ];
};
};
}

View File

@ -1,36 +0,0 @@
{createManagedProcess, tmpDir}:
{port, instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}"}:
let
webapp = import ../../webapp;
in
createManagedProcess {
name = instanceName;
description = "Simple web application";
inherit instanceName;
# This expression only specifies how to run the webapp in foreground mode
foregroundProcess = "${webapp}/bin/webapp";
environment = {
PORT = port;
};
user = instanceName;
credentials = {
groups = {
"${instanceName}" = {};
};
users = {
"${instanceName}" = {
group = instanceName;
description = "Webapp";
};
};
};
overrides = {
sysvinit = {
runlevels = [ 3 4 5 ];
};
};
}

View File

@ -1,39 +0,0 @@
{createManagedProcess, tmpDir}:
{port, instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}"}:
let
webapp = import ../../webapp;
in
createManagedProcess {
name = instanceName;
description = "Simple web application";
inherit instanceName;
# This expression can both run in foreground or daemon mode.
# The process manager can pick which mode it prefers.
process = "${webapp}/bin/webapp";
daemonArgs = [ "-D" ];
environment = {
PORT = port;
PID_FILE = "${tmpDir}/${instanceName}.pid";
};
user = instanceName;
credentials = {
groups = {
"${instanceName}" = {};
};
users = {
"${instanceName}" = {
group = instanceName;
description = "Webapp";
};
};
};
overrides = {
sysvinit = {
runlevels = [ 3 4 5 ];
};
};
}

View File

@ -1,37 +0,0 @@
{ pkgs
, stateDir
, cacheDir
, logDir
, runtimeDir
, tmpDir
, forceDisableUserChange
, ids ? {}
}:
let
createSystemVInitScript = import ../../nixproc/backends/sysvinit/create-sysvinit-script.nix {
inherit (pkgs) stdenv writeTextFile daemon;
inherit runtimeDir logDir tmpDir forceDisableUserChange;
createCredentials = import ../../nixproc/create-credentials {
inherit (pkgs) stdenv;
inherit ids forceDisableUserChange;
};
initFunctions = import ../../nixproc/backends/sysvinit/init-functions.nix {
basePackages = [ pkgs.coreutils pkgs.gnused pkgs.inetutils pkgs.gnugrep pkgs.sysvinit ];
inherit (pkgs) stdenv fetchurl;
inherit runtimeDir;
};
};
in
{
webapp = import ./webapp.nix {
inherit createSystemVInitScript tmpDir;
};
nginxReverseProxy = import ./nginx-reverse-proxy.nix {
inherit createSystemVInitScript stateDir logDir cacheDir runtimeDir forceDisableUserChange;
inherit (pkgs) stdenv writeTextFile nginx;
};
}

View File

@ -1,5 +0,0 @@
{infrastructure}:
{
}

View File

@ -1,6 +0,0 @@
{infrastructure}:
{
webapp = [ infrastructure.test1 ];
nginxReverseProxy = [ infrastructure.test2 ];
}

View File

@ -1,10 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>Disnix VirtualHosts example</title>
</head>
<body>
This web application is unavailable at the moment!
</body>
</html>

View File

@ -1,18 +0,0 @@
rec {
webappPorts = {
min = 5000;
max = 6000;
};
nginxPorts = {
min = 8080;
max = 9000;
};
uids = {
min = 2000;
max = 3000;
};
gids = uids;
}

View File

@ -1,42 +0,0 @@
{
"ids" = {
"gids" = {
"nginx" = 2000;
"nginx2" = 2002;
"webapp1" = 2003;
"webapp2" = 2004;
"webapp3" = 2005;
"webapp4" = 2006;
"webapp5" = 2007;
"webapp6" = 2008;
};
"nginxPorts" = {
"nginx" = 8080;
"nginx2" = 8081;
};
"uids" = {
"nginx" = 2000;
"nginx2" = 2002;
"webapp1" = 2003;
"webapp2" = 2004;
"webapp3" = 2005;
"webapp4" = 2006;
"webapp5" = 2007;
"webapp6" = 2008;
};
"webappPorts" = {
"webapp1" = 5001;
"webapp2" = 5002;
"webapp3" = 5003;
"webapp4" = 5004;
"webapp5" = 5005;
"webapp6" = 5006;
};
};
"lastAssignments" = {
"gids" = 2008;
"nginxPorts" = 8081;
"uids" = 2008;
"webappPorts" = 5006;
};
}

View File

@ -1,24 +0,0 @@
{
"ids" = {
"gids" = {
"nginx" = 2000;
"webapp" = 2001;
};
"nginxPorts" = {
"nginx" = 8080;
};
"uids" = {
"nginx" = 2000;
"webapp" = 2001;
};
"webappPorts" = {
"webapp" = 5000;
};
};
"lastAssignments" = {
"gids" = 2001;
"nginxPorts" = 8080;
"uids" = 2001;
"webappPorts" = 5000;
};
}

View File

@ -1,17 +0,0 @@
{
test1 = {pkgs, ...}:
{
services.disnix.enable = true;
services.openssh.enable = true;
networking.firewall.enable = false;
};
test2 = {pkgs, ...}:
{
services.disnix.enable = true;
services.openssh.enable = true;
networking.firewall.enable = false;
};
}

View File

@ -1,14 +0,0 @@
{
test1 = {pkgs, ...}:
{
deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 4096; # megabytes
};
test2 = {pkgs, ...}:
{
deployment.targetEnv = "virtualbox";
deployment.virtualbox.memorySize = 4096; # megabytes
};
}

View File

@ -1,88 +0,0 @@
{createSystemVInitScript, stdenv, writeTextFile, nginx, runtimeDir, stateDir, cacheDir, logDir, forceDisableUserChange}:
{port ? 80, webapps ? [], instanceSuffix ? "", instanceName ? "nginx${instanceSuffix}"}:
interDependencies:
let
user = instanceName;
group = instanceName;
nginxStateDir = "${stateDir}/${instanceName}";
nginxLogDir = "${nginxStateDir}/logs";
nginxCacheDir = "${cacheDir}/${instanceName}";
in
import ./nginx.nix {
inherit createSystemVInitScript stdenv nginx runtimeDir cacheDir forceDisableUserChange;
stateDir = nginxStateDir;
} {
inherit instanceName;
dependencies = map (webapp: webapp.pkg) webapps
++ map (interDependency: interDependency.pkgs."${stdenv.system}") (builtins.attrValues interDependencies);
configFile = writeTextFile {
name = "nginx.conf";
text = ''
pid ${runtimeDir}/${instanceName}.pid;
error_log ${nginxLogDir}/error.log;
${stdenv.lib.optionalString (!forceDisableUserChange) ''
user ${user} ${group};
''}
events {
worker_connections 190000;
}
http {
access_log ${nginxLogDir}/access.log;
error_log ${nginxLogDir}/error.log;
proxy_temp_path ${nginxCacheDir}/proxy;
client_body_temp_path ${nginxCacheDir}/client_body;
fastcgi_temp_path ${nginxCacheDir}/fastcgi;
uwsgi_temp_path ${nginxCacheDir}/uwsgi;
scgi_temp_path ${nginxCacheDir}/scgi;
${stdenv.lib.concatMapStrings (dependency: ''
upstream webapp${toString dependency.port} {
server localhost:${toString dependency.port};
}
'') webapps}
${stdenv.lib.concatMapStrings (paramName:
let
dependency = builtins.getAttr paramName interDependencies;
in
''
upstream webapp${toString dependency.port} {
server ${dependency.target.properties.hostname}:${toString dependency.port};
}
'') (builtins.attrNames interDependencies)}
# Fallback virtual host displaying an error page. This is what users see
# if they connect to a non-deployed web application.
# Without it, nginx redirects to the first available virtual host, giving
# unpredictable results. This could happen while an upgrade is in progress.
server {
client_body_temp_path ${nginxCacheDir}/client_body;
listen ${toString port};
server_name aaaa;
root ${./errorpage};
}
${stdenv.lib.concatMapStrings (dependency: ''
server {
client_body_temp_path ${nginxCacheDir}/client_body;
listen ${toString port};
server_name ${dependency.dnsName};
location / {
proxy_pass http://webapp${toString dependency.port};
}
}
'') (webapps ++ builtins.attrValues interDependencies)}
}
'';
};
}

View File

@ -1,38 +0,0 @@
{createSystemVInitScript, stdenv, nginx, stateDir, runtimeDir, cacheDir, forceDisableUserChange}:
{configFile, dependencies ? [], instanceSuffix ? "", instanceName ? "nginx${instanceSuffix}"}:
let
user = instanceName;
group = instanceName;
nginxLogDir = "${stateDir}/logs";
nginxCacheDir = "${cacheDir}/${instanceName}";
in
createSystemVInitScript {
name = instanceName;
description = "Nginx";
initialize = ''
mkdir -p ${nginxLogDir}
mkdir -p ${nginxCacheDir}
${stdenv.lib.optionalString (!forceDisableUserChange) ''
chown ${user}:${group} ${nginxLogDir}
''}
'';
process = "${nginx}/bin/nginx";
args = [ "-c" configFile "-p" stateDir ];
runlevels = [ 3 4 5 ];
inherit dependencies instanceName;
credentials = {
groups = {
"${group}" = {};
};
users = {
"${user}" = {
inherit group;
description = "Nginx user";
};
};
};
}

View File

@ -1,113 +0,0 @@
{ pkgs ? import <nixpkgs> { inherit system; }
, system ? builtins.currentSystem
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, cacheDir ? "${stateDir}/cache"
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
}:
let
ids = if builtins.pathExists ./ids-advanced.nix then (import ./ids-advanced.nix).ids else {};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir cacheDir tmpDir forceDisableUserChange ids;
};
in
rec {
webapp1 = rec {
port = ids.webappPorts.webapp1 or 0;
dnsName = "webapp1.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "1";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp2 = rec {
port = ids.webappPorts.webapp2 or 0;
dnsName = "webapp2.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "2";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp3 = rec {
port = ids.webappPorts.webapp3 or 0;
dnsName = "webapp3.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "3";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp4 = rec {
port = ids.webappPorts.webapp4 or 0;
dnsName = "webapp4.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "4";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx = rec {
port = ids.nginxPorts.nginx or 0;
pkg = constructors.nginxReverseProxy {
webapps = [ webapp1 webapp2 webapp3 webapp4 ];
inherit port;
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
webapp5 = rec {
port = ids.webappPorts.webapp5 or 0;
dnsName = "webapp5.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "5";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
webapp6 = rec {
port = ids.webappPorts.webapp6 or 0;
dnsName = "webapp6.local";
pkg = constructors.webapp {
inherit port;
instanceSuffix = "6";
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx2 = rec {
port = ids.nginxPorts.nginx2 or 0;
pkg = constructors.nginxReverseProxy {
webapps = [ webapp5 webapp6 ];
inherit port;
instanceSuffix = "2";
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,40 +0,0 @@
{ pkgs ? import <nixpkgs> { inherit system; }
, system ? builtins.currentSystem
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, logDir ? "${stateDir}/log"
, cacheDir ? "${stateDir}/cache"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? false
}:
let
ids = if builtins.pathExists ./ids.nix then (import ./ids.nix).ids else {};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir cacheDir tmpDir forceDisableUserChange ids;
};
in
rec {
webapp = rec {
port = ids.webappPorts.webapp or 0;
dnsName = "webapp.local";
pkg = constructors.webapp {
inherit port;
};
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginx = rec {
port = ids.nginxPorts.nginx or 0;
pkg = constructors.nginxReverseProxy {
webapps = [ webapp ];
inherit port;
} {};
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,42 +0,0 @@
{ pkgs, distribution, invDistribution, system
, stateDir ? "/var"
, runtimeDir ? "${stateDir}/run"
, logDir ? "${stateDir}/log"
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
, forceDisableUserChange ? true
}:
let
ids = if builtins.pathExists ./ids.nix then (import ./ids.nix).ids else {};
constructors = import ./constructors.nix {
inherit pkgs stateDir runtimeDir logDir tmpDir forceDisableUserChange;
};
in
rec {
webapp = rec {
name = "webapp";
port = ids.webappPorts.webapp or 0;
dnsName = "webapp.local";
pkg = constructors.webapp {
inherit port;
};
type = "sysvinit-script";
requiresUniqueIdsFor = [ "webappPorts" "uids" "gids" ];
};
nginxReverseProxy = rec {
name = "nginxReverseProxy";
port = ids.nginxPorts.nginx or 0;
pkg = constructors.nginxReverseProxy {
inherit port;
};
dependsOn = {
inherit webapp;
};
type = "sysvinit-script";
requiresUniqueIdsFor = [ "nginxPorts" "uids" "gids" ];
};
}

View File

@ -1,32 +0,0 @@
{createSystemVInitScript, tmpDir}:
{port, instanceSuffix ? "", instanceName ? "webapp${instanceSuffix}"}:
let
webapp = import ../../webapp;
in
createSystemVInitScript {
name = instanceName;
inherit instanceName;
process = "${webapp}/bin/webapp";
args = [ "-D" ];
environment = {
PORT = port;
PID_FILE = "${tmpDir}/${instanceName}.pid";
};
runlevels = [ 3 4 5 ];
user = instanceName;
credentials = {
groups = {
"${instanceName}" = {};
};
users = {
"${instanceName}" = {
group = instanceName;
description = "Webapp";
};
};
};
}