Merge pull request #235859 from atorres1985-contrib/emacs-refactor

Emacs refactor - Round II

authored by Atemu and committed by GitHub 328bcf4d 8ba3654c

+40 -55
+19 -16
pkgs/applications/editors/emacs/generic.nix
··· 1 - { pname ? "emacs" 1 + { pname 2 2 , version 3 - , versionModifier ? "" 4 - , name ? "emacs-${version}${versionModifier}" 5 3 , variant 6 4 , src 7 5 , patches ? _: [ ] ··· 74 72 , WebKit 75 73 76 74 # Boolean flags 77 - , nativeComp ? true 75 + , nativeComp ? null 76 + , withNativeCompilation ? 77 + if nativeComp != null 78 + then lib.warn "nativeComp option is deprecated and will be removed; use withNativeCompilation instead" nativeComp 79 + else true 78 80 , noGui ? false 79 81 , srcRepo ? true 80 82 , withAcl ? false ··· 96 98 , withWebP ? lib.versionAtLeast version "29" 97 99 , withX ? !(stdenv.isDarwin || noGui || withPgtk) 98 100 , withXinput2 ? withX && lib.versionAtLeast version "29" 99 - , withXwidgets ? false 101 + , withXwidgets ? !noGui && (withGTK3 || withPgtk) 100 102 101 103 # Options 102 104 , siteStart ? ./site-start.el ··· 120 122 assert withGpm -> stdenv.isLinux; 121 123 assert withNS -> stdenv.isDarwin && !(withX || variant == "macport"); 122 124 assert withPgtk -> withGTK3 && !withX; 123 - assert withXwidgets -> withGTK3; 125 + assert withXwidgets -> !noGui && (withGTK3 || withPgtk); 124 126 125 127 let 126 128 libGccJitLibraryPaths = [ ··· 134 136 then llvmPackages_6.stdenv 135 137 else stdenv) mkDerivation; 136 138 in 137 - mkDerivation (finalAttrs: (lib.optionalAttrs nativeComp { 139 + mkDerivation (finalAttrs: (lib.optionalAttrs withNativeCompilation { 138 140 env = { 139 141 NATIVE_FULL_AOT = "1"; 140 142 LIBRARY_PATH = lib.concatStringsSep ":" libGccJitLibraryPaths; ··· 142 144 } // { 143 145 pname = pname 144 146 + (if noGui then "-nox" 147 + else if variant == "macport" then "-macport" 145 148 else if withPgtk then "-pgtk" 146 149 else if withGTK3 then "-gtk3" 147 150 else if withGTK2 then "-gtk2" ··· 150 153 151 154 inherit src; 152 155 153 - patches = patches fetchpatch ++ lib.optionals nativeComp [ 156 + patches = patches fetchpatch ++ lib.optionals withNativeCompilation [ 154 157 (substituteAll { 155 158 src = if lib.versionOlder finalAttrs.version "29" 156 159 then ./native-comp-driver-options-28.patch ··· 242 245 motif 243 246 ] ++ lib.optionals (withX && withXwidgets) [ 244 247 glib-networking 245 - webkitgtk 246 - ] ++ lib.optionals nativeComp [ 248 + ] ++ lib.optionals withNativeCompilation [ 247 249 libgccjit 248 250 ] ++ lib.optionals withImageMagick [ 249 251 imagemagick ··· 266 268 ] ++ lib.optionals withX [ 267 269 Xaw3d 268 270 cairo 269 - 270 271 giflib 271 272 libXaw 272 273 libXpm ··· 274 275 libpng 275 276 librsvg 276 277 libtiff 278 + ] ++ lib.optionals withXwidgets [ 279 + webkitgtk 277 280 ] ++ lib.optionals stdenv.isDarwin [ 278 281 sigtool 279 282 ] ++ lib.optionals withNS [ ··· 325 328 ] 326 329 ++ (lib.optional stdenv.isDarwin (lib.withFeature withNS "ns")) 327 330 ++ lib.optional (!withToolkitScrollBars) "--without-toolkit-scroll-bars" 328 - ++ lib.optional nativeComp "--with-native-compilation" 331 + ++ lib.optional withNativeCompilation "--with-native-compilation" 329 332 ++ lib.optional withImageMagick "--with-imagemagick" 330 333 ++ lib.optional withTreeSitter "--with-tree-sitter" 331 334 ++ lib.optional withXinput2 "--with-xinput2" ··· 356 359 '' + lib.optionalString withNS '' 357 360 mkdir -p $out/Applications 358 361 mv nextstep/Emacs.app $out/Applications 359 - '' + lib.optionalString (nativeComp && (withNS || variant == "macport")) '' 362 + '' + lib.optionalString (withNativeCompilation && (withNS || variant == "macport")) '' 360 363 ln -snf $out/lib/emacs/*/native-lisp $out/Applications/Emacs.app/Contents/native-lisp 361 - '' + lib.optionalString nativeComp '' 364 + '' + lib.optionalString withNativeCompilation '' 362 365 echo "Generating native-compiled trampolines..." 363 366 # precompile trampolines in parallel, but avoid spawning one process per trampoline. 364 367 # 1000 is a rough lower bound on the number of trampolines compiled. ··· 379 382 ''; 380 383 381 384 passthru = { 382 - inherit nativeComp; 383 - treeSitter = withTreeSitter; 385 + inherit withNativeCompilation; 386 + inherit withTreeSitter; 384 387 pkgs = recurseIntoAttrs (emacsPackagesFor finalAttrs.finalPackage); 385 388 tests = { inherit (nixosTests) emacs-daemon; }; 386 389 };
+4 -13
pkgs/build-support/emacs/generic.nix
··· 2 2 3 3 { lib, stdenv, emacs, texinfo, writeText, gcc, ... }: 4 4 5 - with lib; 6 - 7 5 { pname 8 6 , version ? null 9 - 10 7 , buildInputs ? [] 11 8 , packageRequires ? [] 12 - 13 9 , meta ? {} 14 - 15 10 , ... 16 11 }@args: 17 12 18 13 let 19 - 20 14 defaultMeta = { 21 15 broken = false; 22 16 platforms = emacs.meta.platforms; 23 - } // optionalAttrs ((args.src.meta.homepage or "") != "") { 17 + } // lib.optionalAttrs ((args.src.meta.homepage or "") != "") { 24 18 homepage = args.src.meta.homepage; 25 19 }; 26 - 27 20 in 28 21 29 22 stdenv.mkDerivation ({ 30 - name = "emacs-${pname}${optionalString (version != null) "-${version}"}"; 23 + name = "emacs-${pname}${lib.optionalString (version != null) "-${version}"}"; 31 24 32 25 unpackCmd = '' 33 26 case "$curSrc" in ··· 68 61 meta = defaultMeta // meta; 69 62 } 70 63 71 - // lib.optionalAttrs (emacs.nativeComp or false) { 64 + // lib.optionalAttrs (emacs.withNativeCompilation or false) { 72 65 73 66 LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib"; 74 67 ··· 90 83 ''; 91 84 } 92 85 93 - // removeAttrs args [ "buildInputs" "packageRequires" 94 - "meta" 95 - ]) 86 + // removeAttrs args [ "buildInputs" "packageRequires" "meta" ])
+16 -25
pkgs/build-support/emacs/wrapper.nix
··· 32 32 33 33 */ 34 34 35 - { lib, lndir, makeWrapper, runCommand, gcc }: self: 36 - 37 - with lib; 38 - 35 + { lib, lndir, makeWrapper, runCommand, gcc }: 36 + self: 39 37 let 40 - 41 38 inherit (self) emacs; 42 - 43 - nativeComp = emacs.nativeComp or false; 44 - 45 - treeSitter = emacs.treeSitter or false; 46 - 39 + withNativeCompilation = emacs.withNativeCompilation or false; 40 + withTreeSitter = emacs.withTreeSitter or false; 47 41 in 48 - 49 42 packagesFun: # packages explicitly requested by the user 50 - 51 43 let 52 44 explicitRequires = 53 45 if lib.isFunction packagesFun 54 - then packagesFun self 46 + then packagesFun self 55 47 else packagesFun; 56 48 in 57 - 58 49 runCommand 59 - (appendToName "with-packages" emacs).name 50 + (lib.appendToName "with-packages" emacs).name 60 51 { 61 - nativeBuildInputs = [ emacs lndir makeWrapper ]; 62 52 inherit emacs explicitRequires; 53 + nativeBuildInputs = [ emacs lndir makeWrapper ]; 63 54 64 55 preferLocalBuild = true; 65 56 allowSubstitutes = false; ··· 69 60 deps = runCommand "emacs-packages-deps" 70 61 ({ 71 62 inherit explicitRequires lndir emacs; 72 - nativeBuildInputs = lib.optional nativeComp gcc; 73 - } // lib.optionalAttrs nativeComp { 63 + nativeBuildInputs = lib.optional withNativeCompilation gcc; 64 + } // lib.optionalAttrs withNativeCompilation { 74 65 inherit (emacs) LIBRARY_PATH; 75 66 }) 76 67 '' ··· 110 101 } 111 102 mkdir -p $out/bin 112 103 mkdir -p $out/share/emacs/site-lisp 113 - ${optionalString nativeComp '' 104 + ${lib.optionalString withNativeCompilation '' 114 105 mkdir -p $out/share/emacs/native-lisp 115 106 ''} 116 - ${optionalString treeSitter '' 107 + ${lib.optionalString withTreeSitter '' 117 108 mkdir -p $out/lib 118 109 ''} 119 110 ··· 137 128 linkEmacsPackage() { 138 129 linkPath "$1" "bin" "bin" 139 130 linkPath "$1" "share/emacs/site-lisp" "share/emacs/site-lisp" 140 - ${optionalString nativeComp '' 131 + ${lib.optionalString withNativeCompilation '' 141 132 linkPath "$1" "share/emacs/native-lisp" "share/emacs/native-lisp" 142 133 ''} 143 - ${optionalString treeSitter '' 134 + ${lib.optionalString withTreeSitter '' 144 135 linkPath "$1" "lib" "lib" 145 136 ''} 146 137 } ··· 171 162 (load-file "$emacs/share/emacs/site-lisp/site-start.el")) 172 163 (add-to-list 'load-path "$out/share/emacs/site-lisp") 173 164 (add-to-list 'exec-path "$out/bin") 174 - ${optionalString nativeComp '' 165 + ${lib.optionalString withNativeCompilation '' 175 166 (add-to-list 'native-comp-eln-load-path "$out/share/emacs/native-lisp/") 176 167 ''} 177 - ${optionalString treeSitter '' 168 + ${lib.optionalString withTreeSitter '' 178 169 (add-to-list 'treesit-extra-load-path "$out/lib/") 179 170 ''} 180 171 EOF ··· 189 180 # Byte-compiling improves start-up time only slightly, but costs nothing. 190 181 $emacs/bin/emacs --batch -f batch-byte-compile "$siteStart" "$subdirs" 191 182 192 - ${optionalString nativeComp '' 183 + ${lib.optionalString withNativeCompilation '' 193 184 $emacs/bin/emacs --batch \ 194 185 --eval "(add-to-list 'native-comp-eln-load-path \"$out/share/emacs/native-lisp/\")" \ 195 186 -f batch-native-compile "$siteStart" "$subdirs"
+1 -1
pkgs/tools/networking/mu/default.nix
··· 32 32 ''; 33 33 34 34 # AOT native-comp, mostly copied from pkgs/build-support/emacs/generic.nix 35 - postInstall = lib.optionalString (emacs.nativeComp or false) '' 35 + postInstall = lib.optionalString (emacs.withNativeCompilation or false) '' 36 36 mkdir -p $out/share/emacs/native-lisp 37 37 export EMACSLOADPATH=$out/share/emacs/site-lisp/mu4e: 38 38 export EMACSNATIVELOADPATH=$out/share/emacs/native-lisp: