From 3e62ce8b08b7a36a683341c07e51c554840bfe7a Mon Sep 17 00:00:00 2001 From: stupidcomputer Date: Tue, 8 Oct 2024 23:34:31 -0500 Subject: [PATCH] just some boilerplate for the project --- .gitignore | 1 + .vscode/settings.json | 3 +++ bridge/__init__.py | 11 +++++++++++ contrib/sample.cfg | 1 + contrib/service.nix | 19 +++++++++++++++++++ default.nix | 20 ++++++++++++++++++++ shell.nix | 13 +++++++++++++ 7 files changed, 68 insertions(+) create mode 100644 .gitignore create mode 100644 .vscode/settings.json create mode 100644 bridge/__init__.py create mode 100644 contrib/sample.cfg create mode 100644 contrib/service.nix create mode 100644 default.nix create mode 100644 shell.nix diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..786d4d3 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "nixEnvSelector.nixFile": "${workspaceFolder}/shell.nix" +} \ No newline at end of file diff --git a/bridge/__init__.py b/bridge/__init__.py new file mode 100644 index 0000000..12987b0 --- /dev/null +++ b/bridge/__init__.py @@ -0,0 +1,11 @@ +from flask import Flask +from flask import request +from flask import redirect +from flask import abort + +app = Flask(__name__) +app.config.from_envvar('GIT_BRIDGE_SETTINGS') + +@app.route("/bridge") +def index(): + return "you've reached the main page for an internal service. congrats!" \ No newline at end of file diff --git a/contrib/sample.cfg b/contrib/sample.cfg new file mode 100644 index 0000000..84951fb --- /dev/null +++ b/contrib/sample.cfg @@ -0,0 +1 @@ +SECRET_KEY="replace_me" \ No newline at end of file diff --git a/contrib/service.nix b/contrib/service.nix new file mode 100644 index 0000000..1d715d9 --- /dev/null +++ b/contrib/service.nix @@ -0,0 +1,19 @@ +{ lib, pkgs, config, ... }: +let + cfg = config.services.gmail_mail_bridge; + appEnv = pkgs.python3.withPackages (p: with p; [ waitress (callPackage ./bridge/default.nix {}) ]); +in { + options.services.gmail_mail_bridge = { + enable = lib.mkEnableOption "Enable the Gitea-Github bridge"; + }; + + config = lib.mkIf cfg.enable { + systemd.services.gmail_mail_bridge = { + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = "${appEnv}/bin/waitress-serve --port=8041 bridge:app"; + StandardOutput = "journal"; + }; + }; + }; +} \ No newline at end of file diff --git a/default.nix b/default.nix new file mode 100644 index 0000000..51a3b96 --- /dev/null +++ b/default.nix @@ -0,0 +1,20 @@ +{ pkgs, pythonPackages ? (import {}).python3Packages }: +pythonPackages.buildPythonPackage { + name = "gitea-github-bridge"; + src = ./bridge; + + propagatedBuildInputs = [ pythonPackages.flask pythonPackages.requests ]; + + installPhase = '' + runHook preInstall + + mkdir -p $out/${pythonPackages.python.sitePackages} + cp -r . $out/${pythonPackages.python.sitePackages}/bridge + + runHook postInstall + ''; + + shellHook = "export FLASK_APP=bridge"; + + format = "other"; +} \ No newline at end of file diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..89c5142 --- /dev/null +++ b/shell.nix @@ -0,0 +1,13 @@ +{ pkgs ? import (fetchTarball "https://github.com/NixOS/nixpkgs/tarball/nixos-24.05") {} }: + +pkgs.mkShell { + packages = [ + (pkgs.python3.withPackages (ps: [ + ps.flask + ps.requests + ])) + + pkgs.curl + pkgs.jq + ]; +} \ No newline at end of file