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.

feat: default module packages from the flake's locked nixpkgs

gerrydoro992f901471c9
diff --git a/docs/NIX.md b/docs/NIX.md
index 8e15a5710..a0c961e95 100644
--- a/docs/NIX.md
+++ b/docs/NIX.md
@@ -238,6 +238,14 @@ checkout of the repo:
{ imports = [ "/path/to/opengym/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).
+
### Minimal enable (works on `localhost`)
```nix
diff --git a/flake.nix b/flake.nix
index ec42bd44e..0ebcf819b 100644
--- a/flake.nix
+++ b/flake.nix
@@ -110,7 +110,15 @@
}
)
// {
- nixosModules.opengym = import ./nix/opengym.nix;
+ # 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.
+ nixosModules.opengym =
+ { pkgs, ... }:
+ {
+ imports = [ ./nix/opengym.nix ];
+ _module.args.opengymPkgs = self.packages.${pkgs.system} or null;
+ };
nixosModules.default = self.nixosModules.opengym;
};
}
diff --git a/nix/opengym.nix b/nix/opengym.nix
index af1c9537d..f2f1f8b65 100644
--- a/nix/opengym.nix
+++ b/nix/opengym.nix
@@ -2,13 +2,17 @@
config,
lib,
pkgs,
+ # Injected by the flake (see nixosModules.opengym in flake.nix) so module users get the
+ # packages built from the flake's *locked* nixpkgs input. Falls back to this system's pkgs
+ # (via _module.args below) when the module is imported directly (imports = [ …/opengym.nix ]).
+ opengymPkgs,
...
}:
let
cfg = config.services.opengym;
- opengymPkgs = {
+ hostOpengymPkgs = {
opengym-frontend = pkgs.callPackage ./frontend.nix { };
opengym-api = pkgs.callPackage ./api.nix { };
opengym-mcp = pkgs.callPackage ./mcp.nix { };
@@ -16,6 +20,8 @@ let
opengym-fetch-media = pkgs.callPackage ./media-script.nix { };
};
+ defaultOpengymPkgs = if opengymPkgs != null then opengymPkgs else hostOpengymPkgs;
+
packages = cfg.package;
apiEnv = lib.filterAttrs (_: v: v != null) {
@@ -47,8 +53,11 @@ in
package = lib.mkOption {
type = lib.types.attrsOf lib.types.package;
- default = opengymPkgs;
- defaultText = lib.literalExpression "opengym packages built from source";
+ default = defaultOpengymPkgs;
+ defaultText = lib.literalExpression ''
+ the flake's packages (built from its locked nixpkgs) when the module comes from the
+ flake; otherwise built from this system's nixpkgs
+ '';
description = "openGym package set (typically the flake output).";
};
@@ -196,6 +205,11 @@ in
config = lib.mkMerge [
{
+ # Fallback for `opengymPkgs` when the module is imported directly (no flake wrapper):
+ # build the packages from this system's pkgs. The flake's wrapper supplies the same
+ # argument at higher priority with packages from its locked nixpkgs.
+ _module.args.opengymPkgs = lib.mkDefault hostOpengymPkgs;
+
assertions = [
{
assertion = cfg.environment == { } || cfg.environmentFile == "";