diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 000000000..fe32cd232 --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,19 @@ +name: "CI - Nix" + +on: + push: + +jobs: + nix: + runs-on: "${{ matrix.os }}-latest" + strategy: + matrix: + os: [ubuntu, macos] + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v27 + #- uses: cachix/cachix-action@v15 + #with: + #name: sofa + #authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + - run: nix build -L diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..e45599e26 --- /dev/null +++ b/flake.lock @@ -0,0 +1,82 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1727826117, + "narHash": "sha256-K5ZLCyfO/Zj9mPFldf3iwS6oZStJcU4tSpiXTMYaaL0=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "3d04084d54bedc3d6b8b736c70ef449225c361b1", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1728930054, + "narHash": "sha256-mCaSyViQyiLgZKVLpDcVacbPSNjvsBzfWnGaxvhTzs8=", + "owner": "nim65s", + "repo": "nixpkgs", + "rev": "8e906b3e2aa2274c9d0c555393b4801d3c0badee", + "type": "github" + }, + "original": { + "owner": "nim65s", + "ref": "qt6-libqglviewer", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "lastModified": 1727825735, + "narHash": "sha256-0xHYkMkeLVQAMa7gvkddbPqpxph+hDzdu1XdGPJR+Os=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/fb192fec7cc7a4c26d51779e9bab07ce6fa5597a.tar.gz" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "sofa": "sofa" + } + }, + "sofa": { + "inputs": { + "flake-parts": [ + "flake-parts" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1729076781, + "narHash": "sha256-9OWCN3gaJSmwoNtj14g+Se7U5hhoj8ZDaqvmkruDYG8=", + "owner": "nim65s", + "repo": "sofa", + "rev": "8808d2463a93229cc938b1bb29f362c36ba22321", + "type": "github" + }, + "original": { + "owner": "nim65s", + "repo": "sofa", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..281d98745 --- /dev/null +++ b/flake.nix @@ -0,0 +1,53 @@ +{ + description = "Real-time multi-physics simulation with an emphasis on medical simulation."; + + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + #nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + # ref. https://github.com/NixOS/nixpkgs/pull/348549 + nixpkgs.url = "github:nim65s/nixpkgs/qt6-libqglviewer"; + sofa = { + url = "github:nim65s/sofa"; # update this after PR + inputs = { + flake-parts.follows = "flake-parts"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = + inputs: + inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = inputs.nixpkgs.lib.systems.flakeExposed; + perSystem = + { + pkgs, + self', + system, + ... + }: + { + apps.default = { + type = "app"; + program = + pkgs.runCommand "runSofa" + { + nativeBuildInputs = [ pkgs.makeBinaryWrapper ]; + meta.mainProgram = "runSofa"; + } + '' + makeBinaryWrapper ${pkgs.lib.getExe self'.packages.sofa} $out/bin/runSofa \ + --set SOFA_PLUGIN_PATH ${self'.packages.sofa-python3} \ + --set SOFA_ROOT ${self'.packages.sofa} \ + --add-flags "-l SofaPython3" + ''; + }; + devShells.default = pkgs.mkShell { inputsFrom = [ self'.packages.default ]; }; + packages = { + inherit (inputs.sofa.packages.${system}) sofa; + default = self'.packages.sofa-python3; + sofa-python3 = pkgs.callPackage ./package.nix { inherit (self'.packages) sofa; }; + }; + }; + }; +} diff --git a/package.nix b/package.nix new file mode 100644 index 000000000..34d13d31c --- /dev/null +++ b/package.nix @@ -0,0 +1,53 @@ +{ + cmake, + lib, + python3Packages, + qt6Packages, + sofa, + stdenv, +}: + +stdenv.mkDerivation { + pname = "sofa-python3"; + version = "24.06"; + + src = lib.fileset.toSource { + root = ./.; + fileset = lib.fileset.unions [ + ./bindings + ./CMake + ./CMakeLists.txt + ./constants + ./docs + ./examples + ./Plugin + ./SofaPython3Config.cmake.in + ./splib + ./Testing + ]; + }; + + nativeBuildInputs = [ + cmake + qt6Packages.libqglviewer + qt6Packages.wrapQtAppsHook + ]; + propagatedBuildInputs = [ + python3Packages.pybind11 + python3Packages.scipy + sofa + ]; + + # help locate FindQGLViewer.cmake + cmakeFlags = [ + "-DCMAKE_MODULE_PATH=${sofa.src}/cmake/Modules" + ]; + + meta = { + description = "python plugin for Sofa offering a pythonic interface and python3 support"; + homepage = "https://github.com/sofa-framework/SofaPython3"; + license = lib.licenses.lgpl21Only; + maintainers = with lib.maintainers; [ nim65s ]; + platforms = lib.platforms.unix ++ lib.platforms.windows; + }; +}