diff --git a/pkgs/by-name/po/positron-bin/package.nix b/pkgs/by-name/po/positron-bin/package.nix new file mode 100644 index 00000000000000..0c8f91c5eaf794 --- /dev/null +++ b/pkgs/by-name/po/positron-bin/package.nix @@ -0,0 +1,139 @@ +{ + lib, + _7zz, + alsa-lib, + systemd, + autoPatchelfHook, + blas, + dpkg, + fetchurl, + gtk3, + libglvnd, + libxkbcommon, + makeShellWrapper, + mesa, + musl, + nss, + patchelf, + stdenv, + xorg, +}: +let + pname = "positron-bin"; + version = "2024.11.0-116"; +in +stdenv.mkDerivation { + inherit version pname; + + src = + if (stdenv.isDarwin) then + fetchurl { + url = "https://github.com/posit-dev/positron/releases/download/${version}/Positron-${version}.dmg"; + hash = "sha256-5Ym42InDgFLGdZk0LYV1H0eC5WzmsYToG1KLdiGgTto="; + } + else + fetchurl { + url = "https://github.com/posit-dev/positron/releases/download/${version}/Positron-${version}.deb"; + hash = "sha256-pE25XVYFW8WwyQ7zmox2mmXy6ZCSaXk2gSnPimg7xtU="; + }; + + buildInputs = + [ makeShellWrapper ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + alsa-lib + dpkg + gtk3 + libglvnd + libxkbcommon + mesa + musl + nss + stdenv.cc.cc + xorg.libX11 + xorg.libXcomposite + xorg.libXdamage + xorg.libxkbfile + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + blas + patchelf + ]; + + nativeBuildInputs = + lib.optionals stdenv.hostPlatform.isLinux [ + autoPatchelfHook + ] + ++ lib.optionals stdenv.hostPlatform.isDarwin [ + _7zz + ]; + + runtimeDependencies = lib.optionals stdenv.hostPlatform.isLinux [ + # Needed to fix the "Zygote could not fork" error. + (lib.getLib systemd) + ]; + + unpackPhase = '' + runHook preUnpack + ${builtins.toString ( + lib.optionals stdenv.hostPlatform.isLinux ''dpkg-deb --fsys-tarfile "$src" | tar -x --no-same-owner'' + )} + runHook postUnpack + ''; + + installPhase = + if stdenv.hostPlatform.isDarwin then + '' + runHook preInstall + mkdir -p "$out/Applications" "$out/bin" + cp -r . "$out/Applications/Positron.app" + + # Positron will use the system version of BLAS if we don't provide the nix version. + wrapProgram "$out/Applications/Positron.app/Contents/Resources/app/bin/code" \ + --prefix DYLD_INSERT_LIBRARIES : "${lib.makeLibraryPath [ blas ]}/libblas.dylib" + + ln -s "$out/Applications/Positron.app/Contents/Resources/app/bin/code" "$out/bin/positron" + runHook postInstall + '' + else + '' + runHook preInstall + mkdir -p "$out/share" + cp -r usr/share/pixmaps "$out/share/pixmaps" + cp -r usr/share/positron "$out/share/positron" + + mkdir -p "$out/share/applications" + install -m 444 -D usr/share/applications/positron.desktop "$out/share/applications/positron.desktop" + substituteInPlace "$out/share/applications/positron.desktop" \ + --replace-fail \ + "Icon=com.visualstudio.code.oss" \ + "Icon=$out/share/pixmaps/com.visualstudio.code.oss.png" \ + --replace-fail \ + "Exec=/usr/share/positron/positron %F" \ + "Exec=$out/share/positron/.positron-wrapped %F" \ + --replace-fail \ + "/usr/share/positron/positron --new-window %F" \ + "$out/share/positron/.positron-wrapped --new-window %F" + + # Fix libGL.so not found errors. + wrapProgram "$out/share/positron/positron" \ + --prefix LD_LIBRARY_PATH : "${lib.makeLibraryPath [ libglvnd ]}" + + mkdir -p "$out/bin" + ln -s "$out/share/positron/positron" "$out/bin/positron" + runHook postInstall + ''; + + passthru.updateScript = ./update.sh; + + meta = with lib; { + description = "Positron, a next-generation data science IDE"; + homepage = "https://github.com/posit-dev/positron"; + license = licenses.elastic20; + maintainers = with maintainers; [ + b-rodrigues + detroyejr + ]; + mainProgram = "positron"; + platforms = [ "x86_64-linux" ] ++ platforms.darwin; + }; +} diff --git a/pkgs/by-name/po/positron-bin/update.sh b/pkgs/by-name/po/positron-bin/update.sh new file mode 100755 index 00000000000000..28081f589ec996 --- /dev/null +++ b/pkgs/by-name/po/positron-bin/update.sh @@ -0,0 +1,54 @@ +#!/usr/bin/env nix-shell +#! nix-shell -i bash -p curl jq git + +nixpkgs="$(git rev-parse --show-toplevel)" +positron_nix="$nixpkgs/pkgs/by-name/po/positron-bin/package.nix" + +current_version=$(grep -oP "version = \"\K.*\d" $positron_nix) +new_version=$(curl -sSfL \ + -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + "https://api.github.com/repos/posit-dev/positron/releases?per_page=1" \ + | jq -r '.[0].name') + +if [[ "$new_version" == "$current_version" ]]; then + echo 'Positron is already up to date' + exit 0; +fi + +# Update Darwin hash. +current_hash=$(nix store prefetch-file --json --hash-type sha256 \ + "https://github.com/posit-dev/positron/releases/download/${current_version}/Positron-${current_version}.dmg" \ + | jq -r .hash) + +new_hash=$(nix store prefetch-file --json --hash-type sha256 \ + "https://github.com/posit-dev/positron/releases/download/${new_version}/Positron-${new_version}.dmg" \ + | jq -r .hash) + +sed -i "s|$current_hash|$new_hash|g" $positron_nix + +# Update Linux hash. +current_hash=$(nix store prefetch-file --json --hash-type sha256 \ + "https://github.com/posit-dev/positron/releases/download/${current_version}/Positron-${current_version}.deb" \ + | jq -r .hash) + +new_hash=$(nix store prefetch-file --json --hash-type sha256 \ + "https://github.com/posit-dev/positron/releases/download/${new_version}/Positron-${new_version}.deb" \ + | jq -r .hash) + +sed -i "s|$current_hash|$new_hash|g" $positron_nix + +# Update version +sed -i "s|$current_version|$new_version|g" $positron_nix + +# Attempt to build. +export NIXPKGS_ALLOW_UNFREE=1 + +if ! nix-build -A positron-bin "$nixpkgs"; then + echo "The updated positron-bin failed to build." + exit 1 +fi + +# Commit changes +git add "$positron_nix" +git commit -m "positron-bin: ${current_version} -> ${new_version}"