From c91c353b5dcc077c4ea60d7104ed784330109fe7 Mon Sep 17 00:00:00 2001 From: Lin Jian Date: Tue, 4 Oct 2022 22:57:02 +0800 Subject: Split into two overlays: one for emacs and one for emacs packages Emacs packages in nixpkgs have binary cache since [1]. It is useful to split the whole overlay into two seperated ones so that users can use emacs packages in nixpkgs with emacsWithPackagesFromUsePackage or emacsWithPackagesFromPackageRequires in this overlay. [1]: https://github.com/NixOS/nixpkgs/pull/188110 --- overlays/default.nix | 209 ++------------------------------------------------- overlays/emacs.nix | 143 +++++++++++++++++++++++++++++++++++ overlays/package.nix | 67 +++++++++++++++++ 3 files changed, 217 insertions(+), 202 deletions(-) create mode 100644 overlays/emacs.nix create mode 100644 overlays/package.nix (limited to 'overlays') diff --git a/overlays/default.nix b/overlays/default.nix index 70d10f8346de..089b5494dca9 100644 --- a/overlays/default.nix +++ b/overlays/default.nix @@ -1,205 +1,10 @@ self: super: let - mkExDrv = emacsPackages: name: args: - let - repoMeta = super.lib.importJSON (./repos/exwm/. + "/${name}.json"); - in - emacsPackages.melpaBuild ( - args // { - pname = name; - ename = name; - version = repoMeta.version; - commit = repoMeta.rev; - - recipe = builtins.toFile "recipe" '' - (${name} :fetcher github - :repo "ch11ng/${name}") - ''; - - src = super.fetchFromGitHub { - owner = "ch11ng"; - repo = name; - inherit (repoMeta) rev sha256; - }; - } - ); - - mkGitEmacs = namePrefix: jsonFile: { ... }@args: - let - repoMeta = super.lib.importJSON jsonFile; - fetcher = - if repoMeta.type == "savannah" then - super.fetchFromSavannah - else if repoMeta.type == "github" then - super.fetchFromGitHub - else - throw "Unknown repository type ${repoMeta.type}!"; - in - builtins.foldl' - (drv: fn: fn drv) - super.emacs - [ - - (drv: drv.override ({ srcRepo = true; } // args)) - - ( - drv: drv.overrideAttrs ( - old: { - name = "${namePrefix}-${repoMeta.version}"; - inherit (repoMeta) version; - src = fetcher (builtins.removeAttrs repoMeta [ "type" "version" ]); - - patches = [ ]; - - postPatch = old.postPatch + '' - substituteInPlace lisp/loadup.el \ - --replace '(emacs-repository-get-version)' '"${repoMeta.rev}"' \ - --replace '(emacs-repository-get-branch)' '"master"' - '' + - # XXX: remove when https://github.com/NixOS/nixpkgs/pull/193621 is merged - (super.lib.optionalString (old ? NATIVE_FULL_AOT) - (let backendPath = (super.lib.concatStringsSep " " - (builtins.map (x: ''\"-B${x}\"'') [ - # Paths necessary so the JIT compiler finds its libraries: - "${super.lib.getLib self.libgccjit}/lib" - "${super.lib.getLib self.libgccjit}/lib/gcc" - "${super.lib.getLib self.stdenv.cc.libc}/lib" - - # Executable paths necessary for compilation (ld, as): - "${super.lib.getBin self.stdenv.cc.cc}/bin" - "${super.lib.getBin self.stdenv.cc.bintools}/bin" - "${super.lib.getBin self.stdenv.cc.bintools.bintools}/bin" - ])); - in '' - substituteInPlace lisp/emacs-lisp/comp.el --replace \ - "(defcustom comp-libgccjit-reproducer nil" \ - "(setq native-comp-driver-options '(${backendPath})) -(defcustom comp-libgccjit-reproducer nil" - '')); - } - ) - ) - - # reconnect pkgs to the built emacs - ( - drv: - let - result = drv.overrideAttrs (old: { - passthru = old.passthru // { - pkgs = self.emacsPackagesFor result; - }; - }); - in - result - ) - ]; - - mkPgtkEmacs = namePrefix: jsonFile: { ... }@args: (mkGitEmacs namePrefix jsonFile args).overrideAttrs ( - old: { - configureFlags = (super.lib.remove "--with-xft" old.configureFlags) - ++ super.lib.singleton "--with-pgtk"; - } - ); - - emacsGit = mkGitEmacs "emacs-git" ./repos/emacs/emacs-master.json { withSQLite3 = true; withWebP = true; }; - - emacsNativeComp = super.emacsNativeComp or (mkGitEmacs "emacs-native-comp" ./repos/emacs/emacs-unstable.json { nativeComp = true; }); - - emacsGitNativeComp = mkGitEmacs "emacs-git-native-comp" ./repos/emacs/emacs-master.json { - withSQLite3 = true; - withWebP = true; - nativeComp = true; - }; - - emacsPgtk = mkPgtkEmacs "emacs-pgtk" ./repos/emacs/emacs-master.json { withSQLite3 = true; withGTK3 = true; }; - - emacsPgtkNativeComp = mkPgtkEmacs "emacs-pgtk-native-comp" ./repos/emacs/emacs-master.json { nativeComp = true; withSQLite3 = true; withGTK3 = true; }; - - emacsUnstable = (mkGitEmacs "emacs-unstable" ./repos/emacs/emacs-unstable.json { }); - + inherit (super.lib) foldl' flip extends; + overlays = [ + # package overlay must be applied before emacs overlay + (import ./package.nix) + (import ./emacs.nix) + ]; in -{ - inherit emacsGit emacsUnstable; - - inherit emacsNativeComp emacsGitNativeComp; - - inherit emacsPgtk emacsPgtkNativeComp; - - emacsGit-nox = ( - ( - emacsGit.override { - withNS = false; - withX = false; - withGTK2 = false; - withGTK3 = false; - withWebP = false; - } - ).overrideAttrs ( - oa: { - name = "${oa.name}-nox"; - } - ) - ); - - emacsUnstable-nox = ( - ( - emacsUnstable.override { - withNS = false; - withX = false; - withGTK2 = false; - withGTK3 = false; - withWebP = false; - } - ).overrideAttrs ( - oa: { - name = "${oa.name}-nox"; - } - ) - ); - - emacsWithPackagesFromUsePackage = import ./elisp.nix { pkgs = self; }; - - emacsWithPackagesFromPackageRequires = import ./packreq.nix { pkgs = self; }; - - emacsPackagesFor = emacs: ( - (super.emacsPackagesFor emacs).overrideScope' ( - eself: esuper: - let - melpaStablePackages = esuper.melpaStablePackages.override { - archiveJson = ./repos/melpa/recipes-archive-melpa.json; - }; - - melpaPackages = esuper.melpaPackages.override { - archiveJson = ./repos/melpa/recipes-archive-melpa.json; - }; - - elpaPackages = esuper.elpaPackages.override { - generated = ./repos/elpa/elpa-generated.nix; - }; - - epkgs = esuper.override { - inherit melpaStablePackages melpaPackages elpaPackages; - }; - - in - epkgs - // super.lib.optionalAttrs (super.lib.hasAttr "nongnuPackages" esuper) { - nongnuPackages = esuper.nongnuPackages.override { - generated = ./repos/nongnu/nongnu-generated.nix; - }; - } // { - xelb = mkExDrv eself "xelb" { - packageRequires = [ eself.cl-generic eself.emacs ]; - }; - - exwm = mkExDrv eself "exwm" { - packageRequires = [ eself.xelb ]; - }; - } - ) - ); - -} // super.lib.optionalAttrs (super.config.allowAliases or true) { - emacsGcc = builtins.trace "emacsGcc has been renamed to emacsNativeComp, please update your expression." emacsNativeComp; - emacsPgtkGcc = builtins.trace "emacsPgtkGcc has been renamed to emacsPgtkNativeComp, please update your expression." emacsPgtkNativeComp; -} +foldl' (flip extends) (_: super) overlays self diff --git a/overlays/emacs.nix b/overlays/emacs.nix new file mode 100644 index 000000000000..1b93d4473ec0 --- /dev/null +++ b/overlays/emacs.nix @@ -0,0 +1,143 @@ +self: super: +let + mkGitEmacs = namePrefix: jsonFile: { ... }@args: + let + repoMeta = super.lib.importJSON jsonFile; + fetcher = + if repoMeta.type == "savannah" then + super.fetchFromSavannah + else if repoMeta.type == "github" then + super.fetchFromGitHub + else + throw "Unknown repository type ${repoMeta.type}!"; + in + builtins.foldl' + (drv: fn: fn drv) + super.emacs + [ + + (drv: drv.override ({ srcRepo = true; } // args)) + + ( + drv: drv.overrideAttrs ( + old: { + name = "${namePrefix}-${repoMeta.version}"; + inherit (repoMeta) version; + src = fetcher (builtins.removeAttrs repoMeta [ "type" "version" ]); + + patches = [ ]; + + postPatch = old.postPatch + '' + substituteInPlace lisp/loadup.el \ + --replace '(emacs-repository-get-version)' '"${repoMeta.rev}"' \ + --replace '(emacs-repository-get-branch)' '"master"' + '' + + # XXX: remove when https://github.com/NixOS/nixpkgs/pull/193621 is merged + (super.lib.optionalString (old ? NATIVE_FULL_AOT) + (let backendPath = (super.lib.concatStringsSep " " + (builtins.map (x: ''\"-B${x}\"'') [ + # Paths necessary so the JIT compiler finds its libraries: + "${super.lib.getLib self.libgccjit}/lib" + "${super.lib.getLib self.libgccjit}/lib/gcc" + "${super.lib.getLib self.stdenv.cc.libc}/lib" + + # Executable paths necessary for compilation (ld, as): + "${super.lib.getBin self.stdenv.cc.cc}/bin" + "${super.lib.getBin self.stdenv.cc.bintools}/bin" + "${super.lib.getBin self.stdenv.cc.bintools.bintools}/bin" + ])); + in '' + substituteInPlace lisp/emacs-lisp/comp.el --replace \ + "(defcustom comp-libgccjit-reproducer nil" \ + "(setq native-comp-driver-options '(${backendPath})) +(defcustom comp-libgccjit-reproducer nil" + '')); + } + ) + ) + + # reconnect pkgs to the built emacs + ( + drv: + let + result = drv.overrideAttrs (old: { + passthru = old.passthru // { + pkgs = self.emacsPackagesFor result; + }; + }); + in + result + ) + ]; + + mkPgtkEmacs = namePrefix: jsonFile: { ... }@args: (mkGitEmacs namePrefix jsonFile args).overrideAttrs ( + old: { + configureFlags = (super.lib.remove "--with-xft" old.configureFlags) + ++ super.lib.singleton "--with-pgtk"; + } + ); + + emacsGit = mkGitEmacs "emacs-git" ../repos/emacs/emacs-master.json { withSQLite3 = true; withWebP = true; }; + + emacsNativeComp = super.emacsNativeComp or (mkGitEmacs "emacs-native-comp" ../repos/emacs/emacs-unstable.json { nativeComp = true; }); + + emacsGitNativeComp = mkGitEmacs "emacs-git-native-comp" ../repos/emacs/emacs-master.json { + withSQLite3 = true; + withWebP = true; + nativeComp = true; + }; + + emacsPgtk = mkPgtkEmacs "emacs-pgtk" ../repos/emacs/emacs-master.json { withSQLite3 = true; withGTK3 = true; }; + + emacsPgtkNativeComp = mkPgtkEmacs "emacs-pgtk-native-comp" ../repos/emacs/emacs-master.json { nativeComp = true; withSQLite3 = true; withGTK3 = true; }; + + emacsUnstable = (mkGitEmacs "emacs-unstable" ../repos/emacs/emacs-unstable.json { }); + +in +{ + inherit emacsGit emacsUnstable; + + inherit emacsNativeComp emacsGitNativeComp; + + inherit emacsPgtk emacsPgtkNativeComp; + + emacsGit-nox = ( + ( + emacsGit.override { + withNS = false; + withX = false; + withGTK2 = false; + withGTK3 = false; + withWebP = false; + } + ).overrideAttrs ( + oa: { + name = "${oa.name}-nox"; + } + ) + ); + + emacsUnstable-nox = ( + ( + emacsUnstable.override { + withNS = false; + withX = false; + withGTK2 = false; + withGTK3 = false; + withWebP = false; + } + ).overrideAttrs ( + oa: { + name = "${oa.name}-nox"; + } + ) + ); + + emacsWithPackagesFromUsePackage = import ../elisp.nix { pkgs = self; }; + + emacsWithPackagesFromPackageRequires = import ../packreq.nix { pkgs = self; }; + +} // super.lib.optionalAttrs (super.config.allowAliases or true) { + emacsGcc = builtins.trace "emacsGcc has been renamed to emacsNativeComp, please update your expression." emacsNativeComp; + emacsPgtkGcc = builtins.trace "emacsPgtkGcc has been renamed to emacsPgtkNativeComp, please update your expression." emacsPgtkNativeComp; +} diff --git a/overlays/package.nix b/overlays/package.nix new file mode 100644 index 000000000000..f85fd8f14053 --- /dev/null +++ b/overlays/package.nix @@ -0,0 +1,67 @@ +self: super: +let + mkExDrv = emacsPackages: name: args: + let + repoMeta = super.lib.importJSON (../repos/exwm/. + "/${name}.json"); + in + emacsPackages.melpaBuild ( + args // { + pname = name; + ename = name; + version = repoMeta.version; + commit = repoMeta.rev; + + recipe = builtins.toFile "recipe" '' + (${name} :fetcher github + :repo "ch11ng/${name}") + ''; + + src = super.fetchFromGitHub { + owner = "ch11ng"; + repo = name; + inherit (repoMeta) rev sha256; + }; + } + ); + +in +{ + emacsPackagesFor = emacs: ( + (super.emacsPackagesFor emacs).overrideScope' ( + eself: esuper: + let + melpaStablePackages = esuper.melpaStablePackages.override { + archiveJson = ../repos/melpa/recipes-archive-melpa.json; + }; + + melpaPackages = esuper.melpaPackages.override { + archiveJson = ../repos/melpa/recipes-archive-melpa.json; + }; + + elpaPackages = esuper.elpaPackages.override { + generated = ../repos/elpa/elpa-generated.nix; + }; + + epkgs = esuper.override { + inherit melpaStablePackages melpaPackages elpaPackages; + }; + + in + epkgs + // super.lib.optionalAttrs (super.lib.hasAttr "nongnuPackages" esuper) { + nongnuPackages = esuper.nongnuPackages.override { + generated = ../repos/nongnu/nongnu-generated.nix; + }; + } // { + xelb = mkExDrv eself "xelb" { + packageRequires = [ eself.cl-generic eself.emacs ]; + }; + + exwm = mkExDrv eself "exwm" { + packageRequires = [ eself.xelb ]; + }; + } + ) + ); + +} -- cgit 1.4.1