From b9156eabae3e89c1dfff2a5f4714f3cc47d42b73 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Fri, 11 Oct 2024 18:33:25 +0200 Subject: [PATCH 1/4] [Nix] initial packaging & flake --- flake.lock | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 51 +++++++++++++++++++++++++++++++++ package.nix | 53 ++++++++++++++++++++++++++++++++++ 3 files changed, 186 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 package.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..07f60c5d6 --- /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": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "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": 1728665652, + "narHash": "sha256-x/glIS3Amec9SOP6kSuMC2eAz8QGy65/iUszPV9fKGQ=", + "owner": "nim65s", + "repo": "sofa", + "rev": "58ae0644d117aea880ed284f6cc0beb7e9802f96", + "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..37cda56aa --- /dev/null +++ b/flake.nix @@ -0,0 +1,51 @@ +{ + 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"; + 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..8bedfd2a2 --- /dev/null +++ b/package.nix @@ -0,0 +1,53 @@ +{ + cmake, + lib, + libsForQt5, + python3Packages, + 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 + libsForQt5.libqglviewer + libsForQt5.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; + }; +} From 85ca3fb4b9f199c51a6d7c5e68ec0446469773a1 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Sat, 12 Oct 2024 16:00:37 +0200 Subject: [PATCH 2/4] [Nix] setup CI --- .github/workflows/nix.yml | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 .github/workflows/nix.yml diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml new file mode 100644 index 000000000..acbf25bbf --- /dev/null +++ b/.github/workflows/nix.yml @@ -0,0 +1,20 @@ +name: "CI - Nix" + +on: + push: + +jobs: + nix: + runs-on: "${{ matrix.os }}-latest" + strategy: + matrix: + #os: [ubuntu, macos] + os: [ubuntu] + 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 From f213609b2f14091f82fb87d693bce3ab6ed1e883 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Mon, 14 Oct 2024 19:17:31 +0200 Subject: [PATCH 3/4] [Nix] Qt5 -> Qt6 --- flake.lock | 18 +++++++++--------- flake.nix | 4 +++- package.nix | 6 +++--- 3 files changed, 15 insertions(+), 13 deletions(-) diff --git a/flake.lock b/flake.lock index 07f60c5d6..e45599e26 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1728492678, - "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", - "owner": "NixOS", + "lastModified": 1728930054, + "narHash": "sha256-mCaSyViQyiLgZKVLpDcVacbPSNjvsBzfWnGaxvhTzs8=", + "owner": "nim65s", "repo": "nixpkgs", - "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "rev": "8e906b3e2aa2274c9d0c555393b4801d3c0badee", "type": "github" }, "original": { - "owner": "NixOS", - "ref": "nixos-unstable", + "owner": "nim65s", + "ref": "qt6-libqglviewer", "repo": "nixpkgs", "type": "github" } @@ -63,11 +63,11 @@ ] }, "locked": { - "lastModified": 1728665652, - "narHash": "sha256-x/glIS3Amec9SOP6kSuMC2eAz8QGy65/iUszPV9fKGQ=", + "lastModified": 1729076781, + "narHash": "sha256-9OWCN3gaJSmwoNtj14g+Se7U5hhoj8ZDaqvmkruDYG8=", "owner": "nim65s", "repo": "sofa", - "rev": "58ae0644d117aea880ed284f6cc0beb7e9802f96", + "rev": "8808d2463a93229cc938b1bb29f362c36ba22321", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 37cda56aa..281d98745 100644 --- a/flake.nix +++ b/flake.nix @@ -3,7 +3,9 @@ inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + #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 = { diff --git a/package.nix b/package.nix index 8bedfd2a2..34d13d31c 100644 --- a/package.nix +++ b/package.nix @@ -1,8 +1,8 @@ { cmake, lib, - libsForQt5, python3Packages, + qt6Packages, sofa, stdenv, }: @@ -29,8 +29,8 @@ stdenv.mkDerivation { nativeBuildInputs = [ cmake - libsForQt5.libqglviewer - libsForQt5.wrapQtAppsHook + qt6Packages.libqglviewer + qt6Packages.wrapQtAppsHook ]; propagatedBuildInputs = [ python3Packages.pybind11 From b1de8579a06941c99ba73f226aee8e05cc962e08 Mon Sep 17 00:00:00 2001 From: Guilhem Saurel Date: Wed, 16 Oct 2024 13:10:39 +0200 Subject: [PATCH 4/4] [Nix] CI on macos too --- .github/workflows/nix.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/nix.yml b/.github/workflows/nix.yml index acbf25bbf..fe32cd232 100644 --- a/.github/workflows/nix.yml +++ b/.github/workflows/nix.yml @@ -8,8 +8,7 @@ jobs: runs-on: "${{ matrix.os }}-latest" strategy: matrix: - #os: [ubuntu, macos] - os: [ubuntu] + os: [ubuntu, macos] steps: - uses: actions/checkout@v4 - uses: cachix/install-nix-action@v27