Skip to content

Open-source gym & body-weight tracker, now in the App Store (iPhone + Apple Watch) and as an Android APK. Plan routines, log workouts, see which muscles are trained, import from Strong/Hevy/FitNotes. Self-host it or use it on the phone alone.

refactor: make module Caddy-native instead of nginx

gerrydoro039190e2f059
diff --git a/flake.nix b/flake.nix
old mode 100644
new mode 100755
index 46e555af3..df142334e
--- a/flake.nix
+++ b/flake.nix
@@ -37,8 +37,8 @@
enable = true;
rpId = "localhost";
origin = "http://localhost:8080";
- webPort = 8080;
apiPort = 3000;
+ media.fetchAtBuild = true;
};
system.stateVersion = "25.05";
}
@@ -47,22 +47,26 @@
cfg = testConfig.config.services.opengym;
- nginxVhosts = builtins.attrNames testConfig.config.services.nginx.virtualHosts;
+ nginxEnabled = testConfig.config.services.nginx.enable;
check = pkgs.runCommand "opengym-module-check" { } ''
set -euo pipefail
# Verify the module evaluated correctly
echo "services.opengym.enable = ${if cfg.enable then "true" else "false"}"
echo "services.opengym.apiPort = ${toString cfg.apiPort}"
- echo "services.opengym.webPort = ${toString cfg.webPort}"
echo "services.opengym.rpId = ${cfg.rpId}"
echo "services.opengym.origin = ${cfg.origin}"
# Verify systemd service exists
echo "systemd.services.opengym-api exists = ${if testConfig.config.systemd.services ? opengym-api then "true" else "false"}"
- # Verify nginx vhost
- echo "nginx virtualHosts = ${builtins.concatStringsSep ", " nginxVhosts}"
+ # Verify nginx is disabled (system uses Caddy)
+ echo "services.nginx.enable = ${if nginxEnabled then "true" else "false"}"
+
+ # Verify frontend/media store paths are exposed for a web server
+ echo "services.opengym.web.root = ${cfg.web.root}"
+ echo "services.opengym.media.imageRoot = ${cfg.media.imageRoot}"
+ echo "services.opengym.media.gifRoot = ${cfg.media.gifRoot}"
# Verify user exists
echo "users.users.opengym exists = ${if testConfig.config.users.users ? opengym then "true" else "false"}"
diff --git a/nix/opengym.nix b/nix/opengym.nix
old mode 100644
new mode 100755
index 3b9c40d24..38b618450
--- a/nix/opengym.nix
+++ b/nix/opengym.nix
@@ -40,17 +40,6 @@ let
mediaGifRoot =
if cfg.media.fetchAtBuild then "${packages.opengym-media}/videos" else "${cfg.media.dataDir}/gif";
- nginxListen =
- if cfg.virtualHost == null then
- {
- addr = "0.0.0.0";
- port = cfg.webPort;
- }
- else
- null;
-
- nginxServerName = if cfg.virtualHost != null then cfg.virtualHost else "_.${toString cfg.webPort}";
-
in
{
options.services.opengym = {
@@ -147,18 +136,6 @@ in
description = "VAPID subject for push notifications (defaults to ORIGIN).";
};
- webPort = lib.mkOption {
- type = lib.types.port;
- default = 8080;
- description = "Port nginx listens on (the port you browse to).";
- };
-
- virtualHost = lib.mkOption {
- type = lib.types.nullOr lib.types.str;
- default = null;
- description = "If set, configure as a named virtualHost instead of the default server.";
- };
-
media = {
fetchAtBuild = lib.mkOption {
type = lib.types.bool;
@@ -171,6 +148,26 @@ in
default = "${cfg.dataDir}/media";
description = "Directory for runtime-fetched exercise media.";
};
+
+ imageRoot = lib.mkOption {
+ type = lib.types.path;
+ readOnly = true;
+ description = "Directory containing exercise images (jpg). For use by a web server.";
+ };
+
+ gifRoot = lib.mkOption {
+ type = lib.types.path;
+ readOnly = true;
+ description = "Directory containing exercise GIFs. For use by a web server.";
+ };
+ };
+
+ web = {
+ root = lib.mkOption {
+ type = lib.types.path;
+ readOnly = true;
+ description = "Built frontend directory (static SPA). For use by a web server.";
+ };
};
mcp = {
@@ -241,57 +238,15 @@ in
};
};
- services.nginx = {
- enable = lib.mkDefault true;
-
- virtualHosts.${nginxServerName} = {
- default = (cfg.virtualHost == null);
-
- listen = lib.optionals (cfg.virtualHost == null) [ nginxListen ];
-
- root = "${packages.opengym-frontend}/share/opengym";
-
- locations = {
- "/" = {
- tryFiles = "$uri $uri/ /index.html";
- };
-
- "^~ /api/" = {
- proxyPass = "http://127.0.0.1:${toString cfg.apiPort}";
- extraConfig = ''
- proxy_http_version 1.1;
- proxy_set_header Host $host;
- proxy_set_header X-Real-IP $remote_addr;
- proxy_set_header X-Forwarded-For $remote_addr;
- proxy_set_header X-Forwarded-Proto $scheme;
- '';
- };
-
- "~* \\.(png|jpg|jpeg|gif|ico|svg|woff|woff2|webp|avif)$" = {
- alias = "${mediaRoot}/";
- extraConfig = ''
- expires 30d;
- add_header Cache-Control "public, max-age=2592000, immutable" always;
- add_header X-Frame-Options "DENY" always;
- add_header X-Content-Type-Options "nosniff" always;
- '';
- };
- };
-
- extraConfig = ''
- add_header X-Frame-Options "DENY" always;
- add_header X-Content-Type-Options "nosniff" always;
- add_header Referrer-Policy "same-origin" always;
- add_header Content-Security-Policy "frame-ancestors 'none'" always;
-
- gzip on;
- gzip_types text/plain text/css application/json application/javascript image/svg+xml;
- gzip_vary on;
- gzip_min_length 1024;
- '';
- };
+ services.nginx.enable = lib.mkForce false;
+
+ services.opengym.media = {
+ imageRoot = mediaRoot;
+ gifRoot = mediaGifRoot;
};
+ services.opengym.web.root = "${packages.opengym-frontend}/share/opengym";
+
systemd.services.opengym-mcp = lib.mkIf cfg.mcp.enable {
description = "openGym MCP server";
after = [ "network.target" ];