Testing emacsPackages

Hey!

I think the idea of NixOS is great and I would like to contribute to the project. First I will try to submit a first nixpkg and maintain it. It is an emacsPackage.

I followed the following instructions: Nixpkgs/Create and debug packages - NixOS Wiki

Everything worked fine, the only problem is that I don’t know how to test the package.

nix-build $NIXPKGS --run-env -A emacsPackages.lsp-bridge

works without problems, but I need to run

nix-shell $NIXPKGS -p (pkgs.emacsPackagesFor pkgs.emacs28).emacsWithPackages(epkgs: [ pkgs.emacsPackages.lsp-bridge ])

to add the package to the load-path from emacs.

But it says undefined variable lsp-bridge. does anyone have a tip how to test new emacs nixpkgs?

This is my default.nix:

{ lib
, trivialBuild
, fetchFromGitHub
, writeText
, python310Packages
, posframe
, markdown-mode
, yasnippet
}:

let
  rev = "7dfeeb640d14697755e2ac7997af0ec6c413197f";
in trivialBuild {
  pname = "lsp-bridge";
  version = "20230103";

  commit = rev;

  src = fetchFromGitHub {
    owner = "manateelazycat";
    repo = "lsp-bridge";
    inherit rev;
    sha256 = "sha256-sB5niigN0rdtqeprlZAJEKgAuQDkcUMbbL9yTnrdoLg=";
  };

  packageRequires = [
    python310Packages.epc
    python310Packages.orjson
    python310Packages.sexpdata
    python310Packages.six
    posframe
    markdown-mode
    yasnippet
  ];

  meta = {
    description = "Lsp-bridge's goal is to become the fastest LSP client in Emacs.";
    longDescription = ''
        Lsp-bridge uses python's threading technology to build caches that bridge Emacs and LSP server.
        Lsp-bridge will provide smooth completion experience without compromise to slow down emacs' performance.
      '';
    license = lib.licenses.gpl3;
    maintainers = with lib.maintainers; [ fxttr ];
  };
}
  • fxttr

I’m not an expert in emacs packaging, but first it depends what you mean to “test” your package. Are you testing your derivation directly, or the integration of this derivation into nixpkgs? If you just want to test the derivation, you don’t need any copy of nixpkgs, you should be able to just call your package with epkgs.callPackage ./default.nix {}, with something like:

nix-shell -p "(pkgs.emacsPackagesFor pkgs.emacs28).emacsWithPackages(epkgs: [ (epkgs.callPackage ./default.nix {}) ])"

If you want to integrate it in nixpkgs, and if the package is not present in elpa/melpa, then you can add it in the list in pkgs/applications/editors/emacs/elisp-packages/manual-packages.nix with something like:

# …
# make sure to move your default.nix in pkgs/applications/editors/emacs/elisp-packages/lsp-bridge/default.nix
lsp-bridge = callPackage ./lsp-bridge {};
# …

Then, it should appear as any other package I guess (but I’ve not tested), using something like:

$ nix-shell -I nixpkgs=$HOME/nixpkgs -p "(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.lsp-bridge ])"
1 Like

Hey,

nix-shell -p "(pkgs.emacsPackagesFor pkgs.emacs28).emacsWithPackages(epkgs: [ (epkgs.callPackage ./default.nix {}) ])"

seems to do what I want. Thanks! I already added it to manual-packages.nix, it’s not in melpa/elpa.

nix-shell -I nixpkgs=$HOME/nixpkgs -p "(emacsPackagesFor pkgs.emacs28).emacsWithPackages (epkgs: [ epkgs.lsp-bridge ])"

Also works. Seems like I forgot the -I.
Would it make sense to add this to the wiki entry?

1 Like

Sure, feel free to edit the wiki if something is unclear. Note that you might want to edit the emac specific page in Emacs - NixOS Wiki

PS: to help people to quickly see that the issue is solved (this way they can only open non-solved issues), it’s a good idea to mark the solution as a solution.

edit ahah the solution button is different from the like button ^^ You can put only one solution, which will be reported appropriately when searching unsolved packages, unlike likes. But nevermind ^^