From 1aa49f0effd8408130e9c9544fca7164d57e8e7c Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 2 Feb 2023 15:24:17 +0100 Subject: [PATCH] Restructure web development for hikari Nix is not needed, it is generated. Try to find a better structure for web development setup. The initial steps with httpd and php fpm work now. --- systems/hikari/{nixos => }/cachix.nix | 0 systems/hikari/{nixos => }/cachix/fossar.nix | 0 systems/hikari/{nixos => }/configuration.nix | 2 + .../{nixos => }/hardware-configuration.nix | 0 systems/hikari/nix/nix.conf | 1 - systems/hikari/nix/registry.json | 1 - systems/hikari/{nixos => }/readme.rst | 0 systems/hikari/web-development.nix | 31 +++++++ .../daniel-siepmann.localhost.nix | 85 +++++++++++++++++++ 9 files changed, 118 insertions(+), 2 deletions(-) rename systems/hikari/{nixos => }/cachix.nix (100%) rename systems/hikari/{nixos => }/cachix/fossar.nix (100%) rename systems/hikari/{nixos => }/configuration.nix (99%) rename systems/hikari/{nixos => }/hardware-configuration.nix (100%) delete mode 120000 systems/hikari/nix/nix.conf delete mode 120000 systems/hikari/nix/registry.json rename systems/hikari/{nixos => }/readme.rst (100%) create mode 100644 systems/hikari/web-development.nix create mode 100644 systems/hikari/web-development/daniel-siepmann.localhost.nix diff --git a/systems/hikari/nixos/cachix.nix b/systems/hikari/cachix.nix similarity index 100% rename from systems/hikari/nixos/cachix.nix rename to systems/hikari/cachix.nix diff --git a/systems/hikari/nixos/cachix/fossar.nix b/systems/hikari/cachix/fossar.nix similarity index 100% rename from systems/hikari/nixos/cachix/fossar.nix rename to systems/hikari/cachix/fossar.nix diff --git a/systems/hikari/nixos/configuration.nix b/systems/hikari/configuration.nix similarity index 99% rename from systems/hikari/nixos/configuration.nix rename to systems/hikari/configuration.nix index f8c2c99..7d897cc 100644 --- a/systems/hikari/nixos/configuration.nix +++ b/systems/hikari/configuration.nix @@ -10,6 +10,8 @@ ./hardware-configuration.nix ./cachix.nix + + ./web-development.nix ]; boot = { diff --git a/systems/hikari/nixos/hardware-configuration.nix b/systems/hikari/hardware-configuration.nix similarity index 100% rename from systems/hikari/nixos/hardware-configuration.nix rename to systems/hikari/hardware-configuration.nix diff --git a/systems/hikari/nix/nix.conf b/systems/hikari/nix/nix.conf deleted file mode 120000 index 6b32217..0000000 --- a/systems/hikari/nix/nix.conf +++ /dev/null @@ -1 +0,0 @@ -/etc/static/nix/nix.conf \ No newline at end of file diff --git a/systems/hikari/nix/registry.json b/systems/hikari/nix/registry.json deleted file mode 120000 index 9141445..0000000 --- a/systems/hikari/nix/registry.json +++ /dev/null @@ -1 +0,0 @@ -/etc/static/nix/registry.json \ No newline at end of file diff --git a/systems/hikari/nixos/readme.rst b/systems/hikari/readme.rst similarity index 100% rename from systems/hikari/nixos/readme.rst rename to systems/hikari/readme.rst diff --git a/systems/hikari/web-development.nix b/systems/hikari/web-development.nix new file mode 100644 index 0000000..1a86ea4 --- /dev/null +++ b/systems/hikari/web-development.nix @@ -0,0 +1,31 @@ +{ pkgs, lib, ... }: + +{ + imports = [ + ./web-development/daniel-siepmann.localhost.nix + ]; + + services = { + httpd = { + enable = true; + + user = "daniels"; + + adminAddr = "apache@hikari.localhost"; + + extraModules = [ + "info" + "rewrite" + "proxy" + "proxy_fcgi" + ]; + + virtualHosts."localhost".locations."/server-info" = { + extraConfig = '' + SetHandler server-info + Require local + ''; + }; + }; + }; +} diff --git a/systems/hikari/web-development/daniel-siepmann.localhost.nix b/systems/hikari/web-development/daniel-siepmann.localhost.nix new file mode 100644 index 0000000..30e4531 --- /dev/null +++ b/systems/hikari/web-development/daniel-siepmann.localhost.nix @@ -0,0 +1,85 @@ +{ pkgs, lib, config, ... }: + +let + domain = "daniel-siepmann.localhost"; + documentRoot = "/var/projects/own/daniel-siepmann.de/project/public/"; +in { + services = { + httpd.virtualHosts.${domain} = { + # TODO: Add SSL + # forceSSL = true; + # addSSL = true; + inherit documentRoot; + extraConfig = '' + + AllowOverride None + Require all granted + DirectoryIndex index.php + + RewriteEngine On + + # Store the current location in an environment variable CWD to use + # mod_rewrite in .htaccess files without knowing the RewriteBase + RewriteCond $0#%{REQUEST_URI} ([^#]*)#(.*)\1$ + RewriteRule ^.*$ - [E=CWD:%2] + + # Rule for versioned static files, configured through: + # - $GLOBALS['TYPO3_CONF_VARS']['BE']['versionNumberInFilename'] + # - $GLOBALS['TYPO3_CONF_VARS']['FE']['versionNumberInFilename'] + # IMPORTANT: This rule has to be the very first RewriteCond in order to work! + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteRule ^(.+)\.(\d+)\.(php|js|css|png|jpg|gif|gzip)$ %{ENV:CWD}$1.$3 [L] + + # Access block for folders + RewriteRule _(?:recycler|temp)_/ - [F] + RewriteRule fileadmin/templates/.*\.(?:txt|ts)$ - [F] + RewriteRule ^(?:vendor|typo3_src|typo3temp/var) - [F] + RewriteRule (?:typo3conf/ext|typo3/sysext|typo3/ext)/[^/]+/(?:Configuration|Resources/Private|Tests?|Documentation|docs?)/ - [F] + + # Block access to all hidden files and directories with the exception of + # the visible content from within the `/.well-known/` hidden directory (RFC 5785). + RewriteCond %{REQUEST_URI} "!(^|/)\.well-known/([^./]+./?)+$" [NC] + RewriteCond %{SCRIPT_FILENAME} -d [OR] + RewriteCond %{SCRIPT_FILENAME} -f + RewriteRule (?:^|/)\. - [F] + + # Stop rewrite processing, if we are in any other known directory + # NOTE: Add your additional local storages here + RewriteRule ^(?:fileadmin/|typo3conf/|typo3temp/|uploads/) - [L] + + # If the file/symlink/directory does not exist but is below /typo3/, redirect to the TYPO3 Backend entry point. + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-l + RewriteCond %{REQUEST_URI} ^/typo3/.*$ + RewriteRule ^typo3/(.*)$ %{ENV:CWD}typo3/index.php [QSA,L] + + # If the file/symlink/directory does not exist => Redirect to index.php. + # For httpd.conf, you need to prefix each '%{REQUEST_FILENAME}' with '%{DOCUMENT_ROOT}'. + RewriteCond %{REQUEST_FILENAME} !-f + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-l + RewriteRule ^.*$ %{ENV:CWD}index.php [QSA,L] + + + + SetHandler "proxy:unix:${config.services.phpfpm.pools."${domain}".socket}|fcgi://${domain}/" + + ''; + }; + phpfpm.pools.${domain} = { + inherit (config.services.httpd) user group; + phpPackage = pkgs.php82; + settings = { + "listen.owner" = config.services.httpd.user; + "listen.group" = config.services.httpd.group; + "pm" = "static"; + "pm.max_children" = 15; + }; + phpEnv = { + TYPO3_CONTEXT = "Development/dsiepmann"; + }; + }; + }; +}