From 99800dd6b5955e2955848a9e0bbf95c899ccf814 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Wed, 22 Jul 2026 21:31:42 +0800 Subject: [PATCH] emacs.pkgs.ghostel: ease overrideAttrs of local bumps To make overrideAttrs pleasant, we should merge the elisp derivation and the zig module derivation into one derivation. One way is to make zig build hooks composable via #514028. This patch tries to make overrideAttrs less painful based on the current situation. With this patch, overrideAttrs can be done like this: emacs.pkgs.ghostel.overrideAttrs (old: { version = "0.41.0"; src = old.src.override { hash = "sha256-07Ml/eRIHyptI6MNlHhDNsfIiXOAUVKaEalDVJ101WM="; }; zigDeps = old.zigDeps.overrideAttrs { outputHash = "sha256-lFU0ywNyP1q2NL9MkIfWciH03VAA/Act5dGYAV4V7EY="; }; }) --- .../manual-packages/ghostel/package.nix | 99 +++++++++++-------- 1 file changed, 58 insertions(+), 41 deletions(-) diff --git a/pkgs/applications/editors/emacs/elisp-packages/manual-packages/ghostel/package.nix b/pkgs/applications/editors/emacs/elisp-packages/manual-packages/ghostel/package.nix index cf607e49a6fc..16a9e0f2161a 100644 --- a/pkgs/applications/editors/emacs/elisp-packages/manual-packages/ghostel/package.nix +++ b/pkgs/applications/editors/emacs/elisp-packages/manual-packages/ghostel/package.nix @@ -12,6 +12,46 @@ let zig = zig_0_15; + mkModule = + { + pname, + version, + src, + zigDeps, + }: + stdenv.mkDerivation (finalAttrs: { + inherit + pname + version + src + zigDeps + ; + + nativeBuildInputs = [ zig ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ]; + + env.EMACS_INCLUDE_DIR = "${emacs}/include"; + + dontSetZigDefaultFlags = true; + + doCheck = true; + + zigCheckFlags = [ + "-Dcpu=baseline" + # See https://github.com/ghostty-org/ghostty/blob/main/PACKAGING.md#build-options + "-Doptimize=ReleaseFast" + ]; + + zigBuildFlags = finalAttrs.zigCheckFlags; + + postConfigure = '' + cp -rLT ${finalAttrs.zigDeps} "$ZIG_GLOBAL_CACHE_DIR/p" + chmod -R u+w "$ZIG_GLOBAL_CACHE_DIR/p" + ''; + }); + + libExt = stdenv.hostPlatform.extensions.sharedLibrary; +in +melpaBuild (finalAttrs: { pname = "ghostel"; version = "0.44.0"; @@ -19,60 +59,37 @@ let src = fetchFromGitHub { owner = "dakra"; repo = "ghostel"; - tag = "v${version}"; + tag = "v${finalAttrs.version}"; hash = "sha256-vRGZoQtjsL42ga07fOfEjccKRidAhqgwHBoKs++62Ls="; }; - module = stdenv.mkDerivation (finalAttrs: { - inherit pname version src; - - zigDeps = zig.fetchDeps { - inherit (finalAttrs) src pname version; - fetchAll = true; - hash = "sha256-yrVgiofdmVjTGJ+PGPGRCc8gb/JcEca1uAzIoPgHHqU="; - }; - - nativeBuildInputs = [ zig ] ++ lib.optionals stdenv.hostPlatform.isDarwin [ xcbuild ]; - - env.EMACS_INCLUDE_DIR = "${emacs}/include"; - - dontSetZigDefaultFlags = true; - - doCheck = true; - - zigCheckFlags = [ - "-Dcpu=baseline" - # See https://github.com/ghostty-org/ghostty/blob/main/PACKAGING.md#build-options - "-Doptimize=ReleaseFast" - ]; - - zigBuildFlags = finalAttrs.zigCheckFlags; - - postConfigure = '' - cp -rLT ${finalAttrs.zigDeps} "$ZIG_GLOBAL_CACHE_DIR/p" - chmod -R u+w "$ZIG_GLOBAL_CACHE_DIR/p" - ''; - }); - - libExt = stdenv.hostPlatform.extensions.sharedLibrary; -in -melpaBuild { - inherit pname version src; + # this can be put into mkModule, but we put it here to ease user overrideAttrs + zigDeps = zig.fetchDeps { + inherit (finalAttrs) src pname version; + fetchAll = true; + hash = "sha256-yrVgiofdmVjTGJ+PGPGRCc8gb/JcEca1uAzIoPgHHqU="; + }; files = '' (:defaults "etc" "ghostel-module${libExt}" "ghostel-module.version") ''; preBuild = '' - install ${module}/ghostel-module${libExt} ghostel-module${libExt} - install --mode=444 ${module}/ghostel-module.version ghostel-module.version + install ${finalAttrs.finalPackage.module}/ghostel-module${libExt} ghostel-module${libExt} + install --mode=444 ${finalAttrs.finalPackage.module}/ghostel-module.version ghostel-module.version ''; passthru = { updateScript = nix-update-script { }; - inherit module; - inherit (module) zigDeps; + module = mkModule { + pname = "${finalAttrs.pname}-module"; + inherit (finalAttrs) + version + src + zigDeps + ; + }; }; meta = { @@ -84,4 +101,4 @@ melpaBuild { ]; license = lib.licenses.gpl3Plus; }; -} +})