aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--custom.nix16
-rw-r--r--module/tasker.nix19
-rw-r--r--tasks/default.nix25
3 files changed, 59 insertions, 1 deletions
diff --git a/custom.nix b/custom.nix
index e489fea..272fc6a 100644
--- a/custom.nix
+++ b/custom.nix
@@ -21,7 +21,7 @@ in {
default = "~/";
};
type = mkOption {
- type = types.enum [ "launcher" "terminal" "local-shell" "local-editor" "environment" "python-console" ];
+ type = types.enum [ "launcher" "terminal" "local-shell" "local-editor" "environment" "python-console" "jupyter-lab" ];
default = "launcher";
};
command = mkOption {
@@ -34,9 +34,23 @@ in {
});
};
+ notebooks = mkOption {
+ type = types.attrsOf (types.submodule {
+ options = {
+ description = mkOption {
+ type = types.uniq types.string;
+ };
+ environment = mkOption {
+ type = types.package;
+ };
+ };
+ });
+ };
+
pkgs = mkOption {
type = types.attrs;
};
+
nixpkgs-unstable = mkOption {
type = types.attrs;
};
diff --git a/module/tasker.nix b/module/tasker.nix
index 032027b..0987544 100644
--- a/module/tasker.nix
+++ b/module/tasker.nix
@@ -11,6 +11,23 @@ let
#!/bin/sh
exec ${pkgs.kitty}/bin/kitty -d ${dir} ${cmd}
'';
+ launchJupyterInDirectory = dir: env: ''
+ #!/usr/bin/env nix-shell
+ #!nix-shell ${builtins.unsafeDiscardStringContext env.drvPath} -i fish
+
+ for port in (seq 9000 9100)
+ if not ss --listening --oneline --tcp --no-header | awk '{ split($4, port, ":"); print port[2]+0 }' | grep -q $port
+ set free_port $port
+ break
+ end
+ end
+
+ set token (head /dev/urandom | tr -dc A-Za-z0-9 | head -c 40)
+ jupyter lab --no-browser --port=$free_port --NotebookApp.token=$token &
+ sleep 2
+ ${pkgs.chromium}/bin/chromium --app="http://localhost:$free_port/?token=$token"
+ kill (jobs -lp)
+ '';
taskivations = pkgs.lib.mapAttrsToList (name: conf: let
command = pkgs.writeTextFile {
@@ -31,6 +48,8 @@ let
python-console = launchCommandInDirectory "~/" ''
nix-shell ${builtins.unsafeDiscardStringContext conf.environment.drvPath} --command jupyter-qtconsole
'';
+
+ jupyter-lab = launchJupyterInDirectory conf.directory conf.environment;
};
};
diff --git a/tasks/default.nix b/tasks/default.nix
index 3521443..1ccda33 100644
--- a/tasks/default.nix
+++ b/tasks/default.nix
@@ -27,6 +27,15 @@ let
'';
};
+ jupyter = import (builtins.fetchGit {
+ url = https://github.com/tweag/jupyterWith;
+ rev = "";
+ }) {};
+
+ mkJupyterEnv = kernel: (jupyter.jupyterlabWith {
+ kernels = [ kernel ];
+ }).env;
+
in {
custom.tasks = {
bsc_edit = {
@@ -101,5 +110,21 @@ in {
sympy.init_session()
'';
};
+
+ pymath_jupyter = {
+ description = "Python @ Jupyter Lab";
+ directory = "~/";
+ type = "jupyter-lab";
+ environment = mkJupyterEnv (
+ jupyter.kernels.iPythonWith {
+ name = "python";
+ packages = p: with p; [
+ numpy
+ sympy
+ matplotlib
+ ];
+ }
+ );
+ };
};
}