1 { config, lib, pkgs, ... }:
4 cfg = config.services.mainsail;
5 moonraker = config.services.moonraker;
8 options.services.mainsail = {
9 enable = mkEnableOption "a modern and responsive user interface for Klipper";
11 package = mkPackageOption pkgs "mainsail" { };
15 default = "localhost";
16 description = "Hostname to serve mainsail on";
20 type = types.submodule
21 (import ../web-servers/nginx/vhost-options.nix { inherit config lib; });
23 example = literalExpression ''
25 serverAliases = [ "mainsail.''${config.networking.domain}" ];
28 description = "Extra configuration for the nginx virtual host of mainsail.";
32 config = mkIf cfg.enable {
35 upstreams.mainsail-apiserver.servers."${moonraker.address}:${toString moonraker.port}" = { };
36 virtualHosts."${cfg.hostName}" = mkMerge [
39 root = mkForce "${cfg.package}/share/mainsail";
43 tryFiles = "$uri $uri/ /index.html";
45 "/index.html".extraConfig = ''
46 add_header Cache-Control "no-store, no-cache, must-revalidate";
49 proxyWebsockets = true;
50 proxyPass = "http://mainsail-apiserver/websocket";
52 "~ ^/(printer|api|access|machine|server)/" = {
53 proxyWebsockets = true;
54 proxyPass = "http://mainsail-apiserver$request_uri";