From 6c69fcdbc92c7fd369bd441a7e1edc8749a1bba4 Mon Sep 17 00:00:00 2001 From: Piotr Dobrowolski Date: Sun, 17 Oct 2021 00:32:25 +0200 Subject: [PATCH] hswaw/machines/customs: rework checkinator build Change-Id: I4ec569c5966f65f46f48a3707842a1fe9d483e16 Reviewed-on: https://gerrit.hackerspace.pl/c/hscloud/+/1171 Reviewed-by: informatic --- .../checkinator-tracker.nix | 9 +---- .../checkinator-web.nix | 17 +++----- .../checkinator-werkzeug.patch | 13 +++++++ .../customs.hackerspace.pl/checkinator.nix | 39 +++++++++++++++++++ 4 files changed, 58 insertions(+), 20 deletions(-) create mode 100644 hswaw/machines/customs.hackerspace.pl/checkinator-werkzeug.patch create mode 100644 hswaw/machines/customs.hackerspace.pl/checkinator.nix diff --git a/hswaw/machines/customs.hackerspace.pl/checkinator-tracker.nix b/hswaw/machines/customs.hackerspace.pl/checkinator-tracker.nix index 74617c71..17a9b170 100644 --- a/hswaw/machines/customs.hackerspace.pl/checkinator-tracker.nix +++ b/hswaw/machines/customs.hackerspace.pl/checkinator-tracker.nix @@ -1,14 +1,7 @@ { pkgs, ... }: let - old-pkgs = import (fetchTarball { - sha256 = "0kdx3pz0l422d0vvvj3h8mnq65jcg2scb13dc1z1lg2a8cln842z"; - url = https://api.github.com/repos/NixOS/nixpkgs/tarball/0bf298df24f721a7f85c580339fb7eeff64b927c; - }) { config = pkgs.config; }; - - repo = pkgs.fetchgit (builtins.fromJSON - (builtins.readFile ./checkinator-repo.json)); - checkinator = old-pkgs.callPackage "${repo}/default.nix" {}; + checkinator = pkgs.callPackage ./checkinator.nix {}; name = "checkinator-tracker"; user = name; diff --git a/hswaw/machines/customs.hackerspace.pl/checkinator-web.nix b/hswaw/machines/customs.hackerspace.pl/checkinator-web.nix index 26da7020..91655753 100644 --- a/hswaw/machines/customs.hackerspace.pl/checkinator-web.nix +++ b/hswaw/machines/customs.hackerspace.pl/checkinator-web.nix @@ -1,23 +1,16 @@ { pkgs, ... }: let - old-pkgs = import (fetchTarball { - sha256 = "0kdx3pz0l422d0vvvj3h8mnq65jcg2scb13dc1z1lg2a8cln842z"; - url = https://api.github.com/repos/NixOS/nixpkgs/tarball/0bf298df24f721a7f85c580339fb7eeff64b927c; - }) { config = pkgs.config; }; - - repo = pkgs.fetchgit (builtins.fromJSON - (builtins.readFile ./checkinator-repo.json)); - checkinator = old-pkgs.callPackage "${repo}/default.nix" {}; + checkinator = pkgs.callPackage ./checkinator.nix {}; name = "checkinator-web"; user = name; group = name; socket_dir = "/run/${name}/"; - python = old-pkgs.python3.withPackages (ppackages: with ppackages; [ + python = pkgs.python3.withPackages (ppackages: with ppackages; [ checkinator - old-pkgs.python3Packages.gunicorn + pkgs.python3Packages.gunicorn ]); prepare = pkgs.writeShellScriptBin "${name}-prepare" '' @@ -101,7 +94,7 @@ in { "${pkgs.writeShellScript "checkinator-dbsetup" '' if [ ! -e "/var/checkinator-web/at.db" ] then - ${pkgs.sqlite}/bin/sqlite3 /var/checkinator-web/at.db < ${repo}/dbsetup.sql + ${pkgs.sqlite}/bin/sqlite3 /var/checkinator-web/at.db < ${checkinator}/dbsetup.sql fi ''}" ]; @@ -118,7 +111,7 @@ in { enableACME = true; locations."/static/" = { - alias = "${repo}/static/"; + alias = "${checkinator}/static/"; }; locations."/" = { proxyPass = "http://unix://${socket_dir}/web.sock"; diff --git a/hswaw/machines/customs.hackerspace.pl/checkinator-werkzeug.patch b/hswaw/machines/customs.hackerspace.pl/checkinator-werkzeug.patch new file mode 100644 index 00000000..7517a68e --- /dev/null +++ b/hswaw/machines/customs.hackerspace.pl/checkinator-werkzeug.patch @@ -0,0 +1,13 @@ +diff --git a/at/web.py b/at/web.py +index 34b6337..9eb5e6a 100644 +--- a/at/web.py ++++ b/at/web.py +@@ -54,7 +54,7 @@ def app(instance_path, devices_api, config): + app.updater = devices_api + + if app.config.get('PROXY_FIX'): +- from werkzeug.contrib.fixers import ProxyFix ++ from werkzeug.middleware.proxy_fix import ProxyFix + app.wsgi_app = ProxyFix(app.wsgi_app) + + app.space_auth = SpaceAuth(app) diff --git a/hswaw/machines/customs.hackerspace.pl/checkinator.nix b/hswaw/machines/customs.hackerspace.pl/checkinator.nix new file mode 100644 index 00000000..4135f7a7 --- /dev/null +++ b/hswaw/machines/customs.hackerspace.pl/checkinator.nix @@ -0,0 +1,39 @@ +{ pkgs }: + +let + spaceauth = pkgs.callPackage "${pkgs.fetchgit { + url = "https://code.hackerspace.pl/informatic/flask-spaceauth"; + rev = "d3e1a4412cbc929249e407ccecfb54fbbd14e53a"; + sha256 = "01qnjj647jw81hcyvq359rwqjpc5ah9ghvc6ic0a0wppp13mgw94"; + }}" {}; +in pkgs.python3Packages.buildPythonPackage { + pname = "checkinator"; + version = "0.2"; + + doCheck = false; + src = pkgs.fetchgit (builtins.fromJSON (builtins.readFile ./checkinator-repo.json)); + + patches = [ + ./checkinator-werkzeug.patch + ]; + + postInstall = '' + cp -r dbsetup.sql $out/dbsetup.sql + cp -r static $out/static + ''; + + propagatedBuildInputs = with pkgs; [ + python3Packages.gunicorn + python3Packages.flask + python3Packages.pyyaml + python3Packages.isodate + python3Packages.requests + python3Packages.requests-unixsocket + python3Packages.grpcio + python3Packages.grpcio-tools + python3Packages.setuptools + python3Packages.protobuf + spaceauth + iproute + ]; +}