From fe369100930756d49b56bd00a658d2e02d9d5b42 Mon Sep 17 00:00:00 2001 From: Ingolf Wagner Date: Fri, 11 Sep 2020 22:25:27 +0200 Subject: [PATCH] jupyter setup --- configs/workhorse/configuration.nix | 3 ++ configs/workhorse/jupyter.nix | 69 +++++++++++++++++++++++++++++ configs/workhorse/metabase.nix | 24 ++++++++++ configs/workhorse/mysql.nix | 12 +++++ 4 files changed, 108 insertions(+) create mode 100644 configs/workhorse/jupyter.nix create mode 100644 configs/workhorse/metabase.nix create mode 100644 configs/workhorse/mysql.nix diff --git a/configs/workhorse/configuration.nix b/configs/workhorse/configuration.nix index 4621cc5..00ec07c 100644 --- a/configs/workhorse/configuration.nix +++ b/configs/workhorse/configuration.nix @@ -25,6 +25,9 @@ ./nextcloud.nix ./mattermost.nix ./borg.nix + ./metabase.nix + ./jupyter.nix + ./mysql.nix ]; # todo: add this to each file instead summing that here diff --git a/configs/workhorse/jupyter.nix b/configs/workhorse/jupyter.nix new file mode 100644 index 0000000..f0199d3 --- /dev/null +++ b/configs/workhorse/jupyter.nix @@ -0,0 +1,69 @@ +{ pkgs, lib, config, ... }: { + + services.jupyter = { + enable = true; + ip = "0.0.0.0"; + #In [1]: from notebook.auth import passwd + #In [2]: passwd('test') + #Out[2]: 'sha1:1b961dc713fb:88483270a63e57d18d43cf337e629539de1436ba' + #NOTE: you need to keep the single quote inside nix string. + password = "'sha1:1b961dc713fb:88483270a63e57d18d43cf337e629539de1436ba'"; + kernels = { + python3 = let + env = (pkgs.python3.withPackages (pythonPackages: + with pythonPackages; [ + ipykernel + pandas + + # database stuff + mysqlclient + databases + asyncpg + psycopg2 + aiomysql + pymysql + aiosqlite + #aiopg + sqlalchemy + + # pdf export + nbconvert + ])); + in { + displayName = "Python 3"; + argv = [ + "${env.interpreter}" + "-m" + "ipykernel_launcher" + "-f" + "{connection_file}" + ]; + language = "python"; + }; + }; + }; + + # to generate pdfs and such + environment.systemPackages = [ pkgs.pandoc ]; + + backup.dirs = [ "/var/lib/jupyter" ]; + backup.exclude = + [ "/var/lib/jupyter/.local" "/var/lib/jupyter/.ipynb_checkpoints" ]; + + services.nginx = { + enable = true; + statusPage = true; + virtualHosts = { + "python.${config.networking.hostName}.private" = { + serverAliases = [ "jupyter.${config.networking.hostName}.private" ]; + locations."/" = { + proxyWebsockets = true; + proxyPass = "http://${config.networking.hostName}.private:${ + toString config.services.jupyter.port + }"; + }; + }; + }; + }; + +} diff --git a/configs/workhorse/metabase.nix b/configs/workhorse/metabase.nix new file mode 100644 index 0000000..069767c --- /dev/null +++ b/configs/workhorse/metabase.nix @@ -0,0 +1,24 @@ +{ pkgs, lib, config, ... }: { + + services.metabase = { + listen.port = 3040; + enable = true; + }; + + backup.dirs = [ "/var/lib/metabase" ]; + + services.nginx = { + enable = true; + statusPage = true; + virtualHosts = { + "metabase.${config.networking.hostName}.private" = { + locations."/" = { + proxyPass = "http://${config.networking.hostName}.private:${ + toString config.services.metabase.listen.port + }"; + }; + }; + }; + }; + +} diff --git a/configs/workhorse/mysql.nix b/configs/workhorse/mysql.nix new file mode 100644 index 0000000..ba72412 --- /dev/null +++ b/configs/workhorse/mysql.nix @@ -0,0 +1,12 @@ +{ pkgs, lib, ... }: { + + services.mysql = { + enable = true; + package = pkgs.mysql; + initialScript = pkgs.writeText "initScript" '' + CREATE USER 'admin'@'%' IDENTIFIED BY 'admin'; + GRANT ALL PRIVILEGES ON * . * TO 'admin'@'%'; + ''; + }; + +}