]> git.immae.eu Git - perso/Immae/Config/Nix.git/blobdiff - modules/private/httpd-service-builder.nix
Make httpd service builder
[perso/Immae/Config/Nix.git] / modules / private / httpd-service-builder.nix
similarity index 97%
rename from nixops/modules/websites/apache/httpd_tools.nix
rename to modules/private/httpd-service-builder.nix
index c48d0d2f45348772be29162ea35a60b97fa9cb21..0f0fe2244564ecdb97e4ed83271b36096360565a 100644 (file)
@@ -1,10 +1,13 @@
+# to help backporting this builder should stay as close as possible to
+# nixos/modules/services/web-servers/apache-httpd/default.nix
+{ httpdName, withUsers ? true }:
 { config, lib, pkgs, ... }:
 
 with lib;
 
 let
 
-  mainCfg = config.services.httpdTools;
+  mainCfg = config.services."httpd${httpdName}";
 
   httpd = mainCfg.package.out;
 
@@ -435,7 +438,7 @@ in
 
   options = {
 
-    services.httpdTools = {
+    services."httpd${httpdName}" = {
 
       enable = mkOption {
         type = types.bool;
@@ -642,7 +645,7 @@ in
     }
 
     # Include the options shared between the main server and virtual hosts.
-    // (import ./per-server-options.nix {
+    // (import <nixpkgs/nixos/modules/services/web-servers/apache-httpd/per-server-options.nix> {
       inherit lib;
       forMainServer = true;
     });
@@ -652,7 +655,7 @@ in
 
   ###### implementation
 
-  config = mkIf config.services.httpdTools.enable {
+  config = mkIf config.services."httpd${httpdName}".enable {
 
     assertions = [ { assertion = mainCfg.enableSSL == true
                                -> mainCfg.sslServerCert != null
@@ -662,21 +665,21 @@ in
 
     warnings = map (cfg: ''apache-httpd's port option is deprecated. Use listen = [{/*ip = "*"; */ port = ${toString cfg.port};}]; instead'' ) (lib.filter (cfg: cfg.port != 0) allHosts);
 
-    users.users = optionalAttrs (mainCfg.user == "wwwrun") (singleton
+    users.users = optionalAttrs (withUsers && mainCfg.user == "wwwrun") (singleton
       { name = "wwwrun";
         group = mainCfg.group;
         description = "Apache httpd user";
         uid = config.ids.uids.wwwrun;
       });
 
-    users.groups = optionalAttrs (mainCfg.group == "wwwrun") (singleton
+    users.groups = optionalAttrs (withUsers && mainCfg.group == "wwwrun") (singleton
       { name = "wwwrun";
         gid = config.ids.gids.wwwrun;
       });
 
     environment.systemPackages = [httpd] ++ concatMap (svc: svc.extraPath) allSubservices;
 
-    services.httpdTools.phpOptions =
+    services."httpd${httpdName}".phpOptions =
       ''
         ; Needed for PHP's mail() function.
         sendmail_path = sendmail -t -i
@@ -689,7 +692,7 @@ in
         date.timezone = "${config.time.timeZone}"
       '';
 
-    systemd.services.httpdTools =
+    systemd.services."httpd${httpdName}" =
       { description = "Apache HTTPD";
 
         wantedBy = [ "multi-user.target" ];