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.

nix: move the flake under contrib/nix

gerrydoroe7e210edb0ad
diff --git a/nix/api.nix b/contrib/nix/api.nix
similarity index 98%
rename from nix/api.nix
rename to contrib/nix/api.nix
index 0de411efe..ac2015bf4 100644
--- a/nix/api.nix
+++ b/contrib/nix/api.nix
@@ -11,7 +11,7 @@ buildNpmPackage rec {
pname = "opengym-api";
inherit version;
- src = ./../api;
+ src = ./../../api;
nodejs = nodejs_22;
diff --git a/nix/default.nix b/contrib/nix/default.nix
similarity index 100%
rename from nix/default.nix
rename to contrib/nix/default.nix
diff --git a/flake.lock b/contrib/nix/flake.lock
similarity index 100%
rename from flake.lock
rename to contrib/nix/flake.lock
diff --git a/flake.nix b/contrib/nix/flake.nix
similarity index 77%
rename from flake.nix
rename to contrib/nix/flake.nix
index fa973b857..922df8b01 100644
--- a/flake.nix
+++ b/contrib/nix/flake.nix
@@ -18,7 +18,7 @@
let
pkgs = nixpkgs.legacyPackages.${system};
- opengymPackages = import ./nix/default.nix { inherit pkgs; };
+ opengymPackages = import ./default.nix { inherit pkgs; };
opengymNixOSModule = self.nixosModules.opengym;
@@ -32,7 +32,9 @@
rpId = "localhost";
origin = "http://localhost:8080";
apiPort = 3000;
- environment = { MY_FLAG = "1"; };
+ environment = {
+ MY_FLAG = "1";
+ };
media.fetchAtBuild = true;
};
system.stateVersion = "25.05";
@@ -68,19 +70,35 @@
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"}"
+ echo "systemd.services.opengym-api exists = ${
+ if testConfig.config.systemd.services ? opengym-api then "true" else "false"
+ }"
# Verify extra environment is applied to the API unit
- echo "opengym-api env MY_FLAG = ${if testConfig.config.systemd.services.opengym-api.environment ? MY_FLAG then testConfig.config.systemd.services.opengym-api.environment.MY_FLAG else "missing"}"
+ echo "opengym-api env MY_FLAG = ${
+ if testConfig.config.systemd.services.opengym-api.environment ? MY_FLAG then
+ testConfig.config.systemd.services.opengym-api.environment.MY_FLAG
+ else
+ "missing"
+ }"
# Verify nginx is disabled by default (system uses Caddy)
echo "services.nginx.enable (default) = ${if nginxEnabled then "true" else "false"}"
# Verify the optional managed nginx vhost gets configured
- echo "services.nginx.enable (nginx.enable) = ${if nginxTestConfig.config.services.nginx.enable then "true" else "false"}"
- echo "nginx vhost for 'localhost' = ${if nginxTestConfig.config.services.nginx.virtualHosts ? localhost then "true" else "false"}"
- echo "nginx /api proxyPass = ${nginxTestConfig.config.services.nginx.virtualHosts."localhost".locations."/api/".proxyPass or "missing"}"
- echo "nginx /img alias = ${nginxTestConfig.config.services.nginx.virtualHosts."localhost".locations."/img/".alias or "missing"}"
+ echo "services.nginx.enable (nginx.enable) = ${
+ if nginxTestConfig.config.services.nginx.enable then "true" else "false"
+ }"
+ echo "nginx vhost for 'localhost' = ${
+ if nginxTestConfig.config.services.nginx.virtualHosts ? localhost then "true" else "false"
+ }"
+ echo "nginx /api proxyPass = ${
+ nginxTestConfig.config.services.nginx.virtualHosts."localhost".locations."/api/".proxyPass
+ or "missing"
+ }"
+ echo "nginx /img alias = ${
+ nginxTestConfig.config.services.nginx.virtualHosts."localhost".locations."/img/".alias or "missing"
+ }"
# Verify frontend/media store paths are exposed for a web server
echo "services.opengym.web.root = ${cfg.web.root}"
@@ -88,7 +106,9 @@
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"}"
+ echo "users.users.opengym exists = ${
+ if testConfig.config.users.users ? opengym then "true" else "false"
+ }"
# All checks passed
touch $out
@@ -164,9 +184,10 @@
checks = {
nixos-module-eval = check;
- } // (pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
+ }
+ // (pkgs.lib.optionalAttrs pkgs.stdenv.hostPlatform.isLinux {
# Boots a NixOS VM and exercises the full HTTP contract (API + nginx vhost + SPA).
- opengym-nixos-test = import ./nix/tests.nix {
+ opengym-nixos-test = import ./tests.nix {
inherit pkgs;
modules = [ opengymNixOSModule ];
};
@@ -188,18 +209,18 @@
)
// {
# Wraps the module so NixOS configurations using it get openGym packages built from this
- # flake's LOCKED nixpkgs input. Importing nix/opengym.nix directly falls back to the
- # importing system's nixpkgs.
+ # flake's LOCKED nixpkgs input. Importing contrib/nix/opengym.nix directly falls back to
+ # the importing system's nixpkgs.
nixosModules.opengym =
{ pkgs, ... }:
{
- imports = [ ./nix/opengym.nix ];
+ imports = [ ./opengym.nix ];
_module.args.opengymPkgs = self.packages.${pkgs.system} or null;
};
nixosModules.default = self.nixosModules.opengym;
# Conventional NixOS test output (boots a VM; also wired into checks on Linux).
- nixosTests.opengym = import ./nix/tests.nix {
+ nixosTests.opengym = import ./tests.nix {
pkgs = nixpkgs.legacyPackages.x86_64-linux;
modules = [ self.nixosModules.opengym ];
};
diff --git a/nix/frontend.nix b/contrib/nix/frontend.nix
similarity index 98%
rename from nix/frontend.nix
rename to contrib/nix/frontend.nix
index 9e70761cf..033a4fb8a 100644
--- a/nix/frontend.nix
+++ b/contrib/nix/frontend.nix
@@ -12,7 +12,7 @@ buildNpmPackage rec {
# The frontend imports api/coach/core/* (../../../api/coach/core/…), so the build
# needs the repo root — same layout the Dockerfile uses (see web/Dockerfile).
- src = ./..;
+ src = ./../..;
npmRoot = "frontend";
nodejs = nodejs_22;
diff --git a/nix/mcp.nix b/contrib/nix/mcp.nix
similarity index 96%
rename from nix/mcp.nix
rename to contrib/nix/mcp.nix
index b1b8787f2..5b7e574ea 100644
--- a/nix/mcp.nix
+++ b/contrib/nix/mcp.nix
@@ -11,10 +11,10 @@ buildNpmPackage rec {
pname = "opengym-mcp";
inherit version;
- src = ./../mcp;
+ src = ./../../mcp;
# The MCP server reads shared domain helpers from the sibling frontend/src/lib; include them.
- frontendSrc = ./../frontend;
+ frontendSrc = ./../../frontend;
nodejs = nodejs_22;
diff --git a/nix/media-script.nix b/contrib/nix/media-script.nix
similarity index 100%
rename from nix/media-script.nix
rename to contrib/nix/media-script.nix
diff --git a/nix/media.nix b/contrib/nix/media.nix
similarity index 100%
rename from nix/media.nix
rename to contrib/nix/media.nix
diff --git a/nix/opengym.nix b/contrib/nix/opengym.nix
similarity index 100%
rename from nix/opengym.nix
rename to contrib/nix/opengym.nix
diff --git a/nix/tests.nix b/contrib/nix/tests.nix
similarity index 100%
rename from nix/tests.nix
rename to contrib/nix/tests.nix
diff --git a/nix/version.nix b/contrib/nix/version.nix
similarity index 100%
rename from nix/version.nix
rename to contrib/nix/version.nix
diff --git a/docs/NIX.md b/docs/NIX.md
index 0e680742c..0e447455d 100644
--- a/docs/NIX.md
+++ b/docs/NIX.md
@@ -9,7 +9,8 @@ managed by your NixOS configuration. This document covers both.
### What the flake provides
-`flake.nix` (inputs: `nixpkgs` on `nixos-unstable`, `flake-utils`) exposes, per supported system:
+`contrib/nix/flake.nix` (inputs: `nixpkgs` on `nixos-unstable`, `flake-utils`) exposes, per
+supported system:
| Output | What it is |
| --- | --- |
@@ -63,24 +64,32 @@ browser ── HTTPS ──▶ your web server (Caddy / nginx / …) eve
## 2. Repository layout
```text
-flake.nix Flake entry point — packages, apps, devShell, module alias
-nix/
- opengym.nix The NixOS module (options + systemd/nginx wiring)
- frontend.nix buildNpmPackage → $out/share/opengym
- api.nix buildNpmPackage → bin/opengym-api
- mcp.nix buildNpmPackage → bin/opengym-mcp
- media.nix fetchFromGitHub pin of the exercise dataset (build-time)
- media-script.nix runtime media-fetch shell script
- version.nix version = "1.2.14" + pinned dataset commit (single source of truth)
- default.nix package-set aggregator (used by both the flake and the module)
+contrib/nix/
+ flake.nix Flake entry point — packages, apps, devShell, module alias
+ flake.lock Locked inputs
+ opengym.nix The NixOS module (options + systemd/nginx wiring)
+ frontend.nix buildNpmPackage → $out/share/opengym
+ api.nix buildNpmPackage → bin/opengym-api
+ mcp.nix buildNpmPackage → bin/opengym-mcp
+ media.nix fetchFromGitHub pin of the exercise dataset (build-time)
+ media-script.nix runtime media-fetch shell script
+ version.nix version = "1.2.14" + pinned dataset commit (single source of truth)
+ default.nix package-set aggregator (used by both the flake and the module)
```
+Everything Nix lives under `contrib/nix/` so the flake stays out of the way of the project's own
+build (Docker, CI, the Node packages). The flake reads its sources — `api/`, `frontend/`, `mcp/`
+— from the repository root two levels up, so it must be evaluated *from a checkout of the whole
+repo*, never from a sparse copy of `contrib/nix` alone.
+
## 3. Building and using the packages
Requirements: Nix with flakes enabled (`nix.conf`: `experimental-features = nix-command flakes`).
```bash
-# from a checkout of the repo
+# the flake lives in contrib/nix — start there (from the repo root: nix build ./contrib/nix#… )
+cd contrib/nix
+
nix build .#opengym-frontend # static site → result/share/opengym
nix build .#opengym-api # API → result/bin/opengym-api
nix build .#opengym-mcp
@@ -221,7 +230,8 @@ word-for-word.
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
- opengym.url = "git+https://gitlab.com/DuarteSantos8/opengym";
+ # the flake lives in a subdirectory — ?dir= points at it
+ opengym.url = "github:DuarteSantos8/openGym?dir=contrib/nix";
};
outputs = { self, nixpkgs, opengym, ... }: {
@@ -236,22 +246,26 @@ word-for-word.
}
```
+On the GitLab mirror the same input is
+`"git+https://gitlab.com/DuarteSantos8/opengym?dir=contrib/nix"`.
+
Then `sudo nixos-rebuild switch --flake .#myhost`.
Not using flakes in your NixOS config? You can also `imports` the module file directly from a
checkout of the repo:
```nix
-{ imports = [ "/path/to/opengym/nix/opengym.nix" ]; }
+{ imports = [ "/path/to/opengym/contrib/nix/opengym.nix" ]; }
```
#### Package provenance
When you load the module *through the flake* (`opengym.nixosModules.default`), the default
`services.opengym.package` set is the one built by this flake — from the flake's **locked**
-`nixpkgs` input. Importing `nix/opengym.nix` directly instead falls back to building the packages
-from *your system's* nixpkgs, which may differ slightly. If you ever need a specific set, override
-`services.opengym.package` explicitly (e.g. `opengym.packages.x86_64-linux` from your flake inputs).
+`nixpkgs` input. Importing `contrib/nix/opengym.nix` directly instead falls back to building the
+packages from *your system's* nixpkgs, which may differ slightly. If you ever need a specific set,
+override `services.opengym.package` explicitly (e.g. `opengym.packages.x86_64-linux` from your flake
+inputs).
### Minimal enable (works on `localhost`)
diff --git a/docs/README.md b/docs/README.md
index db092dedc..09f0e65d3 100644
--- a/docs/README.md
+++ b/docs/README.md
@@ -24,6 +24,7 @@ to install.
| [Kubernetes](SELF_HOSTING_KUBERNETES.md) | You run a cluster instead of Docker Compose |
| [AI coach](AI_COACH.md) | You're deciding whether to turn the coach on, and with which provider |
| [MCP server](../mcp/README.md) | You want Claude Desktop, Cursor or another AI client to read your training history |
+| [NixOS](NIX.md) | You run NixOS and want openGym native — flake packages and a NixOS module, no Docker |
| [Security](../SECURITY.md) | You host it for other people, or want to report a vulnerability |
All settings live in `.env`; [`.env.example`](../.env.example) explains each one, and the