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.
JavaScript apple-watchbodyweightdockerfitnessfitness-trackergymhealthiosmcpnodejspasskeysprogressive-web-applicationspwareactself-hostedself-hostingvitewebauthnweightliftingworkout-tracker
fix: only use systemd StateDirectory for the default dataDir
gerrydoro12c3b3e40745
diff --git a/docs/NIX.md b/docs/NIX.mdindex 7f4f5f3ab..d7caf8f1a 100644--- a/docs/NIX.md+++ b/docs/NIX.md@@ -265,10 +265,10 @@ from *your system's* nixpkgs, which may differ slightly. If you ever need a spec```This gives you the `opengym` system user, `/var/lib/opengym` (created via `StateDirectory` +-tmpfiles), the `opengym-api` service listening on `:3000`, and — since `media.fetchAtBuild`-defaults to `false` — the `opengym-media` one-shot that downloads the exercise dataset (~140 MB,-once) into `/var/lib/opengym/media`. Pair it with the Caddy or nginx config from §4 pointing at-the exposed roots.+tmpfiles — the default `dataDir`), the `opengym-api` service listening on `:3000`, and — since+`media.fetchAtBuild` defaults to `false` — the `opengym-media` one-shot that downloads the exercise+dataset (~140 MB, once) into `/var/lib/opengym/media`. Pair it with the Caddy or nginx config from+§4 pointing at the exposed roots.### A realistic production example@@ -358,7 +358,7 @@ for other modules to consume — setting them yourself is an error.| --- | --- | --- | --- || `enable` | `bool` | `false` | Enable openGym (user, services, directories). || `package` | `attrsOf package` | packages built from source | The package set: `{ opengym-frontend, opengym-api, opengym-mcp, opengym-media, opengym-fetch-media }`. Override to serve pre-built binaries (e.g. from a cache). |-| `dataDir` | `path` | `/var/lib/opengym` | Persistent data directory — `db.json`, per-user `state-<uid>.json`, `secret`, `vapid.json`, `audit.log`. Created by the module; `ReadWritePaths` targets it. |+| `dataDir` | `path` | `/var/lib/opengym` | Persistent data directory — `db.json`, per-user `state-<uid>.json`, `secret`, `vapid.json`, `audit.log`. With the default `/var/lib/opengym`, systemd's `StateDirectory` creates (and cleans up) it; a custom path is created by a tmpfiles rule and `ReadWritePaths` points at it instead. || `apiPort` | `port` | `3000` | Port the API listens on (internal — reachable via your reverse proxy, front it yourself if you open the firewall). || `rpId` | `str` | `localhost` | WebAuthn Relying Party ID. Bare hostname, must match the address bar exactly. || `origin` | `str` | `http://localhost:8080` | Full origin for CSRF validation. Must match the address bar exactly (scheme + host, no trailing slash). |diff --git a/nix/opengym.nix b/nix/opengym.nixindex d632a5e54..08c47cca0 100644--- a/nix/opengym.nix+++ b/nix/opengym.nix@@ -259,33 +259,39 @@ inafter = [ "network.target" ];wantedBy = [ "multi-user.target" ];environment = cfg.environment // apiEnv;- serviceConfig = {- ExecStart = "${packages.opengym-api}/bin/opengym-api";- User = "opengym";- Group = "opengym";- StateDirectory = "opengym";- StateDirectoryMode = "0750";- Restart = "on-failure";- RestartSec = 5;- EnvironmentFile = lib.mkIf (cfg.environmentFile != "") cfg.environmentFile;-- NoNewPrivileges = true;- ProtectSystem = "strict";- ProtectHome = true;- PrivateTmp = true;- PrivateDevices = true;- ProtectKernelTunables = true;- ProtectKernelModules = true;- ProtectControlGroups = true;- RestrictNamespaces = true;- RestrictSUIDSGID = true;- LockPersonality = true;- SystemCallFilter = [- "@system-service"- "~@privileged"- ];- ReadWritePaths = [ cfg.dataDir ];- };+ serviceConfig = lib.mkMerge [+ {+ ExecStart = "${packages.opengym-api}/bin/opengym-api";+ User = "opengym";+ Group = "opengym";+ Restart = "on-failure";+ RestartSec = 5;+ EnvironmentFile = lib.mkIf (cfg.environmentFile != "") cfg.environmentFile;++ NoNewPrivileges = true;+ ProtectSystem = "strict";+ ProtectHome = true;+ PrivateTmp = true;+ PrivateDevices = true;+ ProtectKernelTunables = true;+ ProtectKernelModules = true;+ ProtectControlGroups = true;+ RestrictNamespaces = true;+ RestrictSUIDSGID = true;+ LockPersonality = true;+ SystemCallFilter = [+ "@system-service"+ "~@privileged"+ ];+ ReadWritePaths = [ cfg.dataDir ];+ }+ # systemd's StateDirectory= only lives under /var/lib, so use it for the default+ # dataDir; a custom dataDir is created by the tmpfiles rule instead.+ (lib.mkIf (builtins.toString cfg.dataDir == "/var/lib/opengym") {+ StateDirectory = "opengym";+ StateDirectoryMode = "0750";+ })+ ];};systemd.services.opengym-media = lib.mkIf (!cfg.media.fetchAtBuild) {@@ -293,14 +299,18 @@ inafter = [ "network-online.target" ];wants = [ "network-online.target" ];wantedBy = [ "multi-user.target" ];- serviceConfig = {- ExecStart = "${packages.opengym-fetch-media}/bin/opengym-fetch-media ${cfg.media.dataDir}";- Type = "oneshot";- RemainAfterExit = true;- User = "opengym";- Group = "opengym";- StateDirectory = "opengym";- };+ serviceConfig = lib.mkMerge [+ {+ ExecStart = "${packages.opengym-fetch-media}/bin/opengym-fetch-media ${cfg.media.dataDir}";+ Type = "oneshot";+ RemainAfterExit = true;+ User = "opengym";+ Group = "opengym";+ }+ (lib.mkIf (builtins.toString cfg.dataDir == "/var/lib/opengym") {+ StateDirectory = "opengym";+ })+ ];};services.opengym.media = {