This repository has no description
4.9 kB
142 lines
1{
2 lib,
3 stdenv,
4 buildNpmPackage,
5 fetchFromGitHub,
6 makeWrapper,
7 makeDesktopItem,
8 copyDesktopItems,
9 electron_43,
10}:
11
12let
13 electron = electron_43;
14in
15buildNpmPackage (finalAttrs: {
16 pname = "moebius";
17 # Upstream's last tagged release (1.0.29) only ships x86_64 binaries; build the
18 # newer master commit from source so it runs natively on every platform.
19 version = "1.0.29-unstable-2023-12-18";
20
21 src = fetchFromGitHub {
22 owner = "blocktronics";
23 repo = "moebius";
24 rev = "1f624d62654d614177635ab18a288253c3b917eb";
25 hash = "sha256-Uu6vEhbXXiVbUTgC/WeF+SVCf0oLzg4OnGFZIx7SJ6I=";
26 };
27
28 npmDepsHash = "sha256-hLZF0FvyAgJVURmU6M4UYFauZz5SLvH2+6W2qDogoXU=";
29
30 # discord-rpc pulls the optional native `register-scheme` git dependency, which
31 # is only used outside Electron (inside Electron it falls back to
32 # app.setAsDefaultProtocolClient), so drop it and build a pure-JS closure.
33 forceGitDeps = true;
34 npmFlags = [
35 "--omit=dev"
36 "--omit=optional"
37 ];
38
39 # We ship the app on nixpkgs' Electron; don't download a private one or run the
40 # electron-builder packaging step.
41 env.ELECTRON_SKIP_BINARY_DOWNLOAD = "1";
42 dontNpmBuild = true;
43
44 nativeBuildInputs = [
45 makeWrapper
46 ]
47 ++ lib.optionals stdenv.hostPlatform.isLinux [ copyDesktopItems ];
48
49 desktopItems = lib.optionals stdenv.hostPlatform.isLinux [
50 (makeDesktopItem {
51 name = "moebius";
52 desktopName = "Moebius";
53 comment = finalAttrs.meta.description;
54 exec = "moebius %U";
55 icon = "moebius";
56 startupWMClass = "Moebius";
57 categories = [ "Graphics" ];
58 mimeTypes = [ "text/x-ansi" ];
59 })
60 ];
61
62 installPhase = ''
63 runHook preInstall
64
65 app=$out/libexec/moebius
66 res=$app/resources
67 mkdir -p "$app" "$out/bin"
68 cp -r app node_modules package.json "$app/"
69
70 # Sample art and control-character sheets the app loads at runtime.
71 mkdir -p "$res"
72 cp -r build/ans "$res/ans"
73 cp -r build/png "$res/png"
74
75 # The app switches resource paths on app.isPackaged; we run an unpacked tree,
76 # so pin both branches to the store copy above.
77 find "$app/app" -name '*.js' | while read -r f; do
78 substituteInPlace "$f" \
79 --replace-quiet 'remote.app.isPackaged' 'true' \
80 --replace-quiet 'process.resourcesPath' "\"$res\""
81 done
82
83 # @electron/remote 2.1.0 calls the internal features.isViewApiEnabled(),
84 # removed in modern Electron; guard it (the fix shipped upstream in 2.1.2).
85 substituteInPlace "$app/node_modules/@electron/remote/dist/src/common/module-names.js" \
86 --replace-fail 'if (!features || features.isViewApiEnabled()) {' \
87 'if (!features || !features.isViewApiEnabled || features.isViewApiEnabled()) {'
88
89 makeWrapper ${lib.getExe electron} $out/bin/moebius \
90 --add-flags "$app" \
91 ${lib.optionalString stdenv.hostPlatform.isLinux ''
92 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}"
93 ''}
94 ''
95 + lib.optionalString stdenv.hostPlatform.isLinux ''
96 for size in 16 32 128 512 1024; do
97 install -Dm644 build/icons/icon_''${size}x''${size}.png \
98 $out/share/icons/hicolor/''${size}x''${size}/apps/moebius.png
99 done
100 ''
101 + lib.optionalString stdenv.hostPlatform.isDarwin ''
102 appdir="$out/Applications/Moebius.app/Contents"
103 mkdir -p "$appdir/MacOS" "$appdir/Resources"
104 cp build/icon.icns "$appdir/Resources/moebius.icns"
105 makeWrapper $out/bin/moebius "$appdir/MacOS/Moebius"
106 cat > "$appdir/Info.plist" <<EOF
107 <?xml version="1.0" encoding="UTF-8"?>
108 <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
109 <plist version="1.0">
110 <dict>
111 <key>CFBundleName</key><string>Moebius</string>
112 <key>CFBundleDisplayName</key><string>Moebius</string>
113 <key>CFBundleExecutable</key><string>Moebius</string>
114 <key>CFBundleIdentifier</key><string>org.andyherbert.moebius</string>
115 <key>CFBundleIconFile</key><string>moebius.icns</string>
116 <key>CFBundleShortVersionString</key><string>${finalAttrs.version}</string>
117 <key>CFBundlePackageType</key><string>APPL</string>
118 <key>LSMinimumSystemVersion</key><string>10.13</string>
119 <key>NSHighResolutionCapable</key><true/>
120 </dict>
121 </plist>
122 EOF
123 ''
124 + ''
125 runHook postInstall
126 '';
127
128 meta = {
129 description = "Modern ANSI and ASCII art editor with a Photoshop-style half-block brush";
130 homepage = "https://blocktronics.github.io/moebius/";
131 downloadPage = "https://github.com/blocktronics/moebius/releases";
132 license = lib.licenses.asl20;
133 maintainers = [ ];
134 platforms = [
135 "x86_64-linux"
136 "aarch64-linux"
137 "x86_64-darwin"
138 "aarch64-darwin"
139 ];
140 mainProgram = "moebius";
141 };
142})