From cab07f3d140edc755a8fb5a0fb572ff3496420e4 Mon Sep 17 00:00:00 2001 From: Antoine Viallon Date: Tue, 22 Feb 2022 23:04:10 +0100 Subject: [PATCH] [Services] Added modular service configuration + opt-in jupyterhub server --- services.nix | 12 ++++++++++ services/default.nix | 6 +++++ services/jupyterhub.nix | 52 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+) create mode 100644 services/default.nix create mode 100644 services/jupyterhub.nix diff --git a/services.nix b/services.nix index ad4f210..b580a4a 100644 --- a/services.nix +++ b/services.nix @@ -22,6 +22,11 @@ let settings) ); in { + + imports = [ + ./services + ]; + options.aviallon.services = { enable = mkOption { default = true; @@ -119,5 +124,12 @@ in { services.avahi.nssmdns = true; # .lan/.local resolution services.avahi.publish.enable = true; services.avahi.publish.hinfo = true; # Whether to register a mDNS HINFO record which contains information about the local operating system and CPU. + + + services.nginx = { + recommendedProxySettings = true; + recommendedGzipSettings = true; + recommendedOptimisation = true; + }; }; } diff --git a/services/default.nix b/services/default.nix new file mode 100644 index 0000000..d8d12cd --- /dev/null +++ b/services/default.nix @@ -0,0 +1,6 @@ +{ config, pkgs, ...}: +{ + imports = [ + ./jupyterhub.nix + ]; +} diff --git a/services/jupyterhub.nix b/services/jupyterhub.nix new file mode 100644 index 0000000..a259c09 --- /dev/null +++ b/services/jupyterhub.nix @@ -0,0 +1,52 @@ +{config, pkgs, lib, ...}: +with lib; +let + cfg = config.aviallon.services.jupyterhub; +in +{ + options.aviallon.services.jupyterhub = { + enable = mkEnableOption "Jupyterhub server with Python 3 kernel"; + }; + + config = mkIf cfg.enable { + services.jupyterhub = { + enable = true; + kernels.python3 = let + env = (pkgs.python3.withPackages (pythonPackages: with pythonPackages; [ + ipykernel + pandas + scikit-learn + pyspark + matplotlib + numpy + pip + ])); + in { + displayName = "Python 3 for machine learning"; + argv = [ + "${env.interpreter}" + "-m" + "ipykernel_launcher" + "-f" + "{connection_file}" + ]; + language = "python"; + logo32 = "${env}/${env.sitePackages}/ipykernel/resources/logo-32x32.png"; + logo64 = "${env}/${env.sitePackages}/ipykernel/resources/logo-64x64.png"; + }; + }; + + services.nginx = { + enable = true; + }; + services.nginx.virtualHosts = { + "jupyterhub.localhost" = { + listen = [ { addr = "0.0.0.0"; port = 80; } ]; + locations."/" = { + proxyPass = "http://localhost:${toString config.services.jupyterhub.port}"; + proxyWebsockets = true; + }; + }; + }; + }; +}