Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

emacsPackages*: Move to emacs*.pkgs #107152

Merged
merged 2 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions doc/builders/packages/emacs.section.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

## Configuring Emacs {#sec-emacs-config}

The Emacs package comes with some extra helpers to make it easier to configure. `emacsWithPackages` allows you to manage packages from ELPA. This means that you will not have to install that packages from within Emacs. For instance, if you wanted to use `company` `counsel`, `flycheck`, `ivy`, `magit`, `projectile`, and `use-package` you could use this as a `~/.config/nixpkgs/config.nix` override:
The Emacs package comes with some extra helpers to make it easier to configure. `emacs.pkgs.withPackages` allows you to manage packages from ELPA. This means that you will not have to install that packages from within Emacs. For instance, if you wanted to use `company` `counsel`, `flycheck`, `ivy`, `magit`, `projectile`, and `use-package` you could use this as a `~/.config/nixpkgs/config.nix` override:

```nix
{
packageOverrides = pkgs: with pkgs; {
myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
myEmacs = emacs.pkgs.withPackages (epkgs: (with epkgs.melpaStablePackages; [
company
counsel
flycheck
Expand Down Expand Up @@ -84,7 +84,7 @@ You can install it like any other packages via `nix-env -iA myEmacs`. However, t
(projectile-global-mode))
'';

myEmacs = emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [
myEmacs = emacs.pkgs.withPackages (epkgs: (with epkgs.melpaStablePackages; [
(runCommand "default.el" {} ''
mkdir -p $out/share/emacs/site-lisp
cp ${myEmacsConfig} $out/share/emacs/site-lisp/default.el
Expand All @@ -103,14 +103,14 @@ You can install it like any other packages via `nix-env -iA myEmacs`. However, t

This provides a fairly full Emacs start file. It will load in addition to the user's presonal config. You can always disable it by passing `-q` to the Emacs command.

Sometimes `emacsWithPackages` is not enough, as this package set has some priorities imposed on packages (with the lowest priority assigned to Melpa Unstable, and the highest for packages manually defined in `pkgs/top-level/emacs-packages.nix`). But you can't control this priorities when some package is installed as a dependency. You can override it on per-package-basis, providing all the required dependencies manually - but it's tedious and there is always a possibility that an unwanted dependency will sneak in through some other package. To completely override such a package you can use `overrideScope'`.
Sometimes `emacs.pkgs.withPackages` is not enough, as this package set has some priorities imposed on packages (with the lowest priority assigned to Melpa Unstable, and the highest for packages manually defined in `pkgs/top-level/emacs-packages.nix`). But you can't control this priorities when some package is installed as a dependency. You can override it on per-package-basis, providing all the required dependencies manually - but it's tedious and there is always a possibility that an unwanted dependency will sneak in through some other package. To completely override such a package you can use `overrideScope'`.

```nix
overrides = self: super: rec {
haskell-mode = self.melpaPackages.haskell-mode;
...
};
((emacsPackagesGen emacs).overrideScope' overrides).emacsWithPackages
((emacsPackagesFor emacs).overrideScope' overrides).emacs.pkgs.withPackages
(p: with p; [
# here both these package will use haskell-mode of our own choice
ghc-mod
Expand Down
10 changes: 5 additions & 5 deletions nixos/modules/services/editors/emacs.xml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ $ ./result/bin/emacs

let
myEmacs = pkgs.emacs; <co xml:id="ex-emacsNix-2" />
emacsWithPackages = (pkgs.emacsPackagesGen myEmacs).emacsWithPackages; <co xml:id="ex-emacsNix-3" />
emacsWithPackages = (pkgs.emacsPackagesFor myEmacs).emacsWithPackages; <co xml:id="ex-emacsNix-3" />
in
emacsWithPackages (epkgs: (with epkgs.melpaStablePackages; [ <co xml:id="ex-emacsNix-4" />
magit # ; Integrate git &lt;C-x g&gt;
Expand Down Expand Up @@ -254,10 +254,10 @@ in
<example xml:id="module-services-emacs-querying-packages">
<title>Querying Emacs packages</title>
<programlisting><![CDATA[
nix-env -f "<nixpkgs>" -qaP -A emacsPackages.elpaPackages
nix-env -f "<nixpkgs>" -qaP -A emacsPackages.melpaPackages
nix-env -f "<nixpkgs>" -qaP -A emacsPackages.melpaStablePackages
nix-env -f "<nixpkgs>" -qaP -A emacsPackages.orgPackages
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.elpaPackages
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.melpaPackages
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.melpaStablePackages
nix-env -f "<nixpkgs>" -qaP -A emacs.pkgs.orgPackages
]]></programlisting>
</example>
</para>
Expand Down
2 changes: 1 addition & 1 deletion nixos/modules/services/x11/window-managers/exwm.nix
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ in
description = ''
Extra packages available to Emacs. The value must be a
function which receives the attrset defined in
<varname>emacsPackages</varname> as the sole argument.
<varname>emacs.pkgs</varname> as the sole argument.
'';
};
};
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/emacs-modes/elpa-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
To update the list of packages from MELPA,

1. Run `./update-elpa`.
2. Check for evaluation errors: `nix-instantiate ../../../.. -A emacsPackagesNg.elpaPackages`.
2. Check for evaluation errors: `nix-instantiate ../../../.. -A emacs.pkgs.elpaPackages`.
3. `git commit -m "elpa-packages $(date -Idate)" -- elpa-generated.nix`

## Update from overlay
Expand Down
4 changes: 2 additions & 2 deletions pkgs/applications/editors/emacs-modes/melpa-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ To update the list of packages from MELPA,

1. Run ./update-melpa
2. Check for evaluation errors:
env NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ../../../../ -A emacsPackages.melpaStablePackages
env NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ../../../../ -A emacsPackages.melpaPackages
env NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ../../../../ -A emacs.pkgs..melpaStablePackages
env NIXPKGS_ALLOW_BROKEN=1 nix-instantiate --show-trace ../../../../ -A emacs.pkgs..melpaPackages
3. `git commit -m "melpa-packages: $(date -Idate)" recipes-archive-melpa.json`

## Update from overlay
Expand Down
2 changes: 1 addition & 1 deletion pkgs/applications/editors/emacs-modes/org-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
To update the list of packages from Org (ELPA),

1. Run `./update-org`.
2. Check for evaluation errors: `nix-instantiate ../../../.. -A emacsPackagesNg.orgPackages`.
2. Check for evaluation errors: `nix-instantiate ../../../.. -A emacs.pkgs.orgPackages`.
3. `git commit -m "org-packages $(date -Idate)" -- org-generated.nix`

*/
Expand Down
14 changes: 7 additions & 7 deletions pkgs/applications/editors/emacs-modes/update-from-overlay
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ export NIXPKGS_ALLOW_BROKEN=1
# You can use this to avoid running lengthy code generation jobs locally

curl -s -O https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/elpa/elpa-generated.nix
nix-instantiate ../../../.. -A emacsPackagesNg.elpaPackages --show-trace
git diff --exit-code elpa-generated.nix > /dev/null || git commit -m "emacsPackages.elpa-packages: $(date --iso)" -- elpa-generated.nix
nix-instantiate ../../../.. -A emacs.pkgs.elpaPackages --show-trace
git diff --exit-code elpa-generated.nix > /dev/null || git commit -m "emacs.pkgs.elpa-packages: $(date --iso)" -- elpa-generated.nix

curl -s -O https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/org/org-generated.nix
nix-instantiate ../../../.. -A emacsPackagesNg.orgPackages --show-trace
git diff --exit-code org-generated.nix > /dev/null || git commit -m "emacsPackages.org-packages: $(date --iso)" -- org-generated.nix
nix-instantiate ../../../.. -A emacs.pkgs.orgPackages --show-trace
git diff --exit-code org-generated.nix > /dev/null || git commit -m "emacs.pkgs.org-packages: $(date --iso)" -- org-generated.nix

curl -s -O https://raw.githubusercontent.com/nix-community/emacs-overlay/master/repos/melpa/recipes-archive-melpa.json
env nix-instantiate --show-trace ../../../../ -A emacsPackages.melpaStablePackages
env nix-instantiate --show-trace ../../../../ -A emacsPackages.melpaPackages
git diff --exit-code recipes-archive-melpa.json > /dev/null || git commit -m "emacsPackages.melpa-packages: $(date --iso)" -- recipes-archive-melpa.json
nix-instantiate --show-trace ../../../../ -A emacs.pkgs.melpaStablePackages
nix-instantiate --show-trace ../../../../ -A emacs.pkgs.melpaPackages
git diff --exit-code recipes-archive-melpa.json > /dev/null || git commit -m "emacs.pkgs.melpa-packages: $(date --iso)" -- recipes-archive-melpa.json
2 changes: 1 addition & 1 deletion pkgs/applications/editors/emacs-modes/updater-emacs.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
let
pkgs = import ../../../.. {};

emacsEnv = (pkgs.emacsPackagesFor pkgs.emacs).emacsWithPackages (epkgs: let
emacsEnv = pkgs.emacs.withPackages (epkgs: let

promise = epkgs.trivialBuild {
pname = "promise";
Expand Down
9 changes: 5 additions & 4 deletions pkgs/applications/editors/emacs/generic.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
, libtiff, librsvg, gconf, libxml2, imagemagick, gnutls, libselinux
, alsaLib, cairo, acl, gpm, AppKit, GSS, ImageIO, m17n_lib, libotf
, jansson, harfbuzz
, dontRecurseIntoAttrs ,emacsPackagesFor
, libgccjit, targetPlatform, makeWrapper # native-comp params
, systemd ? null
, withX ? !stdenv.isDarwin
Expand Down Expand Up @@ -40,9 +41,7 @@ assert withGTK3 -> !withGTK2 && gtk3-x11 != null;
assert withXwidgets -> withGTK3 && webkitgtk != null;


let

in stdenv.mkDerivation (lib.optionalAttrs nativeComp {
let emacs = stdenv.mkDerivation (lib.optionalAttrs nativeComp {
NATIVE_FULL_AOT = "1";
LIBRARY_PATH = "${lib.getLib stdenv.cc.libc}/lib";
} // lib.optionalAttrs stdenv.isDarwin {
Expand Down Expand Up @@ -175,6 +174,7 @@ in stdenv.mkDerivation (lib.optionalAttrs nativeComp {

passthru = {
inherit nativeComp;
pkgs = dontRecurseIntoAttrs (emacsPackagesFor emacs);
};

meta = with lib; {
Expand All @@ -201,4 +201,5 @@ in stdenv.mkDerivation (lib.optionalAttrs nativeComp {
separately.
'';
};
})
});
in emacs
14 changes: 7 additions & 7 deletions pkgs/build-support/emacs/wrapper.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

# Usage

`emacsWithPackages` takes a single argument: a function from a package
`emacs.pkgs.withPackages` takes a single argument: a function from a package
set to a list of packages (the packages that will be available in
Emacs). For example,
```
emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
emacs.pkgs.withPackages (epkgs: [ epkgs.evil epkgs.magit ])
```
All the packages in the list should come from the provided package
set. It is possible to add any package to the list, but the provided
Expand All @@ -15,19 +15,19 @@ the correct version of Emacs.

# Overriding

`emacsWithPackages` inherits the package set which contains it, so the
`emacs.pkgs.withPackages` inherits the package set which contains it, so the
correct way to override the provided package set is to override the
set which contains `emacsWithPackages`. For example, to override
`emacsPackages.emacsWithPackages`,
set which contains `emacs.pkgs.withPackages`. For example, to override
`emacs.pkgs.emacs.pkgs.withPackages`,
```
let customEmacsPackages =
emacsPackages.overrideScope' (self: super: {
emacs.pkgs.overrideScope' (self: super: {
# use a custom version of emacs
emacs = ...;
# use the unstable MELPA version of magit
magit = self.melpaPackages.magit;
});
in customEmacsPackages.emacsWithPackages (epkgs: [ epkgs.evil epkgs.magit ])
in customEmacsPackages.emacs.pkgs.withPackages (epkgs: [ epkgs.evil epkgs.magit ])
```

*/
Expand Down
8 changes: 4 additions & 4 deletions pkgs/development/tools/cask/default.nix
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
{ stdenv, fetchurl, python, emacsPackages }:
{ stdenv, fetchurl, python, emacs }:

stdenv.mkDerivation rec {
pname = "cask";

inherit (emacsPackages.melpaStablePackages.cask) src version;
inherit (emacs.pkgs.melpaStablePackages.cask) src version;

doCheck = true;

nativeBuildInputs = [ emacsPackages.emacs ];
buildInputs = with emacsPackages; [
nativeBuildInputs = [ emacs ];
buildInputs = with emacs.pkgs; [
s f dash ansi ecukes servant ert-runner el-mock
noflet ert-async shell-split-string git package-build
] ++ [
Expand Down
8 changes: 7 additions & 1 deletion pkgs/top-level/aliases.nix
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,13 @@ mapAliases ({
emacsPackagesGen = emacsPackagesFor; # added 2018-08-18
emacsPackagesNgGen = emacsPackagesFor; # added 2018-08-18
emacsPackagesNgFor = emacsPackagesFor; # added 2019-08-07
emacsPackagesNg = emacsPackages; # added 2019-08-07
emacsPackagesNg = emacs.pkgs; # added 2019-08-07
emacs26Packages = emacs26.pkgs; # added 2020-12-18
emacs27Packages = emacs27.pkgs; # added 2020-12-18
emacs26WithPackages = emacs26.pkgs.withPackages; # added 2020-12-18
emacs27WithPackages = emacs27.pkgs.withPackages; # added 2020-12-18
emacsWithPackages = emacs.pkgs.withPackages; # added 2020-12-18
emacsPackages = emacs.pkgs; # added 2020-12-18
emby = throw "The Emby derivation has been removed, see jellyfin instead for a free software fork."; # added 2019-05-01
enblendenfuse = enblend-enfuse; # 2015-09-30
evolution_data_server = evolution-data-server; # added 2018-02-25
Expand Down
11 changes: 2 additions & 9 deletions pkgs/top-level/all-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -500,7 +500,7 @@ in

mkShell = callPackage ../build-support/mkshell { };

nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacsPackages) inherit-local; };
nixBufferBuilders = import ../build-support/emacs/buffer.nix { inherit (pkgs) lib writeText; inherit (emacs.pkgs) inherit-local; };

nix-gitignore = callPackage ../build-support/nix-gitignore { };

Expand Down Expand Up @@ -9788,7 +9788,7 @@ in
# package. Wishing we could merge it into one irony package, to avoid this issue,
# but its emacs-side expression is autogenerated, and we can't hook into it (other
# than peek into its version).
inherit (emacsPackages.melpaStablePackages) irony;
inherit (emacs.pkgs.melpaStablePackages) irony;
};

hugs = callPackage ../development/interpreters/hugs { };
Expand Down Expand Up @@ -21424,9 +21424,7 @@ in
elvis = callPackage ../applications/editors/elvis { };

emacs = emacs27;
emacsPackages = emacs27Packages;
emacs-nox = emacs27-nox;
emacsWithPackages = emacsPackages.emacsWithPackages;

emacs27 = callPackage ../applications/editors/emacs/27.nix {
# use override to enable additional features
Expand Down Expand Up @@ -21497,11 +21495,6 @@ in
};
};

emacs26Packages = dontRecurseIntoAttrs (emacsPackagesFor emacs26);
emacs27Packages = dontRecurseIntoAttrs (emacsPackagesFor emacs27);
emacs26WithPackages = emacs26Packages.emacsWithPackages;
emacs27WithPackages = emacs27Packages.emacsWithPackages;

inherit (gnome3) empathy;

enhanced-ctorrent = callPackage ../applications/networking/enhanced-ctorrent { };
Expand Down
1 change: 1 addition & 0 deletions pkgs/top-level/emacs-packages.nix
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ in lib.makeScope newScope (self: lib.makeOverridable ({
// {
inherit emacs melpaBuild trivialBuild;
emacsWithPackages = emacsWithPackages self;
withPackages = emacsWithPackages self;
})
) {})
4 changes: 2 additions & 2 deletions pkgs/top-level/packages-config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
"nvidiaPackages"
"sourceHanPackages"
"atomPackages"
"emacs26Packages"
"emacs27Packages"
"emacs26.pkgs"
"emacs27.pkgs"
"steamPackages"
"ut2004Packages"
"zeroadPackages"
Expand Down