about summary refs log tree commit diff
path: root/pkgs/by-name/bl/blockbench/package.nix
blob: 9cf8cac46c72c046dbf587d60bf26d89701cbb0b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
{
  lib,
  stdenv,
  buildNpmPackage,
  fetchFromGitHub,
  makeWrapper,
  imagemagick,
  copyDesktopItems,
  makeDesktopItem,
  electron_28,
}:

let
  electron = electron_28;
  electronDist = "${electron}/${if stdenv.isDarwin then "Applications" else "libexec/electron"}";
in
buildNpmPackage rec {
  pname = "blockbench";
  version = "4.10.2";

  src = fetchFromGitHub {
    owner = "JannisX11";
    repo = "blockbench";
    rev = "v${version}";
    hash = "sha256-Ch+vPSvdqfJF2gNgZN2x5KSY1S1CYfHCyMyUf4W+Vn8=";
  };

  nativeBuildInputs =
    [ makeWrapper ]
    ++ lib.optionals (!stdenv.isDarwin) [
      imagemagick # for icon resizing
      copyDesktopItems
    ];

  npmDepsHash = "sha256-au6GzBTxPcYcqrPEnQ+yEhVRdAbiUa/Ocq7UCPdiox4=";

  env.ELECTRON_SKIP_BINARY_DOWNLOAD = 1;

  # disable code signing on Darwin
  postConfigure = lib.optionalString stdenv.isDarwin ''
    export CSC_IDENTITY_AUTO_DISCOVERY=false
    sed -i "/afterSign/d" package.json
  '';

  npmBuildScript = "bundle";

  postBuild = ''
    # electronDist needs to be modifiable on Darwin
    cp -r ${electronDist} electron-dist
    chmod -R u+w electron-dist

    npm exec electron-builder -- \
        --dir \
        -c.electronDist=electron-dist \
        -c.electronVersion=${electron.version}
  '';

  installPhase = ''
    runHook preInstall

    ${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

      for size in 16 32 48 64 128 256 512; do
        mkdir -p $out/share/icons/hicolor/"$size"x"$size"/apps
        convert -resize "$size"x"$size" icon.png $out/share/icons/hicolor/"$size"x"$size"/apps/blockbench.png
      done

      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
    ''}

    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";
    maintainers = with lib.maintainers; [
      ckie
      tomasajt
    ];
  };
}