Restructure to be more modular and more useable
This commit is contained in:
parent
eb2e035ba9
commit
71a134f1cd
25
default.nix
Normal file
25
default.nix
Normal 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;
|
||||||
|
}
|
10
flake.nix
10
flake.nix
|
@ -15,12 +15,14 @@
|
||||||
system = "x86_64-linux";
|
system = "x86_64-linux";
|
||||||
pkgs = import nixpkgs {inherit system;};
|
pkgs = import nixpkgs {inherit system;};
|
||||||
in {
|
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;};
|
poetry2nix = poetry2nix.lib.mkPoetry2Nix {inherit pkgs;};
|
||||||
catppuccin_jupyterlab = import ./catppuccin_jupyterlab/default.nix;
|
catppuccin_jupyterlab = import ./catppuccin_jupyterlab/default.nix;
|
||||||
mkIpythonKernel = attrs: (pkgs.callPackage ./ipykernel.nix attrs);
|
default = pkgs.callPackage ./default.nix {inherit mkShellHook;};
|
||||||
mkJupyterShell = attrs: (pkgs.callPackage ./jupyter.nix attrs);
|
|
||||||
default = self.packages.${system}.mkJupyterShell;
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
@ -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;};
|
|
||||||
};
|
|
||||||
}
|
|
25
jupyter.nix
25
jupyter.nix
|
@ -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
24
lib/ipykernel.nix
Normal 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
5
lib/shellhook.nix
Normal 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
16
shell.nix
Normal 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 {};
|
||||||
|
}
|
Loading…
Reference in a new issue