Clone of https://github.com/NixOS/nixpkgs.git (to stress-test knotserver)
at devShellTools-shell 45 lines 1.2 kB view raw
1{ 2 python3, 3 jupyter-kernel, 4 lib, 5}: 6 7let 8 mkConsole = 9 { 10 definitions ? jupyter-kernel.default, 11 kernel ? null, 12 }: 13 (python3.buildEnv.override { 14 extraLibs = [ python3.pkgs.jupyter-console ]; 15 makeWrapperArgs = [ 16 "--set JUPYTER_PATH ${jupyter-kernel.create { inherit definitions; }}" 17 ] 18 ++ lib.optionals (kernel != null) [ 19 "--add-flags --kernel" 20 "--add-flags ${kernel}" 21 ]; 22 }).overrideAttrs 23 (oldAttrs: { 24 # To facilitate running nix run .#jupyter-console 25 meta = oldAttrs.meta // { 26 mainProgram = "jupyter-console"; 27 }; 28 }); 29 30in 31 32{ 33 # Build a console derivation with an arbitrary set of definitions, and an optional kernel to use. 34 # If the kernel argument is not supplied, Jupyter console will pick a kernel to run from the ones 35 # available on the system. 36 inherit mkConsole; 37 38 # An ergonomic way to start a console with a single kernel. 39 withSingleKernel = 40 definition: 41 mkConsole { 42 definitions = lib.listToAttrs [ (lib.nameValuePair definition.language definition) ]; 43 kernel = definition.language; 44 }; 45}