diff options
author | Flakebi <flakebi@t-online.de> | 2023-12-02 16:39:55 +0100 |
---|---|---|
committer | Flakebi <flakebi@t-online.de> | 2023-12-02 17:08:10 +0100 |
commit | 06feb44c1ab13a2cc42826c1d114f7c16fa00e00 (patch) | |
tree | d407bf98987715f216079a227557abd578a8d6fc /pkgs/applications/networking/powerdns-admin | |
parent | ec9f89a840e82ae930af77333ede0d3098105019 (diff) |
powerdns-admin: use patch files
Diffstat (limited to 'pkgs/applications/networking/powerdns-admin')
7 files changed, 177 insertions, 25 deletions
diff --git a/pkgs/applications/networking/powerdns-admin/0001-Fix-flask-2.3-issue.patch b/pkgs/applications/networking/powerdns-admin/0001-Fix-flask-2.3-issue.patch new file mode 100644 index 0000000000000..8645e0dbfa7da --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0001-Fix-flask-2.3-issue.patch @@ -0,0 +1,25 @@ +From 29b58e29c813d9bf0b31139a19b556614c28638e Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:26:22 +0100 +Subject: [PATCH 1/6] Fix flask 2.3 issue + +'Blueprint' object has no attribute 'before_app_first_request' +--- + powerdnsadmin/routes/index.py | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/powerdnsadmin/routes/index.py b/powerdnsadmin/routes/index.py +index d56ce61..2176bd6 100644 +--- a/powerdnsadmin/routes/index.py ++++ b/powerdnsadmin/routes/index.py +@@ -46,7 +46,6 @@ index_bp = Blueprint('index', + url_prefix='/') + + +-@index_bp.before_app_first_request + def register_modules(): + global google + global github +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/0002-Remove-cssrewrite-filter.patch b/pkgs/applications/networking/powerdns-admin/0002-Remove-cssrewrite-filter.patch new file mode 100644 index 0000000000000..9b442d5f3d7d7 --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0002-Remove-cssrewrite-filter.patch @@ -0,0 +1,34 @@ +From c60a9658fe2ca429327680fbffb86f609d98c52c Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:27:49 +0100 +Subject: [PATCH 2/6] Remove cssrewrite filter + +--- + powerdnsadmin/assets.py | 4 ++-- + 1 file changed, 2 insertions(+), 2 deletions(-) + +diff --git a/powerdnsadmin/assets.py b/powerdnsadmin/assets.py +index d46d431..3c582be 100644 +--- a/powerdnsadmin/assets.py ++++ b/powerdnsadmin/assets.py +@@ -13,7 +13,7 @@ css_login = Bundle( + 'node_modules/@fortawesome/fontawesome-free/css/all.css', + 'node_modules/icheck/skins/square/blue.css', + 'node_modules/admin-lte/dist/css/adminlte.css', +- filters=('rcssmin', 'cssrewrite'), ++ filters=('rcssmin'), + output='generated/login.css') + + js_login = Bundle( +@@ -37,7 +37,7 @@ css_main = Bundle( + 'node_modules/admin-lte/dist/css/adminlte.css', + 'custom/css/custom.css', + 'node_modules/bootstrap-datepicker/dist/css/bootstrap-datepicker.css', +- filters=('rcssmin', 'cssrewrite'), ++ filters=('rcssmin'), + output='generated/main.css') + + js_main = Bundle( +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/0003-Fix-flask-migrate-4.0-compatibility.patch b/pkgs/applications/networking/powerdns-admin/0003-Fix-flask-migrate-4.0-compatibility.patch new file mode 100644 index 0000000000000..c9956ae22f75b --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0003-Fix-flask-migrate-4.0-compatibility.patch @@ -0,0 +1,25 @@ +From 8c320a34bcca6dc2c1b423a1445235bf178b653e Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:31:02 +0100 +Subject: [PATCH 3/6] Fix flask-migrate 4.0 compatibility + +See https://github.com/PowerDNS-Admin/PowerDNS-Admin/issues/1376 +--- + migrations/env.py | 1 - + 1 file changed, 1 deletion(-) + +diff --git a/migrations/env.py b/migrations/env.py +index 4742e14..739d753 100755 +--- a/migrations/env.py ++++ b/migrations/env.py +@@ -73,7 +73,6 @@ def run_migrations_online(): + context.configure(connection=connection, + target_metadata=target_metadata, + process_revision_directives=process_revision_directives, +- render_as_batch=config.get_main_option('sqlalchemy.url').startswith('sqlite:'), + **current_app.extensions['migrate'].configure_args) + + try: +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/0004-Fix-flask-session-and-powerdns-admin-compatibility.patch b/pkgs/applications/networking/powerdns-admin/0004-Fix-flask-session-and-powerdns-admin-compatibility.patch new file mode 100644 index 0000000000000..b1aaa8c531d17 --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0004-Fix-flask-session-and-powerdns-admin-compatibility.patch @@ -0,0 +1,26 @@ +From 4b4ac26ef1cbb0b5b2354c251b216498325d0411 Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:31:50 +0100 +Subject: [PATCH 4/6] Fix flask-session and powerdns-admin compatibility + +flask-session and powerdns-admin both try to add sqlalchemy to flask. +Reuse the database for flask-session. +--- + powerdnsadmin/__init__.py | 1 + + 1 file changed, 1 insertion(+) + +diff --git a/powerdnsadmin/__init__.py b/powerdnsadmin/__init__.py +index d447a00..653af33 100755 +--- a/powerdnsadmin/__init__.py ++++ b/powerdnsadmin/__init__.py +@@ -60,6 +60,7 @@ def create_app(config=None): + if 'SESSION_TYPE' in os.environ: + app.config['SESSION_TYPE'] = os.environ.get('SESSION_TYPE') + ++ app.config['SESSION_SQLALCHEMY'] = models.base.db + sess = Session(app) + + # create sessions table if using sqlalchemy backend +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/0005-Use-app-context-to-create-routes.patch b/pkgs/applications/networking/powerdns-admin/0005-Use-app-context-to-create-routes.patch new file mode 100644 index 0000000000000..b6931c25d546c --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0005-Use-app-context-to-create-routes.patch @@ -0,0 +1,27 @@ +From 3eb1a408758b68543c73d5214b467c2905fbea2a Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:32:36 +0100 +Subject: [PATCH 5/6] Use app context to create routes + +Routes creates session database tables, so it needs a context. +--- + powerdnsadmin/__init__.py | 3 ++- + 1 file changed, 2 insertions(+), 1 deletion(-) + +diff --git a/powerdnsadmin/__init__.py b/powerdnsadmin/__init__.py +index 653af33..bc6f7df 100755 +--- a/powerdnsadmin/__init__.py ++++ b/powerdnsadmin/__init__.py +@@ -73,7 +73,8 @@ def create_app(config=None): + # Load app's components + assets.init_app(app) + models.init_app(app) +- routes.init_app(app) ++ with app.app_context(): ++ routes.init_app(app) + services.init_app(app) + + # Register filters +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/0006-Register-modules-before-starting.patch b/pkgs/applications/networking/powerdns-admin/0006-Register-modules-before-starting.patch new file mode 100644 index 0000000000000..dd552cc28403d --- /dev/null +++ b/pkgs/applications/networking/powerdns-admin/0006-Register-modules-before-starting.patch @@ -0,0 +1,27 @@ +From 86dcc9f308d2ca65704953f1ff9fe043d743e536 Mon Sep 17 00:00:00 2001 +From: Flakebi <flakebi@t-online.de> +Date: Sat, 2 Dec 2023 16:33:45 +0100 +Subject: [PATCH 6/6] Register modules before starting + +Fixes flask 2.3: 'Blueprint' object has no attribute 'before_app_first_request' +--- + run.py | 3 +++ + 1 file changed, 3 insertions(+) + +diff --git a/run.py b/run.py +index 5ffcde3..52e719d 100755 +--- a/run.py ++++ b/run.py +@@ -1,6 +1,9 @@ + #!/usr/bin/env python3 + from powerdnsadmin import create_app ++from .powerdnsadmin.routes.index import register_modules + + if __name__ == '__main__': + app = create_app() ++ with app.app_context(): ++ register_modules() + app.run(debug=True, host=app.config.get('BIND_ADDRESS', '127.0.0.1'), port=app.config.get('PORT', '9191')) +-- +2.42.0 + diff --git a/pkgs/applications/networking/powerdns-admin/default.nix b/pkgs/applications/networking/powerdns-admin/default.nix index d029c90680237..61a728d983b36 100644 --- a/pkgs/applications/networking/powerdns-admin/default.nix +++ b/pkgs/applications/networking/powerdns-admin/default.nix @@ -19,10 +19,9 @@ let lima lxml passlib pyasn1 pytimeparse pyyaml jinja2 itsdangerous webcolors werkzeug zipp zxcvbn ]; - all_post_patch = '' - # flask 2.3: 'Blueprint' object has no attribute 'before_app_first_request' - substituteInPlace powerdnsadmin/routes/index.py --replace '@index_bp.before_app_first_request' "" - ''; + all_patches = [ + ./0001-Fix-flask-2.3-issue.patch + ]; assets = mkYarnPackage { inherit src version; @@ -40,10 +39,9 @@ let }; nativeBuildInputs = pythonDeps; - patchPhase = '' - sed -i -r -e "s|'rcssmin',\s?'cssrewrite'|'rcssmin'|g" powerdnsadmin/assets.py - ${all_post_patch} - ''; + patches = all_patches ++ [ + ./0002-Remove-cssrewrite-filter.patch + ]; buildPhase = '' # The build process expects the directory to be writable # with node_modules at a specific path @@ -92,25 +90,15 @@ in stdenv.mkDerivation { exec python -m gunicorn.app.wsgiapp "powerdnsadmin:create_app()" "$@" ''; + patches = all_patches ++ [ + ./0003-Fix-flask-migrate-4.0-compatibility.patch + ./0004-Fix-flask-session-and-powerdns-admin-compatibility.patch + ./0005-Use-app-context-to-create-routes.patch + ./0006-Register-modules-before-starting.patch + ]; + postPatch = '' rm -r powerdnsadmin/static powerdnsadmin/assets.py - # flask-migrate 4.0 compatibility: https://github.com/PowerDNS-Admin/PowerDNS-Admin/issues/1376 - substituteInPlace migrations/env.py --replace "render_as_batch=config.get_main_option('sqlalchemy.url').startswith('sqlite:')," "" - # flask-session and powerdns-admin both try to add sqlalchemy to flask. - # Reuse the database for flask-session - substituteInPlace powerdnsadmin/__init__.py --replace "sess = Session(app)" "app.config['SESSION_SQLALCHEMY'] = models.base.db; sess = Session(app)" - # Routes creates session database tables, so it needs a context - substituteInPlace powerdnsadmin/__init__.py --replace "routes.init_app(app)" "with app.app_context(): routes.init_app(app)" - - # flask 2.3: 'Blueprint' object has no attribute 'before_app_first_request' - # Run code before app.run() instead - substituteInPlace run.py \ - --replace 'from powerdnsadmin import create_app' 'from powerdnsadmin import create_app - from .powerdnsadmin.routes.index import register_modules' \ - --replace 'app = create_app()' 'app = create_app() - with app.app_context(): - register_modules()' - ${all_post_patch} ''; installPhase = '' |