How to add packages to a Jupyter Python kernel? (jupyter.nix)

Here is how:

# flake.nix
{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs";
    flake-utils.url = "github:numtide/flake-utils";
    jupyter.url = "github:kirelagin/jupyter.nix";
  };

  outputs = { self, nixpkgs, flake-utils, jupyter }:
    flake-utils.lib.eachDefaultSystem (system: {
      packages = {
        jupyter = jupyter.lib.makeJupyterLab {
          pkgs = nixpkgs.legacyPackages.${system};
          kernels = {
            "python3".ipykernel = {
              packages = pp: with pp; [
                numpy
                polars
              ];
              withPlotly = true;
            };
          };
        };
      };
      }
    );
}

And then just run it:

$ nix run .#jupyter

What

GitHub: kirelagin/jupyter.nix

Dead-simple configuration for Jupyter, based on the NixOS module system, but entirely standalone (well, still requires Nix, duh). A couple of kernels supported out of the box (currently Python and Haskell, please contribute more!) – for these, you essentially just list the packages you want in the environment. Implementing new kernel types is almost trivial as well.

You will find all the details and more examples in the README.

Why

I am a very unsophisticated user of Jupyter: all I want is to list the Python packages that I need and see it run, that’s it. I used to be able to do this with jupyterWith some years ago, however in year 2026 I can’t figure out how to use jupyenv any more (also, seems to be unmaintained and does not work with current Nixpkgs at all). That, and everything else nicely summarised in Criticism of the new jupyterWith.

There also seems to exist something relevant in Nixpkgs proper, but I could not figure out how to use it either (and I’ve been with the Nix crowd for quite a while, mind you!). For the record, I don’t think Nixpkgs is a good place for these kinds of utilities. The correct place is, you guessed it, a separate flake repo dedicated to doing one thing and doing it really well.

What’s next

To be honest, the library is feature-complete, as far as I am concerned, at least at the moment. Who knows, maybe now that I have an easy way to launch Jupyter, I will get to use it more, and become interested in more complex concepts, such as extensions or settings – these are the most obvious missing pieces. The reason they are missing is purely because I’ve never used one!

If something could make your Jupyter life easier if it was in jupyter.nix, let me know, create an issue or, best of all, send a pull request. Contribute a new kernel type for your favourite language, it’s super easy, I promise!

2 Likes

Cool project ! I took the liberty to update the title to make it more relevant.

Wait, what, people can now randomly edit others’ posts, or is it some sort of moderator rights? To be honest, I’d rather you not, but whatever, what’s done is done.

Yes, looks like it.

Anyway, I restored it.