nixpkgs mirror (for testing)
github.com/NixOS/nixpkgs
nix
1{
2 lib,
3 stdenv,
4 fetchFromGitHub,
5 buildNpmPackage,
6 nix-update-script,
7 electron,
8 makeWrapper,
9 copyDesktopItems,
10 makeDesktopItem,
11 pkg-config,
12 pixman,
13 cairo,
14 pango,
15 npm-lockfile-fix,
16 jq,
17 moreutils,
18}:
19
20buildNpmPackage rec {
21 pname = "bruno";
22 version = "2.8.1";
23
24 src = fetchFromGitHub {
25 owner = "usebruno";
26 repo = "bruno";
27 tag = "v${version}";
28 hash = "sha256-+Ce9jjOZH0kFj4EfRgAabUDA9iRmHq7umVD9pOqGBbw=";
29
30 postFetch = ''
31 ${lib.getExe npm-lockfile-fix} $out/package-lock.json
32 '';
33 };
34
35 npmDepsHash = "sha256-+ecdxq5YwZdWRATl1Jc3BaDfyVW5n4T4flCLqzFoVIQ=";
36 npmFlags = [ "--legacy-peer-deps" ];
37
38 nativeBuildInputs = [
39 pkg-config
40 ]
41 ++ lib.optionals (!stdenv.hostPlatform.isDarwin) [
42 makeWrapper
43 copyDesktopItems
44 ];
45
46 buildInputs = [
47 pixman
48 cairo
49 pango
50 ];
51
52 desktopItems = [
53 (makeDesktopItem {
54 name = "bruno";
55 desktopName = "Bruno";
56 exec = "bruno %U";
57 icon = "bruno";
58 comment = "Opensource API Client for Exploring and Testing APIs";
59 categories = [ "Development" ];
60 startupWMClass = "Bruno";
61 })
62 ];
63
64 postPatch = ''
65 substituteInPlace scripts/build-electron.sh \
66 --replace-fail 'if [ "$1" == "snap" ]; then' 'exit 0; if [ "$1" == "snap" ]; then'
67
68 # disable telemetry
69 substituteInPlace packages/bruno-app/src/providers/App/index.js \
70 --replace-fail "useTelemetry({ version });" ""
71
72 # fix version reported in sidebar and about page
73 ${jq}/bin/jq '.version |= "${version}"' packages/bruno-electron/package.json | ${moreutils}/bin/sponge packages/bruno-electron/package.json
74 ${jq}/bin/jq '.version |= "${version}"' packages/bruno-app/package.json | ${moreutils}/bin/sponge packages/bruno-app/package.json
75 '';
76
77 postConfigure = ''
78 # sh: line 1: /build/source/packages/bruno-common/node_modules/.bin/rollup: cannot execute: required file not found
79 patchShebangs packages/*/node_modules
80 '';
81
82 ELECTRON_SKIP_BINARY_DOWNLOAD = 1;
83
84 # remove giflib dependency
85 npmRebuildFlags = [ "--ignore-scripts" ];
86 preBuild = ''
87 # upstream keeps removing and adding back canvas, only patch it when it is present
88 if [[ -e node_modules/canvas/binding.gyp ]]; then
89 substituteInPlace node_modules/canvas/binding.gyp \
90 --replace-fail "'with_gif%': '<!(node ./util/has_lib.js gif)'" "'with_gif%': 'false'"
91 npm rebuild
92 fi
93 '';
94
95 buildPhase = ''
96 runHook preBuild
97
98 npm run build --workspace=packages/bruno-common
99 npm run build --workspace=packages/bruno-graphql-docs
100 npm run build --workspace=packages/bruno-converters
101 npm run build --workspace=packages/bruno-app
102 npm run build --workspace=packages/bruno-query
103 npm run build --workspace=packages/bruno-requests
104
105 npm run sandbox:bundle-libraries --workspace=packages/bruno-js
106
107 bash scripts/build-electron.sh
108
109 pushd packages/bruno-electron
110
111 ${
112 if stdenv.hostPlatform.isDarwin then
113 ''
114 cp -r ${electron.dist}/Electron.app ./
115 find ./Electron.app -name 'Info.plist' | xargs -d '\n' chmod +rw
116
117 substituteInPlace electron-builder-config.js \
118 --replace-fail "identity: 'Anoop MD (W7LPPWA48L)'" 'identity: null' \
119 --replace-fail "afterSign: 'notarize.js'," ""
120
121 npm exec electron-builder -- \
122 --dir \
123 --config electron-builder-config.js \
124 -c.electronDist=./ \
125 -c.electronVersion=${electron.version} \
126 -c.npmRebuild=false
127 ''
128 else
129 ''
130 npm exec electron-builder -- \
131 --dir \
132 -c.electronDist=${electron.dist} \
133 -c.electronVersion=${electron.version} \
134 -c.npmRebuild=false
135 ''
136 }
137
138 popd
139
140 runHook postBuild
141 '';
142
143 npmPackFlags = [ "--ignore-scripts" ];
144
145 installPhase = ''
146 runHook preInstall
147
148 ${
149 if stdenv.hostPlatform.isDarwin then
150 ''
151 mkdir -p $out/Applications
152
153 cp -R packages/bruno-electron/out/**/Bruno.app $out/Applications/
154 ''
155 else
156 ''
157 mkdir -p $out/opt/bruno $out/bin
158
159 cp -r packages/bruno-electron/dist/linux*-unpacked/{locales,resources{,.pak}} $out/opt/bruno
160
161 makeWrapper ${lib.getExe electron} $out/bin/bruno \
162 --add-flags $out/opt/bruno/resources/app.asar \
163 --add-flags "\''${NIXOS_OZONE_WL:+\''${WAYLAND_DISPLAY:+--ozone-platform-hint=auto --enable-features=WaylandWindowDecorations --enable-wayland-ime=true}}" \
164 --set-default ELECTRON_IS_DEV 0 \
165 --inherit-argv0
166
167 for s in 16 32 48 64 128 256 512 1024; do
168 size=${"$"}{s}x$s
169 install -Dm644 $src/packages/bruno-electron/resources/icons/png/$size.png $out/share/icons/hicolor/$size/apps/bruno.png
170 done
171 ''
172 }
173
174 runHook postInstall
175 '';
176
177 passthru.updateScript = nix-update-script { };
178
179 meta = {
180 description = "Open-source IDE For exploring and testing APIs";
181 homepage = "https://www.usebruno.com";
182 license = lib.licenses.mit;
183 mainProgram = "bruno";
184 maintainers = with lib.maintainers; [
185 gepbird
186 kashw2
187 lucasew
188 mattpolzin
189 redyf
190 water-sucks
191 ];
192 platforms = lib.platforms.linux ++ lib.platforms.darwin;
193 };
194}