From ab4cbcd01a498041c931442d53c81012c3a8e23a Mon Sep 17 00:00:00 2001 From: Jon Ringer Date: Sun, 26 Feb 2023 15:20:12 -0800 Subject: [PATCH] Enable darwin builds in Nix for olm From 04f1249a66e75e91ef009ed04304cbc88dea798d Mon Sep 17 00:00:00 2001 From: Jonathan Ringer Date: Sun, 26 Feb 2023 15:14:23 -0800 Subject: [PATCH] Enable darwin builds in Nix Move most packaging concerns into nix/overlay.nix. Alter packaging to mostly align with nixpkgs best practices. Signed-off-by: Jonathan Ringer --- flake.nix | 142 ++++++++---------------------------------------- nix/overlay.nix | 76 ++++++++++++++++++++++++++ 2 files changed, 99 insertions(+), 119 deletions(-) create mode 100644 nix/overlay.nix diff --git a/flake.nix b/flake.nix index c79a322..e606692 100644 --- a/flake.nix +++ b/flake.nix @@ -11,126 +11,30 @@ }; outputs = { self, nixpkgs, flake-utils, npmlock2nix }: - ( + let + localOverlay = import ./nix/overlay.nix; + pkgsForSystem = system: import nixpkgs { + inherit system; + overlays = [ + (final: prev: { + npmlock2nix = final.callPackage npmlock2nix {}; + node_modules = final.npmlock2nix.node_modules { src = ./javascript; }; + }) + localOverlay + ]; + }; + in ( # some systems cause issues, e.g. i686-linux is unsupported by gradle, # which causes "nix flake check" to fail. Investigate more later, but for # now, we will just allow x86_64-linux - flake-utils.lib.eachSystem [ "x86_64-linux" ] (system: - let - pkgs = import nixpkgs { - inherit system; - overlays = [ - (final: prev: { - npmlock2nix = final.callPackage npmlock2nix {}; - }) - ]; - }; - node_modules = pkgs.npmlock2nix.node_modules { src = ./javascript; }; - in - rec { - checks.gcc-cmake = pkgs.gccStdenv.mkDerivation { - name = "olm"; - - buildInputs = [ pkgs.cmake ]; - - src = ./.; - - buildPhase = '' - cmake . -Bbuild - cmake --build build - ''; - - doCheck = true; - checkPhase = '' - cd build/tests - ctest . - cd ../.. - ''; - }; - - checks.clang-cmake = pkgs.clangStdenv.mkDerivation { - name = "olm"; - - buildInputs = [ pkgs.cmake ]; - - src = ./.; - - buildPhase = '' - cmake . -Bbuild - cmake --build build - ''; - - doCheck = true; - checkPhase = '' - cd build/tests - ctest . - cd ../.. - ''; - }; - - checks.gcc-make = pkgs.gccStdenv.mkDerivation { - name = "olm"; - - src = ./.; - - buildPhase = '' - make - ''; - - doCheck = true; - checkPhase = '' - make test - ''; - - installPhase = '' - make install PREFIX=$out - ''; - }; - - packages.javascript = pkgs.buildEmscriptenPackage { - pname = "olm"; - inherit (builtins.fromJSON (builtins.readFile ./javascript/package.json)) version; - - buildInputs = with pkgs; [ gnumake python3 nodejs ]; - - src = ./.; - - postPatch = '' - patchShebangs . - ''; - - configurePhase = ""; - - buildPhase = '' - export EM_CACHE=$TMPDIR - make javascript/exported_functions.json - make js - ''; - - output = [ "out" ]; - - installPhase = '' - mkdir -p $out/javascript - cd javascript - echo sha256: > checksums.txt - sha256sum olm.js olm_legacy.js olm.wasm >> checksums.txt - echo sha512: >> checksums.txt - sha512sum olm.js olm_legacy.js olm.wasm >> checksums.txt - cp package.json olm.js olm.wasm olm_legacy.js index.d.ts README.md checksums.txt $out/javascript - cd .. - ''; - - checkPhase = '' - cd javascript - export HOME=$TMPDIR - ln -s ${node_modules}/node_modules ./node_modules - npm test - cd .. - ''; - }; - - packages.default = packages.javascript; - } - ) - ); + flake-utils.lib.eachSystem [ "x86_64-linux" "x86_64-darwin" "aarch64-darwin" ] (system: rec { + legacyPackages = pkgsForSystem system; + checks = { + inherit (legacyPackages) olm-gcc-cmake olm-clang-cmake olm-gcc-make; + }; + packages = { + javascript = legacyPackages.olm-javascript; + }; + } + )); } diff --git a/nix/overlay.nix b/nix/overlay.nix new file mode 100644 index 0000000..f8ec5f2 --- /dev/null +++ b/nix/overlay.nix @@ -0,0 +1,76 @@ +final: prev: { + olm-gcc-cmake = prev.gccStdenv.mkDerivation { + name = "olm_gcc_cmake"; + + src = ./..; + + nativeBuildInputs = [ prev.cmake ]; + doCheck = true; + checkPhase = '' + (cd tests && ctest . -j $NIX_BUILD_CORES) + ''; + }; + + olm-clang-cmake = prev.clangStdenv.mkDerivation { + name = "olm_clang_cmake"; + + src = ./..; + + nativeBuildInputs = [ prev.cmake ]; + + doCheck = true; + checkPhase = '' + (cd tests && ctest . -j $NIX_BUILD_CORES) + ''; + }; + + olm-gcc-make = prev.gccStdenv.mkDerivation { + name = "olm"; + + src = ./..; + + doCheck = true; + makeFlags = [ "PREFIX=$out" ]; + }; + + olm-javascript = final.buildEmscriptenPackage { + pname = "olm_javascript"; + inherit (builtins.fromJSON (builtins.readFile ../javascript/package.json)) version; + + src = ./..; + + nativeBuildInputs = with prev; [ gnumake python3 nodejs ]; + + postPatch = '' + patchShebangs . + ''; + + configurePhase = false; + + buildPhase = '' + export EM_CACHE=$TMPDIR + make javascript/exported_functions.json + make js + ''; + + installPhase = '' + mkdir -p $out/javascript + cd javascript + echo sha256: > checksums.txt + sha256sum olm.js olm_legacy.js olm.wasm >> checksums.txt + echo sha512: >> checksums.txt + sha512sum olm.js olm_legacy.js olm.wasm >> checksums.txt + cp package.json olm.js olm.wasm olm_legacy.js index.d.ts README.md checksums.txt $out/javascript + cd .. + ''; + + checkPhase = '' + cd javascript + export HOME=$TMPDIR + ln -s ${final.node_modules}/node_modules ./node_modules + npm test + cd .. + ''; + }; + +}