nixpkgs/pkgs/by-name/bl/blockbench/package.nix

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

107 lines
2.9 KiB
Nix
Raw Normal View History

2024-05-20 18:17:40 +00:00
{
lib,
stdenv,
buildNpmPackage,
fetchFromGitHub,
makeWrapper,
imagemagick,
copyDesktopItems,
makeDesktopItem,
2024-07-07 11:28:03 +00:00
electron,
2024-01-09 13:16:41 +00:00
}:
let
2024-05-20 18:17:40 +00:00
electronDist = "${electron}/${if stdenv.isDarwin then "Applications" else "libexec/electron"}";
2024-01-09 13:16:41 +00:00
in
buildNpmPackage rec {
pname = "blockbench";
2024-07-07 11:28:03 +00:00
version = "4.10.4";
2024-01-09 13:16:41 +00:00
src = fetchFromGitHub {
owner = "JannisX11";
repo = "blockbench";
rev = "v${version}";
2024-07-07 11:28:03 +00:00
hash = "sha256-TjT93nx52PxuHuW4NONTfI3G7+Dl0NFX2aKpZDEF8+8=";
2024-01-09 13:16:41 +00:00
};
2024-05-20 18:17:40 +00:00
nativeBuildInputs =
[ makeWrapper ]
++ lib.optionals (!stdenv.isDarwin) [
imagemagick # for icon resizing
copyDesktopItems
];
2024-01-09 13:16:41 +00:00
2024-07-07 11:28:03 +00:00
npmDepsHash = "sha256-WkOn1bLJ9xmJdQcY6ak+hs/YW+crIXhTWA6tjMSVq9I=";
2024-01-09 13:16:41 +00:00
env.ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
2024-05-20 18:17:40 +00:00
# disable code signing on Darwin
postConfigure = lib.optionalString stdenv.isDarwin ''
export CSC_IDENTITY_AUTO_DISCOVERY=false
sed -i "/afterSign/d" package.json
'';
2024-01-09 13:16:41 +00:00
npmBuildScript = "bundle";
postBuild = ''
2024-05-20 18:17:40 +00:00
# electronDist needs to be modifiable on Darwin
cp -r ${electronDist} electron-dist
chmod -R u+w electron-dist
2024-01-09 13:16:41 +00:00
npm exec electron-builder -- \
--dir \
2024-05-20 18:17:40 +00:00
-c.electronDist=electron-dist \
2024-01-09 13:16:41 +00:00
-c.electronVersion=${electron.version}
'';
installPhase = ''
runHook preInstall
2024-05-20 18:17:40 +00:00
${lib.optionalString stdenv.isDarwin ''
mkdir -p $out/Applications
cp -r dist/mac*/Blockbench.app $out/Applications
makeWrapper $out/Applications/Blockbench.app/Contents/MacOS/Blockbench $out/bin/blockbench
''}
${lib.optionalString (!stdenv.isDarwin) ''
mkdir -p $out/share/blockbench
cp -r dist/*-unpacked/{locales,resources{,.pak}} $out/share/blockbench
2024-01-09 13:16:41 +00:00
2024-05-20 18:17:40 +00:00
for size in 16 32 48 64 128 256 512; do
mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
2024-07-07 11:28:03 +00:00
magick convert -resize "$size"x"$size" icon.png $out/share/icons/hicolor/"$size"x"$size"/apps/blockbench.png
2024-05-20 18:17:40 +00:00
done
2024-01-09 13:16:41 +00:00
2024-05-20 18:17:40 +00:00
makeWrapper ${lib.getExe electron} $out/bin/blockbench \
--add-flags $out/share/blockbench/resources/app.asar \
--add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations}}" \
--inherit-argv0
''}
2024-01-09 13:16:41 +00:00
runHook postInstall
'';
# based on desktop file found in the published AppImage archive
desktopItems = [
(makeDesktopItem {
name = "blockbench";
exec = "blockbench %U";
icon = "blockbench";
desktopName = "Blockbench";
comment = meta.description;
categories = [ "3DGraphics" ];
startupWMClass = "Blockbench";
terminal = false;
})
];
meta = {
changelog = "https://github.com/JannisX11/blockbench/releases/tag/${src.rev}";
description = "Low-poly 3D modeling and animation software";
homepage = "https://blockbench.net/";
license = lib.licenses.gpl3Only;
mainProgram = "blockbench";
2024-07-07 11:28:03 +00:00
maintainers = with lib.maintainers; [ tomasajt ];
2024-01-09 13:16:41 +00:00
};
}