From f5e484111ea5c475637b4749b36bba90be07dcc9 Mon Sep 17 00:00:00 2001 From: shivaraj-bh Date: Fri, 22 Mar 2024 04:34:03 +0530 Subject: [PATCH] grafana: fix the darwin build failure * use xcbuild.xcbuild, which is dep for @esfx/equatable; fix 'aligned_alloc' error * frontend's offlineCache: don't allow platforms other than the one's mentioned in `meta.platforms` --- pkgs/servers/monitoring/grafana/default.nix | 29 ++++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/pkgs/servers/monitoring/grafana/default.nix b/pkgs/servers/monitoring/grafana/default.nix index d4812c449653..205c32f76886 100644 --- a/pkgs/servers/monitoring/grafana/default.nix +++ b/pkgs/servers/monitoring/grafana/default.nix @@ -2,7 +2,7 @@ , tzdata, wire , yarn, nodejs, python3, cacert , jq, moreutils -, nix-update-script, nixosTests +, nix-update-script, nixosTests, xcbuild }: let @@ -32,13 +32,21 @@ buildGoModule rec { hash = "sha256-Rp2jGspbmqJFzSbiVy2/5oqQJnAdGG/T+VNBHVsHSwg="; }; + # borrowed from: https://github.com/NixOS/nixpkgs/blob/d70d9425f49f9aba3c49e2c389fe6d42bac8c5b0/pkgs/development/tools/analysis/snyk/default.nix#L20-L22 + env = lib.optionalAttrs (stdenv.isDarwin && stdenv.isx86_64) { + # Fix error: no member named 'aligned_alloc' in the global namespace. + # Occurs while building @esfx/equatable@npm:1.0.2 on x86_64-darwin + NIX_CFLAGS_COMPILE = "-D_LIBCPP_HAS_NO_LIBRARY_ALIGNED_ALLOCATION=1"; + }; + offlineCache = stdenv.mkDerivation { name = "${pname}-${version}-yarn-offline-cache"; - inherit src; + inherit src env; nativeBuildInputs = [ yarn nodejs cacert jq moreutils python3 - ]; + # @esfx/equatable@npm:1.0.2 fails to build on darwin as it requires `xcbuild` + ] ++ lib.optionals stdenv.isDarwin [ xcbuild.xcbuild ]; postPatch = '' ${patchAwayGrafanaE2E} ''; @@ -47,7 +55,7 @@ buildGoModule rec { export HOME="$(mktemp -d)" yarn config set enableTelemetry 0 yarn config set cacheFolder $out - yarn config set --json supportedArchitectures.os '[ "linux" ]' + yarn config set --json supportedArchitectures.os '[ "linux", "darwin" ]' yarn config set --json supportedArchitectures.cpu '["arm", "arm64", "ia32", "x64"]' yarn runHook postBuild @@ -56,14 +64,21 @@ buildGoModule rec { dontInstall = true; dontFixup = true; outputHashMode = "recursive"; - outputHash = "sha256-QdyXSPshzugkDTJoUrJlHNuhPAyR9gae5Cbk8Q8FSl4="; + outputHash = rec { + x86_64-linux = "sha256-3CZgs732c6Z64t2sfWjPAmMFKVTzoolv2TwrbjeRCBA="; + aarch64-linux = x86_64-linux; + aarch64-darwin = "sha256-NKEajOe9uDZw0MF5leiKBIRH1CHUELRho7gyCa96BO8="; + x86_64-darwin = aarch64-darwin; + }.${stdenv.hostPlatform.system} or (throw "Unsupported system: ${stdenv.hostPlatform.system}"); }; disallowedRequisites = [ offlineCache ]; - vendorHash = "sha256-cNkMVLXp3hPMcW0ilOM0VlrrDX/IsZaze+/6qlTfmRs="; + vendorHash = "sha256-puPgbgfRqbPvMVks+gyOPOTTfdClWqbOf89X0ihMLPY="; - nativeBuildInputs = [ wire yarn jq moreutils removeReferencesTo python3 ]; + proxyVendor = true; + + nativeBuildInputs = [ wire yarn jq moreutils removeReferencesTo python3 ] ++ lib.optionals stdenv.isDarwin [ xcbuild.xcbuild ]; postPatch = '' ${patchAwayGrafanaE2E}