From bef31a9d8f384907167220de0a22b985415d9c39 Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 31 Dec 2024 16:23:43 -0500 Subject: [PATCH 1/2] Revert "ghostty: rename `package.nix` to `linux.nix`" This reverts commit 0bc91a7b06dfdfca1c033d25f718b120d5a572e6. --- pkgs/by-name/gh/ghostty/linux.nix | 178 -------------------------- pkgs/by-name/gh/ghostty/package.nix | 190 ++++++++++++++++++++++++---- 2 files changed, 167 insertions(+), 201 deletions(-) delete mode 100644 pkgs/by-name/gh/ghostty/linux.nix diff --git a/pkgs/by-name/gh/ghostty/linux.nix b/pkgs/by-name/gh/ghostty/linux.nix deleted file mode 100644 index ce2d6010f2b0..000000000000 --- a/pkgs/by-name/gh/ghostty/linux.nix +++ /dev/null @@ -1,178 +0,0 @@ -{ - pname, - version, - outputs, - meta, - lib, - stdenv, - bzip2, - callPackage, - fetchFromGitHub, - fontconfig, - freetype, - glib, - glslang, - harfbuzz, - libGL, - libX11, - libadwaita, - ncurses, - nixosTests, - oniguruma, - pandoc, - pkg-config, - removeReferencesTo, - versionCheckHook, - wrapGAppsHook4, - zig_0_13, - # Usually you would override `zig.hook` with this, but we do that internally - # since upstream recommends a non-default level - # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/PACKAGING.md#build-options - optimizeLevel ? "ReleaseFast", - # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/build.zig#L106 - withAdwaita ? true, -}: - -let - zig_hook = zig_0_13.hook.overrideAttrs { - zig_default_flags = "-Dcpu=baseline -Doptimize=${optimizeLevel} --color off"; - }; - - # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/apprt.zig#L72-L76 - appRuntime = if stdenv.hostPlatform.isLinux then "gtk" else "none"; - # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/font/main.zig#L94 - fontBackend = if stdenv.hostPlatform.isDarwin then "coretext" else "fontconfig_freetype"; - # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/renderer.zig#L51-L52 - renderer = if stdenv.hostPlatform.isDarwin then "metal" else "opengl"; -in - -stdenv.mkDerivation (finalAttrs: { - inherit - pname - version - outputs - meta - ; - - src = fetchFromGitHub { - owner = "ghostty-org"; - repo = "ghostty"; - tag = "v${finalAttrs.version}"; - hash = "sha256-AHI1Z4mfgXkNwQA8xYq4tS0/BARbHL7gQUT41vCxQTM="; - }; - - # Avoid using runtime hacks to help find X11 - postPatch = lib.optionalString (appRuntime == "gtk") '' - substituteInPlace src/apprt/gtk/x11.zig \ - --replace-warn 'std.DynLib.open("libX11.so");' 'std.DynLib.open("${lib.getLib libX11}/lib/libX11.so");' - ''; - - deps = callPackage ./deps.nix { - name = "${finalAttrs.pname}-cache-${finalAttrs.version}"; - }; - - strictDeps = true; - - nativeBuildInputs = - [ - ncurses - pandoc - pkg-config - removeReferencesTo - zig_hook - ] - ++ lib.optionals (appRuntime == "gtk") [ - glib # Required for `glib-compile-schemas` - wrapGAppsHook4 - ]; - - buildInputs = - [ - glslang - oniguruma - ] - ++ lib.optional (appRuntime == "gtk" && withAdwaita) libadwaita - ++ lib.optional (appRuntime == "gtk") libX11 - ++ lib.optional (renderer == "opengl") libGL - ++ lib.optionals (fontBackend == "fontconfig_freetype") [ - bzip2 - fontconfig - freetype - harfbuzz - ]; - - zigBuildFlags = - [ - "--system" - "${finalAttrs.deps}" - "-Dversion-string=${finalAttrs.version}" - - "-Dapp-runtime=${appRuntime}" - "-Dfont-backend=${fontBackend}" - "-Dgtk-adwaita=${lib.boolToString withAdwaita}" - "-Drenderer=${renderer}" - ] - ++ lib.mapAttrsToList (name: package: "-fsys=${name} --search-prefix ${lib.getLib package}") { - inherit glslang; - }; - - zigCheckFlags = finalAttrs.zigBuildFlags; - - # Unit tests currently fail inside the sandbox - doCheck = false; - - /** - Ghostty really likes all of it's resources to be in the same directory, so link them back after we split them - - - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/os/resourcesdir.zig#L11-L52 - - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/termio/Exec.zig#L745-L750 - - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/termio/Exec.zig#L818-L834 - - terminfo and shell integration should also be installable on remote machines - - ```nix - { pkgs, ... }: { - environment.systemPackages = [ pkgs.ghostty.terminfo ]; - - programs.bash = { - interactiveShellInit = '' - if [[ "$TERM" == "xterm-ghostty" ]]; then - builtin source ${pkgs.ghostty.shell_integration}/bash/ghostty.bash - fi - ''; - }; - } - ``` - */ - postFixup = '' - ln -s $man/share/man $out/share/man - - moveToOutput share/terminfo $terminfo - ln -s $terminfo/share/terminfo $out/share/terminfo - - mv $out/share/ghostty/shell-integration $shell_integration - ln -s $shell_integration $out/share/ghostty/shell-integration - - mv $out/share/vim/vimfiles $vim - rmdir $out/share/vim - ln -s $vim $out/share/vim-plugins - - remove-references-to -t ${finalAttrs.deps} $out/bin/.ghostty-wrapped - ''; - - nativeInstallCheckInputs = [ - versionCheckHook - ]; - - doInstallCheck = true; - - versionCheckProgramArg = [ "--version" ]; - - passthru = { - tests = lib.optionalAttrs stdenv.hostPlatform.isLinux { - inherit (nixosTests) allTerminfo; - nixos = nixosTests.terminal-emulators.ghostty; - }; - }; - -}) diff --git a/pkgs/by-name/gh/ghostty/package.nix b/pkgs/by-name/gh/ghostty/package.nix index faa55c552978..7242ba82c9da 100644 --- a/pkgs/by-name/gh/ghostty/package.nix +++ b/pkgs/by-name/gh/ghostty/package.nix @@ -1,12 +1,51 @@ { - stdenvNoCC, - callPackage, lib, + stdenv, + bzip2, + callPackage, + fetchFromGitHub, + fontconfig, + freetype, + glib, + glslang, + harfbuzz, + libGL, + libX11, + libadwaita, + ncurses, + nixosTests, + oniguruma, + pandoc, + pkg-config, + removeReferencesTo, + versionCheckHook, + wrapGAppsHook4, + zig_0_13, + # Usually you would override `zig.hook` with this, but we do that internally + # since upstream recommends a non-default level + # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/PACKAGING.md#build-options + optimizeLevel ? "ReleaseFast", + # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/build.zig#L106 + withAdwaita ? true, }: let + zig_hook = zig_0_13.hook.overrideAttrs { + zig_default_flags = "-Dcpu=baseline -Doptimize=${optimizeLevel} --color off"; + }; + + # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/apprt.zig#L72-L76 + appRuntime = if stdenv.hostPlatform.isLinux then "gtk" else "none"; + # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/font/main.zig#L94 + fontBackend = if stdenv.hostPlatform.isDarwin then "coretext" else "fontconfig_freetype"; + # https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/renderer.zig#L51-L52 + renderer = if stdenv.hostPlatform.isDarwin then "metal" else "opengl"; +in + +stdenv.mkDerivation (finalAttrs: { pname = "ghostty"; version = "1.0.0"; + outputs = [ "out" "man" @@ -14,6 +53,129 @@ let "terminfo" "vim" ]; + + src = fetchFromGitHub { + owner = "ghostty-org"; + repo = "ghostty"; + tag = "v${finalAttrs.version}"; + hash = "sha256-AHI1Z4mfgXkNwQA8xYq4tS0/BARbHL7gQUT41vCxQTM="; + }; + + # Avoid using runtime hacks to help find X11 + postPatch = lib.optionalString (appRuntime == "gtk") '' + substituteInPlace src/apprt/gtk/x11.zig \ + --replace-warn 'std.DynLib.open("libX11.so");' 'std.DynLib.open("${lib.getLib libX11}/lib/libX11.so");' + ''; + + deps = callPackage ./deps.nix { + name = "${finalAttrs.pname}-cache-${finalAttrs.version}"; + }; + + strictDeps = true; + + nativeBuildInputs = + [ + ncurses + pandoc + pkg-config + removeReferencesTo + zig_hook + ] + ++ lib.optionals (appRuntime == "gtk") [ + glib # Required for `glib-compile-schemas` + wrapGAppsHook4 + ]; + + buildInputs = + [ + glslang + oniguruma + ] + ++ lib.optional (appRuntime == "gtk" && withAdwaita) libadwaita + ++ lib.optional (appRuntime == "gtk") libX11 + ++ lib.optional (renderer == "opengl") libGL + ++ lib.optionals (fontBackend == "fontconfig_freetype") [ + bzip2 + fontconfig + freetype + harfbuzz + ]; + + zigBuildFlags = + [ + "--system" + "${finalAttrs.deps}" + "-Dversion-string=${finalAttrs.version}" + + "-Dapp-runtime=${appRuntime}" + "-Dfont-backend=${fontBackend}" + "-Dgtk-adwaita=${lib.boolToString withAdwaita}" + "-Drenderer=${renderer}" + ] + ++ lib.mapAttrsToList (name: package: "-fsys=${name} --search-prefix ${lib.getLib package}") { + inherit glslang; + }; + + zigCheckFlags = finalAttrs.zigBuildFlags; + + # Unit tests currently fail inside the sandbox + doCheck = false; + + /** + Ghostty really likes all of it's resources to be in the same directory, so link them back after we split them + + - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/os/resourcesdir.zig#L11-L52 + - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/termio/Exec.zig#L745-L750 + - https://github.com/ghostty-org/ghostty/blob/4b4d4062dfed7b37424c7210d1230242c709e990/src/termio/Exec.zig#L818-L834 + + terminfo and shell integration should also be installable on remote machines + + ```nix + { pkgs, ... }: { + environment.systemPackages = [ pkgs.ghostty.terminfo ]; + + programs.bash = { + interactiveShellInit = '' + if [[ "$TERM" == "xterm-ghostty" ]]; then + builtin source ${pkgs.ghostty.shell_integration}/bash/ghostty.bash + fi + ''; + }; + } + ``` + */ + postFixup = '' + ln -s $man/share/man $out/share/man + + moveToOutput share/terminfo $terminfo + ln -s $terminfo/share/terminfo $out/share/terminfo + + mv $out/share/ghostty/shell-integration $shell_integration + ln -s $shell_integration $out/share/ghostty/shell-integration + + mv $out/share/vim/vimfiles $vim + rmdir $out/share/vim + ln -s $vim $out/share/vim-plugins + + + remove-references-to -t ${finalAttrs.deps} $out/bin/.ghostty-wrapped + ''; + + nativeInstallCheckInputs = [ + versionCheckHook + ]; + + doInstallCheck = true; + + versionCheckProgramArg = [ "--version" ]; + + passthru = { + tests = lib.optionalAttrs stdenv.hostPlatform.isLinux { + inherit (nixosTests) allTerminfo; + nixos = nixosTests.terminal-emulators.ghostty; + }; + }; + meta = { description = "Fast, native, feature-rich terminal emulator pushing modern features"; longDescription = '' @@ -31,7 +193,6 @@ let jcollie pluiedev getchoo - DimitarNestorov ]; outputsToInstall = [ "out" @@ -40,24 +201,7 @@ let "terminfo" ]; platforms = lib.platforms.linux ++ lib.platforms.darwin; + # Issues finding the SDK in the sandbox + broken = stdenv.hostPlatform.isDarwin; }; -in - -if stdenvNoCC.hostPlatform.isDarwin then - callPackage ./darwin.nix { - inherit - pname - version - outputs - meta - ; - } -else - callPackage ./linux.nix { - inherit - pname - version - outputs - meta - ; - } +}) From 41551596d7865c478bd6251f4316544bc87dfe71 Mon Sep 17 00:00:00 2001 From: seth Date: Tue, 31 Dec 2024 16:24:34 -0500 Subject: [PATCH 2/2] Revert "ghostty: add darwin package" This reverts commit 67fff2ff2f1c42380793d1ac544479aa5a57179c. --- pkgs/by-name/gh/ghostty/darwin.nix | 62 ------------------------------ 1 file changed, 62 deletions(-) delete mode 100644 pkgs/by-name/gh/ghostty/darwin.nix diff --git a/pkgs/by-name/gh/ghostty/darwin.nix b/pkgs/by-name/gh/ghostty/darwin.nix deleted file mode 100644 index adb3ec14988e..000000000000 --- a/pkgs/by-name/gh/ghostty/darwin.nix +++ /dev/null @@ -1,62 +0,0 @@ -{ - pname, - version, - outputs, - meta, - lib, - stdenvNoCC, - fetchurl, - _7zz, - makeWrapper, -}: - -stdenvNoCC.mkDerivation (finalAttrs: { - inherit pname version outputs; - - src = fetchurl { - url = "https://release.files.ghostty.org/${finalAttrs.version}/Ghostty.dmg"; - sha256 = "sha256-CR96Kz9BYKFtfVKygiEku51XFJk4FfYqfXACeYQ3JlI="; - }; - - nativeBuildInputs = [ - _7zz - makeWrapper - ]; - - sourceRoot = "."; - installPhase = '' - runHook preInstall - - mkdir -p $out/Applications - mv Ghostty.app $out/Applications/ - makeWrapper $out/Applications/Ghostty.app/Contents/MacOS/ghostty $out/bin/ghostty - - runHook postInstall - ''; - - postFixup = - let - resources = "$out/Applications/Ghostty.app/Contents/Resources"; - in - '' - mkdir -p $man/share - ln -s ${resources}/man $man/share/man - - mkdir -p $terminfo/share - ln -s ${resources}/terminfo $terminfo/share/terminfo - - mkdir -p $shell_integration - for folder in "${resources}/ghostty/shell-integration"/*; do - ln -s $folder $shell_integration/$(basename "$folder") - done - - mkdir -p $vim - for folder in "${resources}/vim/vimfiles"/*; do - ln -s $folder $vim/$(basename "$folder") - done - ''; - - meta = meta // { - sourceProvenance = [ lib.sourceTypes.binaryNativeCode ]; - }; -})