From f8026b6e4c869aa108f6361c8ccd50890657994d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Isma=C3=ABl=20Bouya?= Date: Sat, 18 May 2019 10:49:00 +0200 Subject: Move personal websites to modules --- modules/private/websites/aten/builder.nix | 102 ++++++++++++++++++++++++++ modules/private/websites/aten/integration.nix | 34 +++++++++ modules/private/websites/aten/production.nix | 36 +++++++++ 3 files changed, 172 insertions(+) create mode 100644 modules/private/websites/aten/builder.nix create mode 100644 modules/private/websites/aten/integration.nix create mode 100644 modules/private/websites/aten/production.nix (limited to 'modules/private/websites/aten') diff --git a/modules/private/websites/aten/builder.nix b/modules/private/websites/aten/builder.nix new file mode 100644 index 0000000..9a2e1a7 --- /dev/null +++ b/modules/private/websites/aten/builder.nix @@ -0,0 +1,102 @@ +{ apacheUser, apacheGroup, aten, lib, config }: rec { + app = aten.override { inherit (config) environment; }; + phpFpm = rec { + preStart = '' + if [ ! -f "${app.varDir}/currentWebappDir" -o \ + ! -f "${app.varDir}/currentKey" -o \ + "${app}" != "$(cat ${app.varDir}/currentWebappDir 2>/dev/null)" ] \ + || ! sha512sum -c --status ${app.varDir}/currentKey; then + pushd ${app} > /dev/null + /run/wrappers/bin/sudo -u ${apacheUser} APP_ENV=${app.environment} ./bin/console --env=${app.environment} cache:clear --no-warmup + popd > /dev/null + echo -n "${app}" > ${app.varDir}/currentWebappDir + sha512sum /var/secrets/webapps/${app.environment}-aten > ${app.varDir}/currentKey + fi + ''; + serviceDeps = [ "postgresql.service" ]; + socket = "/var/run/phpfpm/aten-${app.environment}.sock"; + pool = '' + listen = ${socket} + user = ${apacheUser} + group = ${apacheGroup} + listen.owner = ${apacheUser} + listen.group = ${apacheGroup} + php_admin_value[upload_max_filesize] = 20M + php_admin_value[post_max_size] = 20M + ;php_admin_flag[log_errors] = on + php_admin_value[open_basedir] = "${app}:${app.varDir}:/tmp" + php_admin_value[session.save_path] = "${app.varDir}/phpSessions" + ${if app.environment == "dev" then '' + pm = ondemand + pm.max_children = 5 + pm.process_idle_timeout = 60 + env[SYMFONY_DEBUG_MODE] = "yes" + '' else '' + pm = dynamic + pm.max_children = 20 + pm.start_servers = 2 + pm.min_spare_servers = 1 + pm.max_spare_servers = 3 + ''}''; + }; + keys = [{ + dest = "webapps/${app.environment}-aten"; + user = apacheUser; + group = apacheGroup; + permissions = "0400"; + text = '' + SetEnv APP_ENV "${app.environment}" + SetEnv APP_SECRET "${config.secret}" + SetEnv DATABASE_URL "${config.psql_url}" + ''; + }]; + apache = rec { + modules = [ "proxy_fcgi" ]; + webappName = "aten_${app.environment}"; + root = "/run/current-system/webapps/${webappName}"; + vhostConf = '' + + SetHandler "proxy:unix:${phpFpm.socket}|fcgi://localhost" + + + Include /var/secrets/webapps/${app.environment}-aten + + ${if app.environment == "dev" then '' + + Use LDAPConnect + Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + + + Use LDAPConnect + Require ldap-group cn=dev.aten.pro,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + '' else '' + Use Stats aten.pro + + + Use LDAPConnect + Require ldap-group cn=aten.pro,cn=httpd,ou=services,dc=immae,dc=eu + ErrorDocument 401 "" + + ''} + + + Options Indexes FollowSymLinks MultiViews Includes + AllowOverride All + Require all granted + DirectoryIndex index.php + FallbackResource /index.php + + ''; + }; + activationScript = { + deps = [ "wrappers" ]; + text = '' + install -m 0755 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir} + install -m 0750 -o ${apacheUser} -g ${apacheGroup} -d ${app.varDir}/phpSessions + ''; + }; +} diff --git a/modules/private/websites/aten/integration.nix b/modules/private/websites/aten/integration.nix new file mode 100644 index 0000000..790c5a9 --- /dev/null +++ b/modules/private/websites/aten/integration.nix @@ -0,0 +1,34 @@ +{ lib, pkgs, config, myconfig, ... }: +let + aten = pkgs.callPackage ./builder.nix { + inherit (pkgs.webapps) aten; + config = myconfig.env.websites.aten.integration; + apacheUser = config.services.httpd.Inte.user; + apacheGroup = config.services.httpd.Inte.group; + }; + + cfg = config.myServices.websites.aten.integration; +in { + options.myServices.websites.aten.integration.enable = lib.mkEnableOption "enable Aten's website in integration"; + + config = lib.mkIf cfg.enable { + secrets.keys = aten.keys; + services.myPhpfpm.preStart.aten_dev = aten.phpFpm.preStart; + services.myPhpfpm.serviceDependencies.aten_dev = aten.phpFpm.serviceDeps; + services.myPhpfpm.poolConfigs.aten_dev = aten.phpFpm.pool; + system.activationScripts.aten_dev = aten.activationScript; + system.extraSystemBuilderCmds = '' + mkdir -p $out/webapps + ln -s ${aten.app.webRoot} $out/webapps/${aten.apache.webappName} + ''; + services.websites.integration.modules = aten.apache.modules; + services.websites.integration.vhostConfs.aten = { + certName = "eldiron"; + addToCerts = true; + hosts = [ "dev.aten.pro" ]; + root = aten.apache.root; + extraConfig = [ aten.apache.vhostConf ]; + }; + }; +} + diff --git a/modules/private/websites/aten/production.nix b/modules/private/websites/aten/production.nix new file mode 100644 index 0000000..697f1b8 --- /dev/null +++ b/modules/private/websites/aten/production.nix @@ -0,0 +1,36 @@ +{ lib, pkgs, config, myconfig, ... }: +let + aten = pkgs.callPackage ./builder.nix { + inherit (pkgs.webapps) aten; + config = myconfig.env.websites.aten.production; + apacheUser = config.services.httpd.Prod.user; + apacheGroup = config.services.httpd.Prod.group; + }; + + cfg = config.myServices.websites.aten.production; +in { + options.myServices.websites.aten.production.enable = lib.mkEnableOption "enable Aten's website in production"; + + config = lib.mkIf cfg.enable { + secrets.keys = aten.keys; + services.webstats.sites = [ { name = "aten.pro"; } ]; + + services.myPhpfpm.preStart.aten_prod = aten.phpFpm.preStart; + services.myPhpfpm.serviceDependencies.aten_prod = aten.phpFpm.serviceDeps; + services.myPhpfpm.poolConfigs.aten_prod = aten.phpFpm.pool; + system.activationScripts.aten_prod = aten.activationScript; + system.extraSystemBuilderCmds = '' + mkdir -p $out/webapps + ln -s ${aten.app.webRoot} $out/webapps/${aten.apache.webappName} + ''; + services.websites.production.modules = aten.apache.modules; + services.websites.production.vhostConfs.aten = { + certName = "aten"; + certMainHost = "aten.pro"; + hosts = [ "aten.pro" "www.aten.pro" ]; + root = aten.apache.root; + extraConfig = [ aten.apache.vhostConf ]; + }; + }; +} + -- cgit v1.2.3