From 517ac86a3c0918ab07a09392a72a2d5a69509dd0 Mon Sep 17 00:00:00 2001 From: Ember 'n0emis' Keske Date: Tue, 12 Jul 2022 11:04:14 +0200 Subject: [PATCH] package nerd --- hosts/nerd/configuration.nix | 7 +- hosts/nerd/nerd.nix | 86 +++++++++++++++++++ packages/python/default.nix | 4 + .../default.nix | 23 +++++ packages/python/django-bootstrap5/default.nix | 28 ++++++ .../python/django-verify-email/default.nix | 21 +++++ packages/python/nerd/default.nix | 50 +++++++++++ 7 files changed, 215 insertions(+), 4 deletions(-) create mode 100644 hosts/nerd/nerd.nix create mode 100644 packages/python/django-admin-autocomplete-filter/default.nix create mode 100644 packages/python/django-bootstrap5/default.nix create mode 100644 packages/python/django-verify-email/default.nix create mode 100644 packages/python/nerd/default.nix diff --git a/hosts/nerd/configuration.nix b/hosts/nerd/configuration.nix index 8206ad9..6c0a5da 100644 --- a/hosts/nerd/configuration.nix +++ b/hosts/nerd/configuration.nix @@ -4,6 +4,7 @@ imports = [ # Include the results of the hardware scan. ./hardware-configuration.nix + ./nerd.nix ]; # Use the systemd-boot EFI boot loader. @@ -18,13 +19,11 @@ matchConfig = { Name = "ens18"; }; - address = [ "10.42.10.24/24" "fd00:10:42:10::240/64" "2a01:4f8:1c0c:8221::240/64" ]; - gateway = [ "10.42.10.1" "2a01:4f8:1c0c:8221::1" ]; + address = [ "10.42.10.24/24" "fd00:10:42:10::24/64" "2a01:4f8:1c0c:8221::24/64" ]; + gateway = [ "10.42.10.1" ]; }; }; - environment.systemPackages = with pkgs; [ colmena ]; - # This value determines the NixOS release from which the default # settings for stateful data, like file locations and database versions # on your system were taken. It‘s perfectly fine and recommended to leave diff --git a/hosts/nerd/nerd.nix b/hosts/nerd/nerd.nix new file mode 100644 index 0000000..0a9b24c --- /dev/null +++ b/hosts/nerd/nerd.nix @@ -0,0 +1,86 @@ +{ config, pkgs, lib, ... }: + +{ + systemd.services.nerd = { + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + + environment = { + NERD_CONFIG_FILE = pkgs.writeText "nerd.cfg" '' + [django] + secret = TODO + allowed_hosts = nerd.bula22.de + debug = False + language_code = de-de + time_zone = Europe/Berlin + csrf_trusted_origins = https://nerd.bula22.de + + [database] + engine = postgresql_psycopg2 + name = nerd + user = + password = + host = /run/postgresql + port = + + [email] + backend = smtp.EmailBackend + host = mail.n0emis.eu + port = 465 + user = no-reply@n0emis.eu + password = TODO + ssl = True + tls = False + from = noreply@n0emis.eu + ''; + PYTHONPATH = "${pkgs.python3.pkgs.nerd.pythonPath}:${pkgs.python3.pkgs.nerd}/${pkgs.python3.sitePackages}:${pkgs.python3Packages.psycopg2}/${pkgs.python3.sitePackages}"; + }; + + serviceConfig = { + User = "nerd"; + Group = "nerd"; + ExecStartPre = "${pkgs.python3.pkgs.nerd}/bin/nerd migrate"; + ExecStart = '' + ${pkgs.python3Packages.gunicorn}/bin/gunicorn \ + --bind 0.0.0.0:10510 \ + --access-logfile - \ + nerd.wsgi + ''; + }; + }; + + services.postgresql = { + enable = true; + ensureDatabases = [ "nerd" ]; + ensureUsers = [ + { + name = "nerd"; + ensurePermissions = { + "DATABASE nerd" = "ALL PRIVILEGES"; + }; + } + ]; + }; + + users.users.nerd = { + isSystemUser = true; + group = "nerd"; + }; + users.groups.nerd = {}; + + networking.firewall.allowedTCPPorts = [ 80 443 ]; + + services.caddy = { + enable = true; + virtualHosts."nerd.bula22.de" = { + extraConfig = '' + route { + file_server /static/* + reverse_proxy * http://127.0.0.1:10510 + } + + root * ${pkgs.python3.pkgs.nerd}/var/lib/nerd/ + ''; + }; + }; +} diff --git a/packages/python/default.nix b/packages/python/default.nix index d97ab40..5212e91 100644 --- a/packages/python/default.nix +++ b/packages/python/default.nix @@ -4,4 +4,8 @@ self: super: { ywsd = self.callPackage ./ywsd { }; mitel-ommclient2 = self.callPackage ./mitel-ommclient2 { }; fieldpoc = self.callPackage ./fieldpoc { }; + django-admin-autocomplete-filter = self.callPackage ./django-admin-autocomplete-filter { }; + django-bootstrap5 = self.callPackage ./django-bootstrap5 { }; + django-verify-email = self.callPackage ./django-verify-email { }; + nerd = self.callPackage ./nerd { }; } diff --git a/packages/python/django-admin-autocomplete-filter/default.nix b/packages/python/django-admin-autocomplete-filter/default.nix new file mode 100644 index 0000000..13267c9 --- /dev/null +++ b/packages/python/django-admin-autocomplete-filter/default.nix @@ -0,0 +1,23 @@ +{ lib +, buildPythonPackage +, fetchPypi +, django +}: + +buildPythonPackage rec { + pname = "django-admin-autocomplete-filter"; + version = "0.7.1"; + + src = fetchPypi { + inherit pname version; + sha256 = "5a8c9a7016e03104627b80b40811dcc567f26759971e4407f933951546367ba0"; + }; + + buildInputs = [ + django + ]; + + pythonImportsCheck = [ "admin_auto_filters" ]; + + doCheck = false; +} diff --git a/packages/python/django-bootstrap5/default.nix b/packages/python/django-bootstrap5/default.nix new file mode 100644 index 0000000..a66e83e --- /dev/null +++ b/packages/python/django-bootstrap5/default.nix @@ -0,0 +1,28 @@ +{ lib +, buildPythonPackage +, fetchPypi +, django +, beautifulsoup4 +}: + +buildPythonPackage rec { + pname = "django-bootstrap5"; + version = "21.3"; + + src = fetchPypi { + inherit pname version; + sha256 = "35086341881780a44b2e27255894f6029fc5ef75e5a0ec8ebd82f47a5184fa73"; + }; + + buildInputs = [ + django + ]; + + propagatedBuildInputs = [ + beautifulsoup4 + ]; + + pythonImportsCheck = [ "django_bootstrap5" ]; + + doCheck = false; +} diff --git a/packages/python/django-verify-email/default.nix b/packages/python/django-verify-email/default.nix new file mode 100644 index 0000000..3c5a83f --- /dev/null +++ b/packages/python/django-verify-email/default.nix @@ -0,0 +1,21 @@ +{ lib +, buildPythonPackage +, fetchPypi +, django +}: + +buildPythonPackage rec { + pname = "Django-Verify-Email"; + version = "1.0.9"; + + src = fetchPypi { + inherit pname version; + sha256 = "05d296a6a7ef03db07327b076093373e086d9e76e7fa9970a033e4e01168197f"; + }; + + buildInputs = [ + django + ]; + + doCheck = false; +} diff --git a/packages/python/nerd/default.nix b/packages/python/nerd/default.nix new file mode 100644 index 0000000..79b9e35 --- /dev/null +++ b/packages/python/nerd/default.nix @@ -0,0 +1,50 @@ +{ lib +, buildPythonApplication +, makePythonPath +, fetchFromGitHub +, python3 +, hatchling +, django_4 +, django-bootstrap5 +, django-admin-autocomplete-filter +, django-verify-email +}: + +buildPythonApplication rec { + pname = "nerd"; + version = "0.0.1"; + + src = fetchFromGitHub { + owner = "dect-e"; + repo = pname; + #rev = "v${version}"; + rev = "8b8becaeb9d77c3ff2c5dadb1d5be6d66b6ed5f2"; + sha256 = "sha256-R2kOECPtfTTnbqjujGR1AeNGyXNswqC7UJtQu+W4pXo="; + }; + + sourceRoot = "source/src"; + + format = "pyproject"; + + buildInputs = [ python3 hatchling ]; + propagatedBuildInputs = [ + django_4 + django-bootstrap5 + django-admin-autocomplete-filter + django-verify-email + ]; + + postInstall = '' + python ./manage.py collectstatic + + mkdir -p $out/var/lib/nerd + cp -r static $out/var/lib/nerd/ + ''; + + passthru = { + # PYTHONPATH of all dependencies used by the package + pythonPath = python3.pkgs.makePythonPath propagatedBuildInputs; + }; + + doCheck = false; +}