From 43bcfa0c9ffc77a89827d46eed9e2a82298b78bb Mon Sep 17 00:00:00 2001 From: Price Hiller Date: Sat, 6 Jul 2024 01:23:41 -0500 Subject: [PATCH] feat(nix): add own neovide package --- pkgs/default.nix | 1 + pkgs/neovide/package.nix | 131 +++++++++++++++++++++++++++++++ pkgs/neovide/skia-externals.json | 37 +++++++++ 3 files changed, 169 insertions(+) create mode 100644 pkgs/neovide/package.nix create mode 100644 pkgs/neovide/skia-externals.json diff --git a/pkgs/default.nix b/pkgs/default.nix index 9f7793a4..e0f5e30c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -5,6 +5,7 @@ fetchFromGitHub = pkgs.fetchFromGitHub; }; screen-cap = pkgs.callPackage ./screen-cap/default.nix { }; + neovide = pkgs.callPackage ./neovide/package.nix { }; Fmt = pkgs.writeShellApplication { name = "Fmt"; runtimeInputs = with pkgs; [ diff --git a/pkgs/neovide/package.nix b/pkgs/neovide/package.nix new file mode 100644 index 00000000..cf2bfa4d --- /dev/null +++ b/pkgs/neovide/package.nix @@ -0,0 +1,131 @@ +{ + lib, + rustPlatform, + clangStdenv, + fetchFromGitHub, + linkFarm, + fetchgit, + runCommand, + gn, + neovim, + ninja, + makeWrapper, + pkg-config, + python3, + removeReferencesTo, + xcbuild, + SDL2, + fontconfig, + xorg, + stdenv, + darwin, + libglvnd, + libxkbcommon, + enableWayland ? stdenv.isLinux, + wayland, +}: + +rustPlatform.buildRustPackage.override { stdenv = clangStdenv; } rec { + pname = "neovide"; + version = "24fcfc94c30775a6ff08277e76d266d2a1bde62c"; + + src = fetchFromGitHub { + owner = "neovide"; + repo = "neovide"; + rev = version; + hash = "sha256-5F9U2sE2CUQGSraWJ5plxvYdH498EQbj9U7DK0chWRU="; + }; + + cargoHash = "sha256-hV0EWjcb1P1GSlgnhJ6Xy0aUBtCK52mHOqdfr/COQbk="; + + SKIA_SOURCE_DIR = + let + repo = fetchFromGitHub { + owner = "rust-skia"; + repo = "skia"; + # see rust-skia:skia-bindings/Cargo.toml#package.metadata skia + rev = "m125-0.72.3"; + hash = "sha256-zlHUJUXukE4CsXwwmVl3KHf9mnNPT8lC/ETEE15Gb4s="; + }; + # The externals for skia are taken from skia/DEPS + externals = linkFarm "skia-externals" ( + lib.mapAttrsToList (name: value: { + inherit name; + path = fetchgit value; + }) (lib.importJSON ./skia-externals.json) + ); + in + runCommand "source" { } '' + cp -R ${repo} $out + chmod -R +w $out + ln -s ${externals} $out/third_party/externals + ''; + + SKIA_GN_COMMAND = "${gn}/bin/gn"; + SKIA_NINJA_COMMAND = "${ninja}/bin/ninja"; + + nativeBuildInputs = [ + makeWrapper + pkg-config + python3 # skia + removeReferencesTo + ] ++ lib.optionals stdenv.isDarwin [ xcbuild ]; + + nativeCheckInputs = [ neovim ]; + + buildInputs = [ + SDL2 + fontconfig + rustPlatform.bindgenHook + ] ++ lib.optionals stdenv.isDarwin [ darwin.apple_sdk.frameworks.AppKit ]; + + postFixup = + let + libPath = lib.makeLibraryPath ( + [ + libglvnd + libxkbcommon + xorg.libXcursor + xorg.libXext + xorg.libXrandr + xorg.libXi + ] + ++ lib.optionals enableWayland [ wayland ] + ); + in + '' + # library skia embeds the path to its sources + remove-references-to -t "$SKIA_SOURCE_DIR" \ + $out/bin/neovide + + wrapProgram $out/bin/neovide \ + --prefix LD_LIBRARY_PATH : ${libPath} + ''; + + postInstall = + lib.optionalString stdenv.isDarwin '' + mkdir -p $out/Applications + cp -r extra/osx/Neovide.app $out/Applications + ln -s $out/bin $out/Applications/Neovide.app/Contents/MacOS + '' + + lib.optionalString stdenv.isLinux '' + for n in 16x16 32x32 48x48 256x256; do + install -m444 -D "assets/neovide-$n.png" \ + "$out/share/icons/hicolor/$n/apps/neovide.png" + done + install -m444 -Dt $out/share/icons/hicolor/scalable/apps assets/neovide.svg + install -m444 -Dt $out/share/applications assets/neovide.desktop + ''; + + disallowedReferences = [ SKIA_SOURCE_DIR ]; + + meta = with lib; { + description = "This is a simple graphical user interface for Neovim"; + mainProgram = "neovide"; + homepage = "https://github.com/neovide/neovide"; + changelog = "https://github.com/neovide/neovide/releases/tag/${version}"; + license = with licenses; [ mit ]; + maintainers = with maintainers; [ ck3d ]; + platforms = platforms.linux ++ [ "aarch64-darwin" ]; + }; +} diff --git a/pkgs/neovide/skia-externals.json b/pkgs/neovide/skia-externals.json new file mode 100644 index 00000000..9a71fd62 --- /dev/null +++ b/pkgs/neovide/skia-externals.json @@ -0,0 +1,37 @@ +{ + "expat": { + "url": "https://chromium.googlesource.com/external/github.com/libexpat/libexpat.git", + "rev": "441f98d02deafd9b090aea568282b28f66a50e36", + "sha256": "sha256-FXTDGAK03jc2wvazhRKqtsFRKZUYS/9HLpZNp4JfZJI=" + }, + "libjpeg-turbo": { + "url": "https://chromium.googlesource.com/chromium/deps/libjpeg_turbo.git", + "rev": "ed683925e4897a84b3bffc5c1414c85b97a129a3", + "sha256": "sha256-DYJP3phe4OzCtRN2pMc07ITTWR8MuIlOWWg9PBsQAVw=" + }, + "icu": { + "url": "https://chromium.googlesource.com/chromium/deps/icu.git", + "rev": "a0718d4f121727e30b8d52c7a189ebf5ab52421f", + "sha256": "sha256-BI3f/gf9GNDvSfXWeRHKBvznSz4mjXY8rM24kK7QvOM=" + }, + "zlib": { + "url": "https://chromium.googlesource.com/chromium/src/third_party/zlib", + "rev": "646b7f569718921d7d4b5b8e22572ff6c76f2596", + "sha256": "sha256-jNj6SuTZ5/a7crtYhxW3Q/TlfRMNMfYIVxDlr7bYdzQ=" + }, + "harfbuzz": { + "url": "https://chromium.googlesource.com/external/github.com/harfbuzz/harfbuzz.git", + "rev": "c053e8f29257814e11ad61493dbbe29f27656de4", + "sha256": "sha256-D8DNcZH/oiJqWvfWFHvQ8AwQ3OrMwyZdfGmZ5y30Hvg=" + }, + "wuffs": { + "url": "https://skia.googlesource.com/external/github.com/google/wuffs-mirror-release-c.git", + "rev": "e3f919ccfe3ef542cfc983a82146070258fb57f8", + "sha256": "sha256-373d2F/STcgCHEq+PO+SCHrKVOo6uO1rqqwRN5eeBCw=" + }, + "libpng": { + "url": "https://skia.googlesource.com/third_party/libpng.git", + "rev": "144b348e072a78e8130ed0acc452c9f039a67bf2", + "sha256": "sha256-eTF7q7hR4S1OqV2oPQKmcHujA5Od4rGMc5879kT0SkE=" + } +}