2021-03-25 20:30:24 +00:00
|
|
|
{ pkgs ? import <nixpkgs> { inherit system; }
|
|
|
|
, system ? builtins.currentSystem
|
|
|
|
, stateDir ? "/var"
|
|
|
|
, runtimeDir ? "${stateDir}/run"
|
|
|
|
, logDir ? "${stateDir}/log"
|
|
|
|
, spoolDir ? "${stateDir}/spool"
|
|
|
|
, cacheDir ? "${stateDir}/cache"
|
|
|
|
, libDir ? "${stateDir}/lib"
|
|
|
|
, tmpDir ? (if stateDir == "/var" then "/tmp" else "${stateDir}/tmp")
|
|
|
|
, forceDisableUserChange ? false
|
|
|
|
, processManager
|
2021-04-23 19:39:52 +00:00
|
|
|
, nix-processmgmt ? ../../../nix-processmgmt
|
2021-03-25 20:30:24 +00:00
|
|
|
}:
|
|
|
|
|
|
|
|
let
|
|
|
|
constructors = import ../../services-agnostic/constructors.nix {
|
2021-04-23 19:39:52 +00:00
|
|
|
inherit pkgs stateDir runtimeDir logDir tmpDir cacheDir libDir spoolDir forceDisableUserChange processManager nix-processmgmt;
|
2021-03-25 20:30:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
webappStatic = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "webapp-static";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cat > $out/index.html <<EOF
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Hello</title>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
|
|
|
<h1>Hello world!</h1>
|
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
webappPHP = pkgs.stdenv.mkDerivation {
|
|
|
|
name = "webapp-php";
|
|
|
|
buildCommand = ''
|
|
|
|
mkdir -p $out
|
|
|
|
cat > $out/index.php <<EOF
|
|
|
|
<!DOCTYPE html>
|
|
|
|
|
|
|
|
<html>
|
|
|
|
<head>
|
|
|
|
<title>Hello</title>
|
|
|
|
</head>
|
|
|
|
|
|
|
|
<body>
|
2023-09-20 16:36:47 +00:00
|
|
|
<h1><?php print("Hello world from PHP!"); ?></h1>
|
2021-03-25 20:30:24 +00:00
|
|
|
</body>
|
|
|
|
</html>
|
|
|
|
EOF
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
in
|
|
|
|
rec {
|
|
|
|
# The first instance only serves static web apps
|
|
|
|
apache-primary = rec {
|
|
|
|
port = if forceDisableUserChange then 8080 else 80;
|
|
|
|
|
|
|
|
pkg = constructors.simpleWebappApache {
|
|
|
|
inherit port;
|
|
|
|
instanceSuffix = "-primary";
|
|
|
|
serverAdmin = "root@localhost";
|
|
|
|
documentRoot = webappStatic;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
# The second instance is PHP enabled
|
|
|
|
apache-secondary = rec {
|
|
|
|
port = if forceDisableUserChange then 8081 else 81;
|
|
|
|
|
|
|
|
pkg = constructors.simpleWebappApache {
|
|
|
|
inherit port;
|
|
|
|
instanceSuffix = "-secondary";
|
|
|
|
serverAdmin = "root@localhost";
|
|
|
|
documentRoot = webappPHP;
|
|
|
|
enablePHP = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|