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