1 { lib, stdenv, nodePackages
3 , fetchFromGitHub, gitMinimal, curlMinimal, cacert, yarn, unzip, xorg, nodejs
4 , ripgrep, fontconfig, libGL, libGLU, ncurses, acl, harfbuzz, libjpeg, expat
7 , jq, perl, makeWrapper, bash, which, nasm, python2, gn, ninja, cmake, clang
8 , fixup_yarn_lock, callPackage }:
10 { variant, version, rev, sha256, fetchDepsSha256, license }:
13 source = fetchFromGitHub {
19 fetchDeps = stdenv.mkDerivation {
20 name = "oni2-fetch-deps";
23 cp ${source}/{release,package}.json ./
24 cp -r ${source}/{release.esy.lock,node,extensions} ./
25 chmod -R +w node extensions
41 export ESY__PREFIX=$NIX_BUILD_TOP/esy
42 export ESY__GLOBAL_PATH=PATH
44 esy '@release' install
46 ln -s $NIX_BUILD_TOP/esy/source/i/ $NIX_BUILD_TOP/source
48 cd $NIX_BUILD_TOP/source
49 cd $(ls | grep "^esy_skia")
51 # Prefetch esy_skia pinned dependencies
52 # angle2, dng_sdk, piex and sfntly are unique and need to be fetched
53 # zlib and webp used here seem to be outdated, so it's impossible to link esy_skia against upstream zlib and webp
54 cat DEPS | grep -E '{|}|angle2|dng_sdk|piex|sfntly|zlib|webp' > DEPS-upd
56 python tools/git-sync-deps
57 # Patch esy_skia builder to use nixpkgs ninja, gn tools and icu, expat and libpng libraries.
59 patch build.sh ${./esy_skia_use_nixpkgs.patch}
61 cd $NIX_BUILD_TOP/source
62 cd $(ls | grep '^revery' | grep -v '__s__')
63 jq '.esy.build |= "bash -c \"\(.)\""' package.json > package-upd.json
64 mv package{-upd,}.json
66 # Delete esy_cmake and ninja dependencies (they are brought from Nixpkgs)
67 # Removing them from release.esy.lock is hard because it reports corruption
68 for d in "revery__s__esy_cmake" "ninja"; do
69 cd $NIX_BUILD_TOP/source
74 rm -rf $(find $NIX_BUILD_TOP/esy -name .git)
79 cp -r $NIX_BUILD_TOP/esy $out/
82 dontPatchShebangs = true;
84 impureEnvVars = lib.fetchers.proxyImpureEnvVars;
86 outputHashMode = "recursive";
87 outputHashAlgo = "sha256";
88 outputHash = fetchDepsSha256;
90 in stdenv.mkDerivation (rec {
139 cp -r ${fetchDeps}/esy ./
141 chmod -R +w esy node/ extensions/
142 chmod +w assets/configuration
145 hardeningDisable = [ "fortify" ];
147 node = (callPackage ./node.nix { }).offline_cache;
148 extensions = (callPackage ./extensions.nix { }).offline_cache;
153 # Esy by default erases the entire environment, so the builder makes a wrapper over bash to automatically re-export it
155 echo "#!${bash}/bin/bash" > wrapped-bash/bash
156 export | sed 's/PATH="/PATH="$PATH:/' >> wrapped-bash/bash
157 echo "exec ${bash}/bin/bash \"\$@\"" >> wrapped-bash/bash
158 chmod +x wrapped-bash/bash
160 # Use custom builder for Oni2 to provide necessary environment to it
161 echo 'declare -x NIX_LDFLAGS="$NIX_LDFLAGS -lXext -lharfbuzz -ljpeg -lpthread -lpng -lexpat"' > build.sh
162 echo $(jq -r '.esy.build' package.json) >> build.sh
163 jq '.esy.build |= "bash build.sh"' package.json > package-upd.json
164 mv package{-upd,}.json
166 export PATH="$NIX_BUILD_TOP/wrapped-bash:$PATH"
167 patchShebangs $NIX_BUILD_TOP/esy/source
169 echo "" > assets/configuration/setup.json # it will be set at installation phase.
171 substituteInPlace src/gen_buildinfo/generator.re --replace "git rev-parse --short HEAD" "echo '${version}'"
173 runHook postConfigure
180 export HOME=$(mktemp -d)
182 # Install pinned yarn packages
184 # Remove `resolutions` section from package.json
185 jq 'del(.resolutions)' $3/package.json > $3/package-upd.json
186 cp $3/package{-upd,}.json
188 # Copy custom yarn.lock to match updated package.json, do fixup
190 fixup_yarn_lock $3/yarn.lock
192 # Make yarn install prefetched dependencies
193 yarn config --offline set yarn-offline-mirror $1
194 # Set explicit node install directory for node-gyp.
195 npm_config_nodedir=${nodejs} yarn install --frozen-lockfile --offline --no-progress --non-interactive --cwd $3
197 yarnInstall ${node} ${./node.lock} node
198 yarnInstall ${extensions} ${./extensions.lock} extensions
200 export ESY__PREFIX="$NIX_BUILD_TOP/esy"
201 esy '@release' install # should do nothing
203 export ESY__GLOBAL_PATH=PATH
204 # Create link to bin directory, currently empty
205 esy '@release' sh -c "ln -s \$cur__bin result"
206 # Finish building Oni2
207 esy '@release' x Oni2 --help
217 cp -Lr ./result $out/bin
219 cp -r ./extensions $out/
222 chmod +x $out/bin/Oni2 $out/bin/Oni2_editor
223 # Unset LANG and XMODIFIERS. See https://github.com/onivim/oni2/issues/3772
224 # Unset SDL_VIDEODRIVER because Wayland is not supported. See https://github.com/onivim/oni2/issues/3438
225 mv $out/bin/Oni2{,_unwrapped}
226 makeWrapper $out/bin/Oni2{_unwrapped,} --unset LANG --unset XMODIFIERS --unset SDL_VIDEODRIVER
227 mv $out/bin/Oni2_editor{,_unwrapped}
228 makeWrapper $out/bin/Oni2_editor{_unwrapped,} --unset LANG --unset XMODIFIERS --unset SDL_VIDEODRIVER
230 rm -f $out/bin/setup.json
231 jq -n "{node: \"${nodejs}/bin/node\", nodeScript: \"$out/node\", bundledExtensions: \"$out/extensions\", rg: \"${ripgrep}/bin/rg\"}" > $out/bin/setup.json
233 mkdir -p $out/share/applications $out/share/pixmaps
234 cp ${source}/scripts/linux/Onivim2.desktop $out/share/applications
235 cp ${source}/assets/images/icon512.png $out/share/pixmaps/Onivim2.png
241 description = "Native, lightweight modal code editor";
243 Onivim 2 is a reimagination of the Oni editor. Onivim 2 aims to bring the speed of Sublime, the language integration of VSCode, and the modal editing experience of Vim together, in a single package.
245 homepage = "https://v2.onivim.io/";
247 maintainers = with maintainers; [ gardspirito ];
248 platforms = [ "x86_64-linux" "x86_64-darwin" ];