Writing my own local httpd subservice

@pimiddy I have created a PR to add moodle to NixOS: moodle: init at 3.7.1 by aanderse · Pull Request #63634 · NixOS/nixpkgs · GitHub

I’m assuming you are familiar enough with moodle to adequately test this. I have never used moodle before so my testing was rather limited. You can see a minimal example in the test (nixos/tests/moodle.nix), but I’ll also include a full example here as well.

services.moodle = {
  hostName = "moodle.example.org";
  enableSSL = true;
  adminAddr = "webmaster@example.org";
  sslServerCert = "/var/lib/acme/moodle.example.org/full.pem";
  sslServerKey = "/var/lib/acme/moodle.example.org/key.pem";
};
# used for both ssl cert and https redirect
services.httpd.virtualHosts = [
  { hostName = "moodle.example.org";
    servedDirs = [
      { dir = "/var/run/acme-challenges/.well-known/acme-challenge";
        urlPath = "/.well-known/acme-challenge";
      }
    ];
    extraConfig = ''
      RewriteEngine On
      RewriteCond %{REQUEST_URI} !^/\.well\-known/
      RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    '';
  }
];
security.acme.certs = {
  "moodle.example.org" =
    { email = "webmaster@example.org";
      postRun = "systemctl reload httpd.service";
      webroot = "/var/run/acme-challenges";
    };
};

@pimiddy If you have an account on github please comment on the PR I created with your results for testing, otherwise feel free to comment here.

On a slightly unrelated note this example demonstrates how far behind nginx the httpd service has fallen. PRs to follow, I guess.

1 Like