From 60090a9e0f5f536bea0e715a1485e5ac1d0b7a6e Mon Sep 17 00:00:00 2001 From: kanarus Date: Thu, 16 Jul 2026 19:17:57 +0900 Subject: [PATCH 1/4] chore: introduce nix --- .envrc | 1 + flake.lock | 115 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 49 +++++++++++++++++++++++ 3 files changed, 165 insertions(+) create mode 100644 .envrc create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..bc0f4a9 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake path:. diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..e41e656 --- /dev/null +++ b/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1782949081, + "narHash": "sha256-vp6Y/Grm98ESt6ceOkWiHWyZRDV3J1RID4w+6NWK9yA=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "17c9d6cdfc60c64f4ee8d306f9bc0b4ccb51481e", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1784007870, + "narHash": "sha256-djcLt/JJphyNt4eDY9XTly+/WbCK5lqWq9lSgCmJkkQ=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "18b9261cb3294b6d2a06d03f96872827b8fe2698", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1782614948, + "narHash": "sha256-ePjCwr1sNm9NYUqywL7QfK3JnlS015msC+eBu2zKlp8=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "db3f255737b94216eb71cce308e2912cf6bc2d7c", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixpkgs-pin-mujoco-3_10_0": { + "locked": { + "lastModified": 1782169413, + "narHash": "sha256-OemhXzlWI9ZximP9Hbd8eXi9gmRmCGzoxp4DtVO1pbU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "775bdd0467f3de2fb5017830d00fa1f573b2ecda", + "type": "github" + }, + "original": { + "owner": "nixos", + "repo": "nixpkgs", + "rev": "775bdd0467f3de2fb5017830d00fa1f573b2ecda", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "nixpkgs-pin-mujoco-3_10_0": "nixpkgs-pin-mujoco-3_10_0", + "rust-overlay": "rust-overlay", + "systems": "systems" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1784091390, + "narHash": "sha256-aILAwrBQPhKldL98N8lmsbfst3OPtbMM4vT2VXn40/Y=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a7887636a3959168bd1ba7ef24a8a70b168dcb56", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..f59b0db --- /dev/null +++ b/flake.nix @@ -0,0 +1,49 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixpkgs-pin-mujoco-3_10_0.url = "github:nixos/nixpkgs/775bdd0467f3de2fb5017830d00fa1f573b2ecda"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = inputs@{ + flake-parts, + systems, + ... + }: flake-parts.lib.mkFlake { inherit inputs; } { + systems = import systems; + perSystem = { + system, + pkgs, + pkgs-pin-mujoco-3_10_0, + ... + }: { + _module.args = { + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ (inputs.rust-overlay.overlays.default) ]; + }; + pkgs-pin-mujoco-3_10_0 = import inputs.nixpkgs-pin-mujoco-3_10_0 { + inherit system; + }; + }; + devShells.default = + let + rustToolchain = pkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" ]; + }; + mujoco-3_10_0 = pkgs-pin-mujoco-3_10_0.mujoco; + in + pkgs.mkShell { + RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + MUJOCO_LIB = "${mujoco-3_10_0}/lib"; + packages = [ rustToolchain ] ++ (with pkgs; [ + ]); + }; + }; + }; +} From 6a7bfbdbbe02e60c84a5accabde7f24e193d5c54 Mon Sep 17 00:00:00 2001 From: kanarus Date: Thu, 16 Jul 2026 19:24:24 +0900 Subject: [PATCH 2/4] update README --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fe0cf32..96d34c4 100644 --- a/README.md +++ b/README.md @@ -39,7 +39,7 @@ ### Note / Tips -- For example on x86_64 Linux, run: +- For example on typical x86_64 Linux, run: ```sh wget https://github.com/google-deepmind/mujoco/releases/download/3.10.0/mujoco-3.10.0-linux-x86_64.tar.gz tar -xzf mujoco-3.10.0-linux-x86_64.tar.gz @@ -61,11 +61,13 @@ export LD_LIBRARY_PATH="$MUJOCO_LIB:$LD_LIBRARY_PATH" ``` -- Or, you can get MuJoCo library through Python toolchain like `uv` or `pip`. - +- Or, you can get MuJoCo library through Nix, or Python toolchain like `uv` or `pip`. + - Depending on your setting, be sure to specify `$MUJOCO_LIB` as shared library path when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_LIB cargo run` on Linux) +- For Nix user: refer to [rusty_mujoco repo's flake.nix](https://github.com/rust-control/rusty_mujoco/blob/main/flake.nix) as an example for setting up specific version of MuJoCo. + ## Example ```toml From 8b8aeb8cade1bfae3713ec06862980d5761963f1 Mon Sep 17 00:00:00 2001 From: kanarus Date: Thu, 16 Jul 2026 19:28:03 +0900 Subject: [PATCH 3/4] update README --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 96d34c4..889567b 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ - Depending on your setting, be sure to specify `$MUJOCO_LIB` as shared library path when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_LIB cargo run` on Linux) -- For Nix user: refer to [rusty_mujoco repo's flake.nix](https://github.com/rust-control/rusty_mujoco/blob/main/flake.nix) as an example for setting up specific version of MuJoCo. +- For Nix user: Refer to [rusty_mujoco repo's flake.nix](https://github.com/rust-control/rusty_mujoco/blob/main/flake.nix) as an example for setting up specific version of MuJoCo and `MUJOCO_LIB`. ## Example From 9600eec4eb1d67848af2babd78ffa7e2cd318d26 Mon Sep 17 00:00:00 2001 From: kanarus Date: Thu, 16 Jul 2026 20:26:53 +0900 Subject: [PATCH 4/4] example works on NixOS --- README.md | 2 +- examples/README.md | 7 ++++--- flake.nix | 10 +++++++++- 3 files changed, 14 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 889567b..04a3532 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ - Depending on your setting, be sure to specify `$MUJOCO_LIB` as shared library path when executing your app (for example `LD_LIBRARY_PATH=$MUJOCO_LIB cargo run` on Linux) -- For Nix user: Refer to [rusty_mujoco repo's flake.nix](https://github.com/rust-control/rusty_mujoco/blob/main/flake.nix) as an example for setting up specific version of MuJoCo and `MUJOCO_LIB`. +- For Nix user: Refer to [rusty_mujoco repo's flake.nix](https://github.com/rust-control/rusty_mujoco/blob/main/flake.nix) as an example for the Nix-way to setup specific version of MuJoCo, `MUJOCO_LIB`, or `glfw` or other depending packages for executable app. ## Example diff --git a/examples/README.md b/examples/README.md index 34d63cd..5db139c 100644 --- a/examples/README.md +++ b/examples/README.md @@ -8,14 +8,15 @@ This example leaves a single object in the scene and visualizes it. - Of course [`rusty_mujoco` Requirements](https://github.com/rust-control/rusty_mujoco?tab=readme-ov-file#requirements) - Additionally [`glfw` Prerequisites](https://github.com/PistonDevelopers/glfw-rs?tab=readme-ov-file#prerequisites) + - (NOTE: This is already configured if you setup with `flake.nix`) ### Usage Pass the path to a MuJoCo model XML file as an argument. For example, -you can use the `humanoid.xml` model provided by MuJoCo: +you may use the `humanoid.xml` model provided by MuJoCo: ```sh -cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid/humanoid.xml +cargo run --example visualize_left_object -- $MUJOCO_LIB/../share/mujoco/model/humanoid/humanoid.xml ``` *(replace the path to humanoid.xml with yours)* @@ -35,5 +36,5 @@ Depending on your setting, you may need to specify: like: ```sh -LD_LIBRARY_PATH="$MUJOCO_LIB" cargo run --example visualize_left_object -- $MUJOCO_LIB/../model/humanoid.xml +LD_LIBRARY_PATH="$MUJOCO_LIB" cargo run --example visualize_left_object -- $MUJOCO_LIB/../share/mujoco/model/humanoid/humanoid.xml ``` diff --git a/flake.nix b/flake.nix index f59b0db..1d7dbc1 100644 --- a/flake.nix +++ b/flake.nix @@ -40,8 +40,16 @@ in pkgs.mkShell { RUST_SRC_PATH = "${rustToolchain}/lib/rustlib/src/rust/library"; + RUSTFLAGS = pkgs.lib.optionalString pkgs.stdenv.isLinux "-C link-arg=-fuse-ld=bfd"; MUJOCO_LIB = "${mujoco-3_10_0}/lib"; - packages = [ rustToolchain ] ++ (with pkgs; [ + packages = [ + rustToolchain + ] ++ (with pkgs-pin-mujoco-3_10_0; [ + pkg-config + glfw3 + ]) ++ pkgs.lib.optionals pkgs.stdenv.isLinux (with pkgs-pin-mujoco-3_10_0; [ + libx11 + wayland ]); }; };