From 04812f9a9845cd5c13ef3a99318fc39a36df5729 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samuel=20=C5=A0tancl?= Date: Wed, 23 Jul 2025 16:14:11 +0200 Subject: [PATCH] Multi-domain support --- README.md | 11 +++++++---- laravel.nix | 9 ++++++--- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index dcb76f9..d8c1706 100644 --- a/README.md +++ b/README.md @@ -72,10 +72,10 @@ Import the module in your system flake and invoke it with these parameters: ```nix (laravelSite { name = "mysite"; - domain = "mysite.com"; + domains = [ "mysite.com" ]; phpPackage = pkgs.php84; - ssl = true; # optional, defaults to false + ssl = true; # optional, defaults to false, affects *ALL* domains extraNginxConfig = "nginx configuration string"; # optional sshKeys = [ "array" "of" "public" "ssh" "keys" ]; # optional extraPackages = [ pkgs.nodejs_24 ]; # optional @@ -111,7 +111,7 @@ to false). Also, if you're using `ssl` you should put this line into your system config: ```nix -security.acme.email = "your@email.com"; +security.acme.defaults.email = "your@email.com"; ``` A full system config can look something like this (excluding any additional configuration @@ -134,7 +134,10 @@ you may want to make): inherit system; modules = [ - { nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; } + { + nix.nixPath = [ "nixpkgs=${inputs.nixpkgs}" ]; + security.acme.defaults.email = "your@email.com"; + } ./configuration.nix # your (laravelSite { ... }) calls here diff --git a/laravel.nix b/laravel.nix index 2cbbb91..0ba5bf5 100644 --- a/laravel.nix +++ b/laravel.nix @@ -1,4 +1,4 @@ -{ name, domain, ssl ? false, extraNginxConfig ? null, sshKeys ? null, phpPackage, extraPackages ? [], queue ? false, queueArgs ? "", generateSshKey ? true, poolSettings ? { +{ name, phpPackage, domains ? [], ssl ? false, extraNginxConfig ? null, sshKeys ? null, extraPackages ? [], queue ? false, queueArgs ? "", generateSshKey ? true, poolSettings ? { "pm" = "dynamic"; "pm.max_children" = 8; "pm.start_servers" = 2; @@ -28,6 +28,7 @@ in { environment.etc."laravel-${name}-bashrc".text = '' # Laravel site welcome message echo "Welcome to ${name} Laravel site!" + echo "Domains: ${lib.concatStringsSep ", " domains}" echo "User home: /home/${mkUsername name}" echo "Site: /srv/${name}" echo "Restart php-fpm: sudo systemctl reload phpfpm-${name}" @@ -101,7 +102,9 @@ in { }; # Nginx virtual host configuration - services.nginx.virtualHosts.${domain} = { + # Note: these assignments within modules do NOT override the existing value that + # virtualHosts may have. Instead, all vhost configurations get merged into one. + services.nginx.virtualHosts = lib.genAttrs domains (domain: { enableACME = ssl; forceSSL = ssl; root = "/srv/${name}/public"; @@ -141,7 +144,7 @@ in { deny all; ''; }; - }; + }); # PHP-FPM pool configuration services.phpfpm.pools.${name} = {