Jupyter service with GCC access

I’m attempting to configure a jupyter service that can compile Cython. It therefore needs access to GCC. How can I do this? This is the current configuration I have. Thanks!

{ pkgs
, ...
}:

{
  services.jupyter = {
    enable = true;
    command = "jupyter-notebook";
    group = "users";
    ip = "localhost";
    port = 8888;
    user = "matt";
    notebookDir = "~/.jupyter";

    kernels = {
      python3 =
        let
          env = (pkgs.python3.withPackages (p: with p;
            [
              numpy
              matplotlib
              cython
              scipy
              ipykernel
              pandas
            ]));
        in
        {
          displayName = "Python 3 Jupyter kernel";
          argv = [
            "${env.interpreter}"
            "-m"
            "ipykernel_launcher"
            "-f"
            "{connection_file}"
          ];
          language = "python";
        };
    };
  };
}
1 Like

This is really hacky, but change

          argv = [
            "${env.interpreter}"

to

          argv = [
            "PATH=${lib.makeBinPath [ pkgs.stdenv.cc ]}"
            "${env.interpreter}"

I’m not sure the nature in which this is being executed. If it’s running in child processes, you should be able to do "PATH=${lib.makeBinPath [ pkgs.stdenv.cc ]}:$PATH" so you’re not unsetting other PATH paths. Just concerned that you may be getting an ever increasing PATH command if you keep appending from older invocations.

other option would be to use buildEnv’s postBuild hook, so you could run a hook which wraps each of the programs.

Best long-term solution would probably be to add support for declaring the PATH inside the service. Currently it only does:

        environment = {
          JUPYTER_PATH = toString kernels;
        };

something like:

    packages = mkOption {
      type = types.listOf types.package;
      default = [ ];
      description = ''
        Additional packages to be available on the PATH.
      '';
    };

    ....
    environment = {
       JUPYTER_PATH = toString kernels;
       PATH = lib.makeBinPath [ cfg.packages ]; 
    };

and then your configuration would just be:

  services.jupyter = {
    enable = true;
    packages = with pkgs; [ stdenv.cc ];
    ....

Python’s buildEnv supports setting makeWrapperArgs. That way, you can have non-Python deps per environment.

1 Like