Restructure to be more modular and more useable

This commit is contained in:
Evie Litherland-Smith 2024-05-09 16:37:42 +01:00
parent eb2e035ba9
commit 71a134f1cd
7 changed files with 76 additions and 53 deletions

25
default.nix Normal file
View file

@ -0,0 +1,25 @@
{
mkShellNoCC,
python3,
mkShellHook,
kernels ? [],
extraPackages ? [],
extraPythonPackages ? [],
}:
mkShellNoCC {
nativeBuildInputs =
[
(python3.withPackages (ps:
with ps;
[
jupyterlab
jupyterlab-git
nbdime
nbconvert
python-lsp-server
]
++ extraPythonPackages))
]
++ extraPackages;
shellHook = mkShellHook kernels;
}

View file

@ -15,12 +15,14 @@
system = "x86_64-linux";
pkgs = import nixpkgs {inherit system;};
in {
packages.${system} = {
lib.${system} = {
mkIpythonKernel = pkgs.callPackage ./lib/ipykernel.nix {};
mkShellHook = import ./lib/shellhook.nix;
};
packages.${system} = with self.lib.${system}; {
poetry2nix = poetry2nix.lib.mkPoetry2Nix {inherit pkgs;};
catppuccin_jupyterlab = import ./catppuccin_jupyterlab/default.nix;
mkIpythonKernel = attrs: (pkgs.callPackage ./ipykernel.nix attrs);
mkJupyterShell = attrs: (pkgs.callPackage ./jupyter.nix attrs);
default = self.packages.${system}.mkJupyterShell;
default = pkgs.callPackage ./default.nix {inherit mkShellHook;};
};
};
}

View file

@ -1,24 +0,0 @@
{
writeTextFile,
name,
pyenv,
...
}: let
interpreter = pyenv.interpreter; # TODO ensure ipykernel package installed somehow...
in
writeTextFile {
name = "${name}-ipykernel";
destination = "/kernels/${name}/kernel.json";
text = builtins.toJSON {
display_name = name;
argv = [
"${interpreter}"
"-m"
"ipykernel_launcher"
"-f"
"{connection_file}"
];
language = "python";
metadata = {debugger = true;};
};
}

View file

@ -1,25 +0,0 @@
{
mkShellNoCC,
python3,
kernels ? [],
extraPackages ? (ps: []),
}:
mkShellNoCC {
nativeBuildInputs = [
(python3.withPackages (ps:
with ps;
[
jupyterlab
jupyterlab-git
nbdime
nbconvert
python-lsp-server
(ps.callPackage ./catppuccin_jupyterlab {})
]
++ (extraPackages ps)))
];
shellHook = with builtins; let
kernelString = foldl' (x: y: ":" + (toString y) + x) "" kernels;
pathString = substring 1 (stringLength kernelString) kernelString;
in "export JUPYTER_PATH=${pathString}";
}

24
lib/ipykernel.nix Normal file
View file

@ -0,0 +1,24 @@
{pkgs, ...}: (
{
name,
pyenv,
}: let
interpreter = pyenv.interpreter; # TODO ensure ipykernel package installed somehow...
in
pkgs.writeTextFile {
name = "${name}-ipykernel";
destination = "/kernels/${name}/kernel.json";
text = builtins.toJSON {
display_name = name;
argv = [
"${interpreter}"
"-m"
"ipykernel_launcher"
"-f"
"{connection_file}"
];
language = "python";
metadata = {debugger = true;};
};
}
)

5
lib/shellhook.nix Normal file
View file

@ -0,0 +1,5 @@
kernels:
with builtins; let
kernelString = foldl' (x: y: ":" + (toString y) + x) "" kernels;
pathString = substring 1 (stringLength kernelString) kernelString;
in "export JUPYTER_PATH=${pathString}"

16
shell.nix Normal file
View file

@ -0,0 +1,16 @@
{pkgs ? import <nixpkgs> {}, ...}:
with pkgs;
mkShellNoCC {
nativeBuildInputs = [
(python3.withPackages (ps:
with ps; [
jupyterlab
jupyterlab-git
nbdime
nbconvert
python-lsp-server
(ps.callPackage ./catppuccin_jupyterlab {})
]))
];
shellHook = import ./shellhook.nix {};
}