aboutsummaryrefslogtreecommitdiff
path: root/module
diff options
context:
space:
mode:
authorAdrian Kummerlaender2020-01-17 15:36:29 +0100
committerAdrian Kummerlaender2020-01-17 15:36:29 +0100
commit40804b0af1814c8d5ea1875283464673b7d3a28c (patch)
tree9eaeb25faa2bcbdb4fd739bade0582738c710f96 /module
parent9e4f0d3a0d6cae734436c140f0c584557b813c2c (diff)
downloadnixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar.gz
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar.bz2
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar.lz
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar.xz
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.tar.zst
nixos_home-40804b0af1814c8d5ea1875283464673b7d3a28c.zip
Implement Jupyter Lab type in Tasker module
Allows for convenient creation of shortcuts to Jupyter Lab sessions. As a bonus they are wrapped in Chromium App View instances and automatically terminated when required.
Diffstat (limited to 'module')
-rw-r--r--module/tasker.nix19
1 files changed, 19 insertions, 0 deletions
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;
};
};