From ac36f0adf229706b56d9d8d7259e6be8d7ed8b55 Mon Sep 17 00:00:00 2001 From: Adrian Gunnar Lauterer Date: Wed, 24 Sep 2025 11:56:39 +0200 Subject: [PATCH] jupyter qbit --- machines/galadriel/configuration.nix | 1 + services/jupyterhub.nix | 99 ++++++++++++++ services/qbittorrent-old.nix | 139 ++++++++++++++++++++ services/rss.nix | 2 +- services/torrent.nix | 188 +++++++++++---------------- 5 files changed, 315 insertions(+), 114 deletions(-) create mode 100644 services/jupyterhub.nix create mode 100644 services/qbittorrent-old.nix diff --git a/machines/galadriel/configuration.nix b/machines/galadriel/configuration.nix index ebc67b6..aa2cfa7 100644 --- a/machines/galadriel/configuration.nix +++ b/machines/galadriel/configuration.nix @@ -21,6 +21,7 @@ #../../services/smb.nix #../../services/wordpress.nix # lets not ../../services/torrent.nix + ../../services/jupyterhub.nix #../../services/ozai.nix #../../services/stableDiffusion.nix ../../services/rss.nix diff --git a/services/jupyterhub.nix b/services/jupyterhub.nix new file mode 100644 index 0000000..d9ec287 --- /dev/null +++ b/services/jupyterhub.nix @@ -0,0 +1,99 @@ +{ config, pkgs, lib, ... }: +let + myPython = pkgs.python3; + + myJupyterHubEnv = myPython.withPackages (ps: with ps; [ + jupyterhub + jupyterhub-systemdspawner + ipython + jupyterlab + notebook + ipykernel + numpy + scipy + pandas + matplotlib + seaborn + scikit-learn + ]); + + myJupyterLabEnv = myPython.withPackages (ps: with ps; [ + jupyterhub + jupyterlab + ipykernel + numpy + scipy + pandas + matplotlib + seaborn + scikit-learn + ]); + +in +{ + environment.systemPackages = with pkgs; [ + python3Packages.numpy + python3Packages.scipy + python3Packages.pandas + python3Packages.matplotlib + python3Packages.seaborn + python3Packages.scikit-learn + ]; + + users.users.tdt4117 = { + isNormalUser = true; + home = "/home/tdt4117"; + description = "Alice Foobar"; + extraGroups = [ ]; + # openssh.authorizedKeys.keys = [ "ssh-dss AAAAB3Nza... " ]; + }; + + services.jupyterhub = { + jupyterhubEnv = myJupyterHubEnv; + jupyterlabEnv = myJupyterLabEnv; + enable = true; + port = 8770; + host = "0.0.0.0"; + extraConfig = '' + c.Authenticator.allow_all = True + c.ConfigurableHTTPProxy.api_url = 'http://0.0.0.0:8770' + c.JupyterHub.bind_url = 'http://0.0.0.0:8771' + ''; + + kernels = { + python3 = let + env = (pkgs.python3.withPackages (pythonPackages: with pythonPackages; [ + ipykernel + pandas + scikit-learn + seaborn + pandas + huggingface-hub + datasets + matplotlib + tqdm + numpy + scipy + + ])); + 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"; + }; + }; + + + + + }; + +} diff --git a/services/qbittorrent-old.nix b/services/qbittorrent-old.nix new file mode 100644 index 0000000..3f89662 --- /dev/null +++ b/services/qbittorrent-old.nix @@ -0,0 +1,139 @@ +{ config, lib, pkgs, ... }: +let + port = 8090; + torrentPort = 44183; + savePath = "/Main/Data/media/Downloads/"; + path = "/var/lib/qbittorrent"; + + + configurationFile = '' + [Application] + FileLogger\Age=1 + FileLogger\AgeType=1 + FileLogger\Backup=true + FileLogger\DeleteOld=true + FileLogger\Enabled=true + FileLogger\MaxSizeBytes=66560 + FileLogger\Path=/Main/Data/media/.qbittorrent/logs + MemoryWorkingSetLimit=8192 + + [BitTorrent] + Session\AddExtensionToIncompleteFiles=true + Session\AlternativeGlobalDLSpeedLimit=1000 + Session\AlternativeGlobalUPSpeedLimit=1000 + Session\AnonymousModeEnabled=false + Session\BTProtocol=Both + Session\BandwidthSchedulerEnabled=false + Session\DefaultSavePath=/Main/Data/media/Downloads + Session\Encryption=1 + Session\ExcludedFileNames= + Session\FinishedTorrentExportDirectory=/Main/Data/media/Downloads/torrents-complete + Session\GlobalDLSpeedLimit=0 + Session\GlobalMaxRatio=1.5 + Session\GlobalUPSpeedLimit=0 + Session\I2P\Enabled=true + Session\IgnoreLimitsOnLAN=true + Session\IncludeOverheadInLimits=true + Session\Interface=tun0 + Session\InterfaceAddress=${config.sops.placeholder."qbittorrent/interfaceAddress"} + Session\InterfaceName=tun0 + Session\LSDEnabled=true + Session\MaxActiveCheckingTorrents=15 + Session\MaxRatioAction=1 + Session\Port=44183 + Session\Preallocation=true + Session\QueueingSystemEnabled=false + Session\SubcategoriesEnabled=true + Session\Tags=movie, anime + Session\TempPath=/Main/Data/media/Downloads/temp + Session\TempPathEnabled=true + Session\TorrentContentLayout=Subfolder + Session\TorrentExportDirectory=/Main/Data/media/Downloads/torrents + Session\UseAlternativeGlobalSpeedLimit=false + + [Core] + AutoDeleteAddedTorrentFile=Never + + [LegalNotice] + Accepted=true + + [Meta] + MigrationVersion=6 + + [Network] + PortForwardingEnabled=true + + [Preferences] + General\Locale=en + MailNotification\req_auth=true + Scheduler\days=Weekday + Scheduler\end_time=@Variant(\0\0\0\xf\x5%q\xa0) + WebUI\AuthSubnetWhitelist=192.168.1.0/24, 100.0.0.0/8 + WebUI\AuthSubnetWhitelistEnabled=true + WebUI\Port=${toString port} + WebUI\UseUPnP=false + + [RSS] + AutoDownloader\DownloadRepacks=true + AutoDownloader\EnableProcessing=true + AutoDownloader\SmartEpisodeFilter=s(\\d+)e(\\d+), (\\d+)x(\\d+), "(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", "(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})" + Session\EnableProcessing=true + ''; + +in +{ + + imports = [ + ../profiles/sops.nix + ]; + + networking.firewall.allowedTCPPorts = [ port torrentPort]; + networking.firewall.allowedUDPPorts = [ port torrentPort]; + + sops.secrets."qbittorrent/interfaceAddress" = { + restartUnits = [ "qbittorrent-nox.service" ]; + owner = "qbittorrent"; + mode = "0755"; + }; + + sops.templates."qbittorrent/configuration" = { + content = configurationFile; + #path = "${path}/.config/qBittorrent/qBittorrent.conf"; #did not seem to work + owner = "qbittorrent"; + mode = "0755"; + }; + + users.users.qbittorrent = { + isNormalUser = true; #make this a normal user to be able to make files + home = path; + group = "media"; + + }; + users.groups.qbittorrent = {}; + + systemd.services."qbittorrent-nox" = { + after = [ "network.target" ]; + wants = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + serviceConfig = { + ExecStartPre = "${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/mkdir -p ${path} && ${pkgs.coreutils}/bin/chmod -R 755 ${path} && ${pkgs.coreutils}/bin/cp ${config.sops.templates."qbittorrent/configuration".path} ${path}/.config/qBittorrent/qBittorrent.conf'"; + ExecStart = "${pkgs.unstable.qbittorrent-nox}/bin/qbittorrent-nox"; + User = "qbittorrent"; + Group = "media"; + Restart = "on-failure"; + + ProtectKernelModules = true; + NoNewPrivileges = true; + }; + }; + services.nginx.virtualHosts."qbittorrent.${config.networking.hostName}.${config.networking.domain}" = { + forceSSL = true; + #useACMEHost = config.networking.domain; #not sure if this will work, unless + locations."/" = { + proxyWebsockets = true; + proxyPass = "http://localhost:${port}"; + }; + basicAuthFile = config.sops.secrets."nginx/defaultpass".path; + }; +} diff --git a/services/rss.nix b/services/rss.nix index bb33a95..3ba1871 100644 --- a/services/rss.nix +++ b/services/rss.nix @@ -18,7 +18,7 @@ services.miniflux.enable = true; - services.miniflux.config.LISTEN_ADDR = "0.0.0.0:8081"; + services.miniflux.config.LISTEN_ADDR = "0.0.0.0:8089"; services.miniflux.adminCredentialsFile = config.sops.secrets."miniflux/adminCredentialsFile".path; } diff --git a/services/torrent.nix b/services/torrent.nix index 3f89662..3ab6e9c 100644 --- a/services/torrent.nix +++ b/services/torrent.nix @@ -1,85 +1,6 @@ { config, lib, pkgs, ... }: let - port = 8090; - torrentPort = 44183; - savePath = "/Main/Data/media/Downloads/"; - path = "/var/lib/qbittorrent"; - - - configurationFile = '' - [Application] - FileLogger\Age=1 - FileLogger\AgeType=1 - FileLogger\Backup=true - FileLogger\DeleteOld=true - FileLogger\Enabled=true - FileLogger\MaxSizeBytes=66560 - FileLogger\Path=/Main/Data/media/.qbittorrent/logs - MemoryWorkingSetLimit=8192 - - [BitTorrent] - Session\AddExtensionToIncompleteFiles=true - Session\AlternativeGlobalDLSpeedLimit=1000 - Session\AlternativeGlobalUPSpeedLimit=1000 - Session\AnonymousModeEnabled=false - Session\BTProtocol=Both - Session\BandwidthSchedulerEnabled=false - Session\DefaultSavePath=/Main/Data/media/Downloads - Session\Encryption=1 - Session\ExcludedFileNames= - Session\FinishedTorrentExportDirectory=/Main/Data/media/Downloads/torrents-complete - Session\GlobalDLSpeedLimit=0 - Session\GlobalMaxRatio=1.5 - Session\GlobalUPSpeedLimit=0 - Session\I2P\Enabled=true - Session\IgnoreLimitsOnLAN=true - Session\IncludeOverheadInLimits=true - Session\Interface=tun0 - Session\InterfaceAddress=${config.sops.placeholder."qbittorrent/interfaceAddress"} - Session\InterfaceName=tun0 - Session\LSDEnabled=true - Session\MaxActiveCheckingTorrents=15 - Session\MaxRatioAction=1 - Session\Port=44183 - Session\Preallocation=true - Session\QueueingSystemEnabled=false - Session\SubcategoriesEnabled=true - Session\Tags=movie, anime - Session\TempPath=/Main/Data/media/Downloads/temp - Session\TempPathEnabled=true - Session\TorrentContentLayout=Subfolder - Session\TorrentExportDirectory=/Main/Data/media/Downloads/torrents - Session\UseAlternativeGlobalSpeedLimit=false - - [Core] - AutoDeleteAddedTorrentFile=Never - - [LegalNotice] - Accepted=true - - [Meta] - MigrationVersion=6 - - [Network] - PortForwardingEnabled=true - - [Preferences] - General\Locale=en - MailNotification\req_auth=true - Scheduler\days=Weekday - Scheduler\end_time=@Variant(\0\0\0\xf\x5%q\xa0) - WebUI\AuthSubnetWhitelist=192.168.1.0/24, 100.0.0.0/8 - WebUI\AuthSubnetWhitelistEnabled=true - WebUI\Port=${toString port} - WebUI\UseUPnP=false - - [RSS] - AutoDownloader\DownloadRepacks=true - AutoDownloader\EnableProcessing=true - AutoDownloader\SmartEpisodeFilter=s(\\d+)e(\\d+), (\\d+)x(\\d+), "(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})", "(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})" - Session\EnableProcessing=true - ''; - + interfaceaddress = builtins.readFile config.sops.secrets."qbittorrent/interfaceAddress".path; in { @@ -87,8 +8,6 @@ in ../profiles/sops.nix ]; - networking.firewall.allowedTCPPorts = [ port torrentPort]; - networking.firewall.allowedUDPPorts = [ port torrentPort]; sops.secrets."qbittorrent/interfaceAddress" = { restartUnits = [ "qbittorrent-nox.service" ]; @@ -96,44 +15,87 @@ in mode = "0755"; }; - sops.templates."qbittorrent/configuration" = { - content = configurationFile; - #path = "${path}/.config/qBittorrent/qBittorrent.conf"; #did not seem to work - owner = "qbittorrent"; - mode = "0755"; - }; - users.users.qbittorrent = { - isNormalUser = true; #make this a normal user to be able to make files - home = path; - group = "media"; + group = lib.mkForce "media"; }; users.groups.qbittorrent = {}; - systemd.services."qbittorrent-nox" = { - after = [ "network.target" ]; - wants = [ "network.target" ]; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - ExecStartPre = "${pkgs.bash}/bin/bash -c '${pkgs.coreutils}/bin/mkdir -p ${path} && ${pkgs.coreutils}/bin/chmod -R 755 ${path} && ${pkgs.coreutils}/bin/cp ${config.sops.templates."qbittorrent/configuration".path} ${path}/.config/qBittorrent/qBittorrent.conf'"; - ExecStart = "${pkgs.unstable.qbittorrent-nox}/bin/qbittorrent-nox"; - User = "qbittorrent"; - Group = "media"; - Restart = "on-failure"; - ProtectKernelModules = true; - NoNewPrivileges = true; - }; - }; - services.nginx.virtualHosts."qbittorrent.${config.networking.hostName}.${config.networking.domain}" = { - forceSSL = true; - #useACMEHost = config.networking.domain; #not sure if this will work, unless - locations."/" = { - proxyWebsockets = true; - proxyPass = "http://localhost:${port}"; + services.qbittorrent = { + enable = true; + extraArgs = [ + "--confirm-legal-notice" + ]; + + webuiPort = 8090; + torrentingPort = 44183; + + serverConfig = { + LegalNotice.Accepted = true; + Meta.MigrationVersion=6; + Network.PortForwardingEnabled=true; + + Preferences = { + WebUI = { + AuthSubnetWhitelist="192.168.1.0/24, 100.0.0.0/8"; + AuthSubnetWhitelistEnabled=true; + UseUPnP=false; + + }; + BitTorrent = { + Session = { + AddExtensionToIncompleteFiles=true; + AlternativeGlobalDLSpeedLimit=1000; + AlternativeGlobalUPSpeedLimit=1000; + AnonymousModeEnabled=false; + BTProtocol="Both"; + BandwidthSchedulerEnabled=false; + DefaultSavePath="/Main/Data/media/Downloads"; + Encryption=1; + FinishedTorrentExportDirectory="/Main/Data/media/Downloads/torrents-complete"; + GlobalDLSpeedLimit=0; + GlobalMaxRatio=1.5; + GlobalUPSpeedLimit=0; + I2P.Enabled=true; + IgnoreLimitsOnLAN=true; + IncludeOverheadInLimits=true; + Interface="tun0"; + #InterfaceAddress="${config.sops.placeholder."qbittorrent/interfaceAddress"}"; + InterfaceAddress="${interfaceaddress}"; + InterfaceName="tun0"; + LSDEnabled="true"; + MaxActiveCheckingTorrents=15; + MaxRatioAction=1; + Port=44183; + Preallocation=true; + QueueingSystemEnabled=false; + SubcategoriesEnabled=true; + Tags="movie, anime"; + TempPath="/Main/Data/media/Downloads/temp"; + TempPathEnabled=true; + TorrentContentLayout="Subfolder"; + TorrentExportDirectory="/Main/Data/media/Downloads/torrents"; + UseAlternativeGlobalSpeedLimit=false; + }; }; - basicAuthFile = config.sops.secrets."nginx/defaultpass".path; + + RSS = { + AutoDownloader = { + DownloadRepacks=true; + EnableProcessing=true; + SmartEpisodeFilter="s(\\d+)e(\\d+), (\\d+)x(\\d+), \"(\\d{4}[.\\-]\\d{1,2}[.\\-]\\d{1,2})\", \"(\\d{1,2}[.\\-]\\d{1,2}[.\\-]\\d{4})\""; + }; + Session.EnableProcessing=true; + }; + General.Locale = "en"; + }; + + }; + + }; + + }