From 658e71cd9f80ddb0e2db932142e301afaaae7bca Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Wed, 30 Aug 2023 10:27:43 +0300 Subject: balena-cli: 16.7.6 -> 17.0.0 Since upstream now supports nodejs18, we can use buildNpmPackage and build it completely from source. See also: https://github.com/balena-io/balena-cli/issues/2620 . Also, add doronbehar as maintainer. --- pkgs/tools/admin/balena-cli/default.nix | 106 +++++++++----------------------- 1 file changed, 30 insertions(+), 76 deletions(-) diff --git a/pkgs/tools/admin/balena-cli/default.nix b/pkgs/tools/admin/balena-cli/default.nix index 827d4e162b51d..c687eb994d943 100644 --- a/pkgs/tools/admin/balena-cli/default.nix +++ b/pkgs/tools/admin/balena-cli/default.nix @@ -1,47 +1,43 @@ { lib , stdenv -, fetchzip +, buildNpmPackage +, fetchFromGitHub , testers +, balena-cli +, nodePackages +, python3 +, udev }: -let - inherit (stdenv.hostPlatform) system; - throwSystem = throw "Unsupported system: ${system}"; - plat = { - x86_64-linux = "linux-x64"; - x86_64-darwin = "macOS-x64"; - # Balena only packages for x86 so we rely on Rosetta for Apple Silicon - aarch64-darwin = "macOS-x64"; - }.${system} or throwSystem; - - sha256 = { - x86_64-linux = "sha256-USljQ/cnbSabzsZWXlZ0eeZSqkTr3wVP0ktXqZ7Fw4U="; - x86_64-darwin = "sha256-NWzJPB+HzlsB6yTcEMwTg8pioonGWPOU96jyIpiZiTY="; - aarch64-darwin = "sha256-NWzJPB+HzlsB6yTcEMwTg8pioonGWPOU96jyIpiZiTY="; - }.${system} or throwSystem; - - version = "16.7.6"; - src = fetchzip { - url = "https://github.com/balena-io/balena-cli/releases/download/v${version}/balena-cli-v${version}-${plat}-standalone.zip"; - inherit sha256; - }; -in -stdenv.mkDerivation (finalAttrs: { +buildNpmPackage rec { pname = "balena-cli"; - inherit version src; + version = "17.0.0"; - installPhase = '' - runHook preInstall + src = fetchFromGitHub { + owner = "balena-io"; + repo = "balena-cli"; + rev = "v${version}"; + hash = "sha256-sNpxjSumiP+4fX6b3j+HEl/lr4pvudrhfTzr2TYastE="; + }; - mkdir -p $out/bin - cp -r ./* $out/ - ln -s $out/balena $out/bin/balena + npmDepsHash = "sha256-q2Yc6e5dEiP2Q4tFIeqj4mswM1/pX1pdGeoagyiupvs="; - runHook postInstall + postPatch = '' + ln -s npm-shrinkwrap.json package-lock.json ''; + makeCacheWritable = true; + + nativeBuildInputs = [ + nodePackages.node-gyp + python3 + ]; + + buildInputs = lib.optionals (!stdenv.isDarwin) [ + udev + ]; passthru.tests.version = testers.testVersion { - package = finalAttrs.finalPackage; + package = balena-cli; command = '' # Override default cache directory so Balena CLI's unavoidable update check does not fail due to write permissions BALENARC_DATA_DIRECTORY=./ balena --version @@ -49,46 +45,6 @@ stdenv.mkDerivation (finalAttrs: { inherit version; }; - # https://github.com/NixOS/nixpkgs/pull/48193/files#diff-b65952dbe5271c002fbc941b01c3586bf5050ad0e6aa6b2fcc74357680e103ea - preFixup = - if stdenv.isLinux then - let - libPath = lib.makeLibraryPath [ stdenv.cc.cc ]; - in - '' - orig_size=$(stat --printf=%s $out/balena) - patchelf --set-interpreter "$(cat $NIX_CC/nix-support/dynamic-linker)" $out/balena - patchelf --set-rpath ${libPath} $out/balena - chmod +x $out/balena - new_size=$(stat --printf=%s $out/balena) - ###### zeit-pkg fixing starts here. - # we're replacing plaintext js code that looks like - # PAYLOAD_POSITION = '1234 ' | 0 - # [...] - # PRELUDE_POSITION = '1234 ' | 0 - # ^-----20-chars-----^^------22-chars------^ - # ^-- grep points here - # - # var_* are as described above - # shift_by seems to be safe so long as all patchelf adjustments occur - # before any locations pointed to by hardcoded offsets - var_skip=20 - var_select=22 - shift_by=$(expr $new_size - $orig_size) - function fix_offset { - # $1 = name of variable to adjust - location=$(grep -obUam1 "$1" $out/bin/balena | cut -d: -f1) - location=$(expr $location + $var_skip) - value=$(dd if=$out/balena iflag=count_bytes,skip_bytes skip=$location \ - bs=1 count=$var_select status=none) - value=$(expr $shift_by + $value) - echo -n $value | dd of=$out/balena bs=1 seek=$location conv=notrunc - } - fix_offset PAYLOAD_POSITION - fix_offset PRELUDE_POSITION - '' else ''''; - dontStrip = true; - meta = with lib; { description = "A command line interface for balenaCloud or openBalena"; longDescription = '' @@ -100,9 +56,7 @@ stdenv.mkDerivation (finalAttrs: { homepage = "https://github.com/balena-io/balena-cli"; changelog = "https://github.com/balena-io/balena-cli/blob/v${version}/CHANGELOG.md"; license = licenses.asl20; - maintainers = [ maintainers.kalebpace ]; - platforms = platforms.linux ++ platforms.darwin; - sourceProvenance = [ sourceTypes.binaryNativeCode ]; + maintainers = [ maintainers.kalebpace maintainers.doronbehar ]; mainProgram = "balena"; }; -}) +} -- cgit 1.4.1 From 7afe4e3282a9a5fbce0729ad68843fc0572247b5 Mon Sep 17 00:00:00 2001 From: Doron Behar Date: Thu, 31 Aug 2023 09:30:27 +0300 Subject: balena-cli: Fix darwin build --- pkgs/tools/admin/balena-cli/default.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pkgs/tools/admin/balena-cli/default.nix b/pkgs/tools/admin/balena-cli/default.nix index c687eb994d943..bb674a83f3221 100644 --- a/pkgs/tools/admin/balena-cli/default.nix +++ b/pkgs/tools/admin/balena-cli/default.nix @@ -7,6 +7,7 @@ , nodePackages , python3 , udev +, darwin }: buildNpmPackage rec { @@ -30,10 +31,15 @@ buildNpmPackage rec { nativeBuildInputs = [ nodePackages.node-gyp python3 + ] ++ lib.optionals stdenv.isDarwin [ + darwin.cctools ]; - buildInputs = lib.optionals (!stdenv.isDarwin) [ + buildInputs = lib.optionals stdenv.isLinux [ udev + ] ++ lib.optionals stdenv.isDarwin [ + darwin.apple_sdk.frameworks.Foundation + darwin.apple_sdk.frameworks.Cocoa ]; passthru.tests.version = testers.testVersion { -- cgit 1.4.1