Skip to content

Commit

Permalink
positron-bin: init at 2024.11.0-116
Browse files Browse the repository at this point in the history
  • Loading branch information
detroyejr committed Oct 28, 2024
1 parent c9e4eba commit 689930a
Show file tree
Hide file tree
Showing 2 changed files with 193 additions and 0 deletions.
139 changes: 139 additions & 0 deletions pkgs/by-name/po/positron-bin/package.nix
Original file line number Diff line number Diff line change
@@ -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;
};
}
54 changes: 54 additions & 0 deletions pkgs/by-name/po/positron-bin/update.sh
Original file line number Diff line number Diff line change
@@ -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}"

0 comments on commit 689930a

Please sign in to comment.