Skip to content

Instantly share code, notes, and snippets.

@cleverca22
Last active July 6, 2016 11:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cleverca22/a7946666fe7fbf5ff7a4f46618a067f1 to your computer and use it in GitHub Desktop.
Save cleverca22/a7946666fe7fbf5ff7a4f46618a067f1 to your computer and use it in GitHub Desktop.
{ lib, config, pkgs, ... }:
with lib;
let
aedb = pkgs.callPackage ./aedb.nix {};
public_html = pkgs.callPackage ./public_html.nix { aedb = aedb; cfg = config.services.AEDB; };
in
{
options = {
services.AEDB = {
enable = mkOption {
type = types.bool;
default = false;
};
hostname = mkOption {
type = types.string;
default = config.networking.hostName;
};
master = mkOption {
type = types.string;
default = "nixos.angeldsis.com";
};
};
};
config = mkIf config.services.AEDB.enable {
users.extraUsers.AEDB = {
home = "/home/AEDB";
isNormalUser = true;
uid = 1002;
};
systemd.services.mysql.serviceConfig.TimeoutStartSec = "15m";
services = {
phpfpm.phpIni = ./php-recommended.ini;
phpfpm.poolConfigs = {
AEDB = ''
listen = /run/phpfpm/AEDB
listen.owner = lighttpd
user = AEDB
pm = static
pm.max_children = 1
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 1
pm.max_requests = 500
'';
};
mysql = {
enable = true;
package = pkgs.mysql55;
initialDatabases = [
{ name = "nixos_dsis"; schema = ./dsis_db_schema.sql; }
];
initialScript = pkgs.writeTextFile {
name = "initial.sql";
text = ''
grant all on `nixos_dsis`.* to `test`@localhost identified by 'test';
grant all on `nixos_qtest`.* to `test`@localhost identified by 'test';
'';
};
};
lighttpd = {
enable = true;
document-root = public_html;
enableModules = [ "mod_fastcgi" "mod_redirect" "mod_rewrite" ];
extraConfig =
''
#debug.log-request-handling = "enable"
$HTTP["host"] =~ "^nixos.angeldsis.com$" {
server.document-root = "${public_html}"
# include "/home/klingon/lighttpd_redirects"
url.rewrite-once += (
"/.*\?(.*)$" => "/index.php?$1",
"/.*\.(js|ico|gif|jpg|png|css|html)$" => "$0",
"/" => "/index.php"
)
fastcgi.server = ( ".php" =>
( "localhost" =>
(
"socket" => "/run/phpfpm/AEDB"
)
)
)
}
'';
};
};
};
}
{ stdenv, aedb, writeTextFile, cfg }:
let
config = writeTextFile {
name = "config.php";
text = ''
<?php
$master_server = "${cfg.master}";
$this_server = "${cfg.hostname}";
$base = 'nixos';
'';
};
in
stdenv.mkDerivation {
name = "public_html";
phases = [ "installPhase" ];
installPhase = ''
mkdir -pv $out/dsis/
cp -vi ${aedb}/root/index.php $out/
ln -sv ${aedb}/web/css $out/dsis/
ln -sv ${aedb}/web/java $out/dsis/
ln -sv ${aedb}/web/js $out/dsis/
ln -sv ${aedb}/web/sounds $out/dsis/
ln -sv ${aedb}/web/help $out/dsis/
ln -sv ${aedb}/web/images $out/dsis/
substituteInPlace $out/index.php --replace @AEDB@ ${aedb} --replace @CONFIGFILE@ ${config};
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment