Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

oni2: init at 0.5.7 #136101

Merged
merged 2 commits into from
Nov 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions maintainers/maintainer-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4104,6 +4104,12 @@
githubId = 20208;
name = "Rok Garbas";
};
gardspirito = {
name = "gardspirito";
email = "[email protected]";
github = "gardspirito";
githubId = 29687558;
};
garrison = {
email = "[email protected]";
github = "garrison";
Expand Down
252 changes: 252 additions & 0 deletions pkgs/applications/editors/oni2/common.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
{ lib, stdenv, nodePackages
# Fetch dependencies
, fetchFromGitHub, gitMinimal, curlMinimal, cacert, yarn, unzip, xorg, nodejs
, ripgrep, fontconfig, libGL, libGLU, ncurses, acl, harfbuzz, libjpeg, expat
, icu58, libpng
# Build
, jq, perl, makeWrapper, bash, which, nasm, python2, gn, ninja, cmake, clang
, fixup_yarn_lock, callPackage }:

{ variant, version, rev, sha256, fetchDepsSha256, license }:

let
source = fetchFromGitHub {
repo = variant;
owner = "onivim";
inherit rev sha256;
};

fetchDeps = stdenv.mkDerivation {
name = "oni2-fetch-deps";

unpackPhase = ''
cp ${source}/{release,package}.json ./
cp -r ${source}/{release.esy.lock,node,extensions} ./
chmod -R +w node extensions
'';

nativeBuildInputs = [
jq
nodePackages.esy
gitMinimal
curlMinimal
cacert
python2
perl
unzip
yarn
];

buildPhase = ''
export ESY__PREFIX=$NIX_BUILD_TOP/esy
export ESY__GLOBAL_PATH=PATH

esy '@release' install

ln -s $NIX_BUILD_TOP/esy/source/i/ $NIX_BUILD_TOP/source

cd $NIX_BUILD_TOP/source
cd $(ls | grep "^esy_skia")

# Prefetch esy_skia pinned dependencies
# angle2, dng_sdk, piex and sfntly are unique and need to be fetched
# zlib and webp used here seem to be outdated, so it's impossible to link esy_skia against upstream zlib and webp
cat DEPS | grep -E '{|}|angle2|dng_sdk|piex|sfntly|zlib|webp' > DEPS-upd
mv DEPS{-upd,}
python tools/git-sync-deps
# Patch esy_skia builder to use nixpkgs ninja, gn tools and icu, expat and libpng libraries.
cd esy
patch build.sh ${./esy_skia_use_nixpkgs.patch}

cd $NIX_BUILD_TOP/source
cd $(ls | grep '^revery' | grep -v '__s__')
jq '.esy.build |= "bash -c \"\(.)\""' package.json > package-upd.json
mv package{-upd,}.json

# Delete esy_cmake and ninja dependencies (they are brought from Nixpkgs)
# Removing them from release.esy.lock is hard because it reports corruption
for d in "revery__s__esy_cmake" "ninja"; do
cd $NIX_BUILD_TOP/source
cd $(ls | grep $d)
rm -rf *
done

rm -rf $(find $NIX_BUILD_TOP/esy -name .git)
'';

installPhase = ''
mkdir $out
cp -r $NIX_BUILD_TOP/esy $out/
'';

dontPatchShebangs = true;

impureEnvVars = lib.fetchers.proxyImpureEnvVars;

outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = fetchDepsSha256;
};
in stdenv.mkDerivation (rec {
pname = "oni2";
inherit version;

nativeBuildInputs = [
clang
makeWrapper
nodePackages.esy
bash
perl
which
nasm
python2
gn
ninja
cmake
jq
yarn
fixup_yarn_lock
];

buildInputs = [
nodejs
ripgrep
fontconfig
libGL
libGLU
ncurses
acl
harfbuzz
libjpeg
expat
icu58
libpng
] ++ (with xorg; [
libX11
libXext
libXi
libXxf86vm
libXrandr
libXinerama
libXcursor
libICE
libSM
libXt
libxkbfile
]);

unpackPhase = ''
cp -r ${source}/* ./
cp -r ${fetchDeps}/esy ./

chmod -R +w esy node/ extensions/
chmod +w assets/configuration
'';

hardeningDisable = [ "fortify" ];

node = (callPackage ./node.nix { }).offline_cache;
extensions = (callPackage ./extensions.nix { }).offline_cache;

configurePhase = ''
runHook preConfigure

# Esy by default erases the entire environment, so the builder makes a wrapper over bash to automatically re-export it
mkdir wrapped-bash
echo "#!${bash}/bin/bash" > wrapped-bash/bash
export | sed 's/PATH="/PATH="$PATH:/' >> wrapped-bash/bash
echo "exec ${bash}/bin/bash \"\$@\"" >> wrapped-bash/bash
chmod +x wrapped-bash/bash

# Use custom builder for Oni2 to provide necessary environment to it
echo 'declare -x NIX_LDFLAGS="$NIX_LDFLAGS -lXext -lharfbuzz -ljpeg -lpthread -lpng -lexpat"' > build.sh
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we set the variable globally?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that no. Building esy_skia, which also happens in this buildPhase, does not need these LD flags. At least it failed last time I tested.

echo $(jq -r '.esy.build' package.json) >> build.sh
jq '.esy.build |= "bash build.sh"' package.json > package-upd.json
mv package{-upd,}.json

export PATH="$NIX_BUILD_TOP/wrapped-bash:$PATH"
patchShebangs $NIX_BUILD_TOP/esy/source

echo "" > assets/configuration/setup.json # it will be set at installation phase.

substituteInPlace src/gen_buildinfo/generator.re --replace "git rev-parse --short HEAD" "echo '${version}'"

runHook postConfigure
'';

buildPhase = ''
runHook preBuild

# Required by yarn
export HOME=$(mktemp -d)

# Install pinned yarn packages
yarnInstall() {
# Remove `resolutions` section from package.json
jq 'del(.resolutions)' $3/package.json > $3/package-upd.json
cp $3/package{-upd,}.json

# Copy custom yarn.lock to match updated package.json, do fixup
cp $2 $3/yarn.lock
fixup_yarn_lock $3/yarn.lock

# Make yarn install prefetched dependencies
yarn config --offline set yarn-offline-mirror $1
# Set explicit node install directory for node-gyp.
npm_config_nodedir=${nodejs} yarn install --frozen-lockfile --offline --no-progress --non-interactive --cwd $3
}
yarnInstall ${node} ${./node.lock} node
yarnInstall ${extensions} ${./extensions.lock} extensions

export ESY__PREFIX="$NIX_BUILD_TOP/esy"
esy '@release' install # should do nothing

export ESY__GLOBAL_PATH=PATH
# Create link to bin directory, currently empty
esy '@release' sh -c "ln -s \$cur__bin result"
# Finish building Oni2
esy '@release' x Oni2 --help

runHook postBuild
'';

installPhase = ''
runHook preInstall

mkdir $out

cp -Lr ./result $out/bin
cp -r ./node $out/
cp -r ./extensions $out/

chmod +w $out/bin
chmod +x $out/bin/Oni2 $out/bin/Oni2_editor
# Unset LANG and XMODIFIERS. See https://github.com/onivim/oni2/issues/3772
# Unset SDL_VIDEODRIVER because Wayland is not supported. See https://github.com/onivim/oni2/issues/3438
mv $out/bin/Oni2{,_unwrapped}
makeWrapper $out/bin/Oni2{_unwrapped,} --unset LANG --unset XMODIFIERS --unset SDL_VIDEODRIVER
mv $out/bin/Oni2_editor{,_unwrapped}
makeWrapper $out/bin/Oni2_editor{_unwrapped,} --unset LANG --unset XMODIFIERS --unset SDL_VIDEODRIVER

rm -f $out/bin/setup.json
jq -n "{node: \"${nodejs}/bin/node\", nodeScript: \"$out/node\", bundledExtensions: \"$out/extensions\", rg: \"${ripgrep}/bin/rg\"}" > $out/bin/setup.json

mkdir -p $out/share/applications $out/share/pixmaps
cp ${source}/scripts/linux/Onivim2.desktop $out/share/applications
cp ${source}/assets/images/icon512.png $out/share/pixmaps/Onivim2.png

runHook postInstall
'';

meta = with lib; {
description = "Native, lightweight modal code editor";
longDescription = ''
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.
'';
homepage = "https://v2.onivim.io/";
inherit license;
maintainers = with maintainers; [ gardspirito ];
platforms = [ "x86_64-linux" "x86_64-darwin" ];
};
})

16 changes: 16 additions & 0 deletions pkgs/applications/editors/oni2/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{ callPackage }:

let mkOni2 = callPackage ./common.nix { };
in mkOni2 rec {
variant = "oni2";
license = {
fullName = "Outrun Labs End User License Agreement";
url = "https://github.com/onivim/oni2/blob/master/Outrun-Labs-EULA-v1.1.md";
free = false;
};
version = "0.5.7";
rev = "v${version}";
sha256 = "NlN0Ntdwtx5XLjd1ltUzv/bjmJQR5eyRqtmicppP6YU=";
fetchDepsSha256 = "k7G6jPJfxCCSuSucPfiXljCVJhmjl/BxWMCEjv2tfhA=";
gardspirito marked this conversation as resolved.
Show resolved Hide resolved
}

13 changes: 13 additions & 0 deletions pkgs/applications/editors/oni2/esy_skia_use_nixpkgs.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
diff --git a/build-or.sh b/build.sh
index be0bc6f..fddc9cb 100644
--- a/build-or.sh
+++ b/build.sh
@@ -50,6 +50,6 @@ else
echo "llvm toolset-7.0 does not need to be manually activated"
fi

- bin/gn gen $cur__target_dir/out/Static --script-executable="$PYTHON_BINARY" "--args=cc=\"$CC\" cxx=\"$CXX\" skia_use_system_libjpeg_turbo=true esy_skia_enable_svg=true is_debug=false extra_cflags=[\"-I${ESY_LIBJPEG_TURBO_PREFIX}/include\"] extra_ldflags=[\"-L${ESY_LIBJPEG_TURBO_PREFIX}/lib\", \"-ljpeg\" ]" || exit -1
- ninja.exe -C $cur__target_dir/out/Static || exit -1
+ gn gen $cur__target_dir/out/Static --script-executable="$PYTHON_BINARY" "--args=cc=\"$CC\" cxx=\"$CXX\" skia_use_system_libjpeg_turbo=true skia_use_system_expat=true skia_use_system_icu=true skia_use_system_libpng=true esy_skia_enable_svg=true is_debug=false extra_cflags=[\"-I${ESY_LIBJPEG_TURBO_PREFIX}/include\"] extra_ldflags=[\"-L${ESY_LIBJPEG_TURBO_PREFIX}/lib\", \"-ljpeg\" ]" || exit -1
+ ninja -C $cur__target_dir/out/Static || exit -1
fi
Loading