10 Commits

Author SHA1 Message Date
malobot
69693c5e63 Update flake.lock 2026-03-19 00:03:11 +00:00
bf3f4db1b2 [hydra] forgot to change repo
All checks were successful
Check flake syntax / flake-check (push) Successful in 32m56s
Weekly Flake Update / update_and_check_flake (push) Successful in 5m55s
2026-03-16 20:58:45 +01:00
f4614f2887 [modules] do not reference self within modules
Some checks failed
Check flake syntax / flake-check (push) Has been cancelled
if it gets included in other flakes 'self' references to that flake,
instead of malobeo
2026-03-16 20:52:14 +01:00
07d7f3b882 [modules] add gitea translator
All checks were successful
Check flake syntax / flake-check (push) Successful in 6m13s
2026-03-16 20:42:26 +01:00
6dee590206 Merge pull request 'Hydra integration' (#145) from ahtlon/infrastructure:hydra_integration3 into master
All checks were successful
Check flake syntax / flake-check (push) Successful in 12m9s
Reviewed-on: #145
Reviewed-by: kalipso <kalipso@c3d2.de>
2026-03-14 12:21:15 +01:00
b6cd2b57f8 Document the gitea-translator module 2026-03-13 16:30:31 +01:00
c80628a1a9 Add gitea-translator server and module 2026-03-13 16:09:12 +01:00
8cd2eafaa5 Fix master build 2026-03-13 15:50:32 +01:00
ed19426eb7 Add status callback 2026-03-13 15:21:14 +01:00
7ff64a5c16 Add hydra spec files 2026-03-13 14:39:49 +01:00
8 changed files with 328 additions and 15 deletions

View File

@@ -0,0 +1,75 @@
{ nixpkgs, pulls, ... }:
let
pkgs = import nixpkgs { };
prs = builtins.fromJSON (builtins.readFile pulls);
prJobsets = pkgs.lib.mapAttrs (num: info: {
enabled = 1;
hidden = false;
description = "PR ${num}: ${info.title}";
checkinterval = 300;
schedulingshares = 20;
enableemail = false;
emailoverride = "";
keepnr = 1;
type = 1;
flake = "${info.head.repo.html_url}/archive/${info.head.ref}.tar.gz";
inputs = {
gitea_repo_name = {
type = "string";
value = "${info.head.repo.name}";
emailresponsible = false;
};
gitea_repo_owner = {
type = "string";
value = "${info.head.repo.owner.username}";
emailresponsible = false;
};
gitea_http_url = {
type = "string";
value = "https://git.dynamicdiscord.de";
emailresponsible = false;
};
gitea_status_repo = {
type = "string";
value = "${info.head.ref}";
emailresponsible = false;
};
};
}) prs;
mkFlakeJobset = branch: {
description = "Build ${branch} branch of the Malobeo Infrastructure repo";
checkinterval = 300;
enabled = "1";
schedulingshares = 100;
enableemail = false;
emailoverride = "";
keepnr = 3;
hidden = false;
type = 1;
flake = "https://git.dynamicdiscord.de/malobeo/infrastructure/archive/${branch}.tar.gz";
};
desc = prJobsets // {
"master" = mkFlakeJobset "master";
};
log = {
pulls = prs;
jobsets = desc;
};
in
{
jobsets = pkgs.runCommand "spec-jobsets.json" { } ''
cat >$out <<'EOF'
${builtins.toJSON desc}
EOF
# This is to get nice .jobsets build logs on Hydra
cat >tmp <<'EOF'
${builtins.toJSON log}
EOF
${pkgs.jq}/bin/jq . tmp
'';
}

30
.hydra/spec.json Normal file
View File

@@ -0,0 +1,30 @@
{
"enabled": 1,
"hidden": false,
"description": "Malobeo infrastructure repo",
"nixexprinput": "nixexpr",
"nixexprpath": ".hydra/declarative-jobsets.nix",
"checkinterval": 60,
"schedulingshares": 100,
"enableemail": false,
"emailoverride": "",
"keepnr": 5,
"type": 0,
"inputs": {
"nixexpr": {
"value": "https://git.dynamicdiscord.de/malobeo/infrastructure master",
"type": "git",
"emailresponsible": false
},
"nixpkgs": {
"value": "https://github.com/NixOS/nixpkgs nixos-25.11",
"type": "git",
"emailresponsible": false
},
"pulls": {
"type": "path",
"value": "http://127.0.0.1:27364/gitea-pulls-sorted.json",
"emailresponsible": false
}
}
}

View File

@@ -12,6 +12,7 @@
- [musik](./projekte/musik.md)
- [TODO](./todo.md)
- [Modules]()
- [Gitea-translator](./module/gitea-translator.md)
- [Initrd-ssh](./module/initssh.md)
- [Disks](./module/disks.md)
- [How-to]()

View File

@@ -0,0 +1,21 @@
# Gitea-tanslator
The module can be used by importing `inputs.self.nixosModules.malobeo.gitea-translator`
This module starts a python server that fetches the gitea pull request api and translates it to a file that hydra understands.
To use, just set the parameters of the gitea server, then send a GET request to either `http://${host}:${port}/` or `http://${host}:${port}/gitea-pulls-sorted.json`
## Module config
##### enable (default = false) - enables the module
##### baseurl (default = "git.dynamicdiscord.de") - Base URL of the Gitea instance
##### owner (default = "malobeo") - Repository owner
##### repo (default = "infrastructure") - Repository name
##### host (default = "127.0.0.1") - Address the server binds to
##### port (default = 27364) - Port the server listens on
## Hydra config
If you change the default port or host, the file `.hydra/spec.json` has to be modified accordingly.
With the module running on the hydra host, create a new hydra project, then:
- Set `Declarative spec file` to `.hydra/spec.json`
- Change declaritive input type to `Git checkout`
- Set your git repo location in the field below that

30
flake.lock generated
View File

@@ -126,11 +126,11 @@
"spectrum": "spectrum"
},
"locked": {
"lastModified": 1773018425,
"narHash": "sha256-fpgZBmZpKoEXEowBK/6m8g9FcOLWQ4UxhXHqCw2CpSM=",
"lastModified": 1773872447,
"narHash": "sha256-IWTp4EMUfZwnuF5S/AjWfOFzCbbgkMzRwNd0qHC/EMg=",
"owner": "astro",
"repo": "microvm.nix",
"rev": "25ebda3c558e923720c965832dc9a04f559a055c",
"rev": "b202882536b018a76f0b6e71a48677f41f4de9d8",
"type": "github"
},
"original": {
@@ -177,11 +177,11 @@
},
"nixos-hardware": {
"locked": {
"lastModified": 1772972630,
"narHash": "sha256-mUJxsNOrBMNOUJzN0pfdVJ1r2pxeqm9gI/yIKXzVVbk=",
"lastModified": 1773533765,
"narHash": "sha256-qonGfS2lzCgCl59Zl63jF6dIRRpvW3AJooBGMaXjHiY=",
"owner": "NixOS",
"repo": "nixos-hardware",
"rev": "3966ce987e1a9a164205ac8259a5fe8a64528f72",
"rev": "f8e82243fd601afb9f59ad230958bd073795cbfe",
"type": "github"
},
"original": {
@@ -209,11 +209,11 @@
},
"nixpkgs-unstable": {
"locked": {
"lastModified": 1772963539,
"narHash": "sha256-9jVDGZnvCckTGdYT53d/EfznygLskyLQXYwJLKMPsZs=",
"lastModified": 1773734432,
"narHash": "sha256-IF5ppUWh6gHGHYDbtVUyhwy/i7D261P7fWD1bPefOsw=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "9dcb002ca1690658be4a04645215baea8b95f31d",
"rev": "cda48547b432e8d3b18b4180ba07473762ec8558",
"type": "github"
},
"original": {
@@ -225,11 +225,11 @@
},
"nixpkgs_2": {
"locked": {
"lastModified": 1773068389,
"narHash": "sha256-vMrm7Pk2hjBRPnCSjhq1pH0bg350Z+pXhqZ9ICiqqCs=",
"lastModified": 1773814637,
"narHash": "sha256-GNU+ooRmrHLfjlMsKdn0prEKVa0faVanm0jrgu1J/gY=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "44bae273f9f82d480273bab26f5c50de3724f52f",
"rev": "fea3b367d61c1a6592bc47c72f40a9f3e6a53e96",
"type": "github"
},
"original": {
@@ -264,11 +264,11 @@
]
},
"locked": {
"lastModified": 1773096132,
"narHash": "sha256-M3zEnq9OElB7zqc+mjgPlByPm1O5t2fbUrH3t/Hm5Ag=",
"lastModified": 1773698643,
"narHash": "sha256-VCiDjE8kNs8uCAK73Ezk1r3fFuc4JepvW07YFqaN968=",
"owner": "Mic92",
"repo": "sops-nix",
"rev": "d1ff3b1034d5bab5d7d8086a7803c5a5968cd784",
"rev": "8237de83e8200d16fe0c4467b02a1c608ff28044",
"type": "github"
},
"original": {

View File

@@ -0,0 +1,78 @@
{ config, self, lib, inputs, pkgs, ... }:
with lib;
let
cfg = config.services.malobeo.gitea-translator;
in
{
options = {
services.malobeo.gitea-translator = {
enable = mkOption {
default = false;
type = types.bool;
description = lib.mdDoc "Start a webserver for hydra to use the gitea pull request api.";
};
baseurl = mkOption {
type = types.str;
default = "git.dynamicdiscord.de";
description = lib.mdDoc "Base URL of the Gitea instance.";
};
owner = mkOption {
type = types.str;
default = "malobeo";
description = lib.mdDoc "Repository owner on the Gitea instance.";
};
repo = mkOption {
type = types.str;
default = "infrastructure";
description = lib.mdDoc "Repository name on the Gitea instance.";
};
host = mkOption {
type = types.str;
default = "127.0.0.1";
description = lib.mdDoc "Address the server binds to.";
};
port = mkOption {
type = types.port;
default = 27364;
description = lib.mdDoc "Port the server listens on.";
};
};
};
config = mkIf cfg.enable {
systemd.services.gitea-translator = {
description = "Gitea Pull Request Translator for Hydra";
after = [ "network-online.target" ];
wants = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = ''
${pkgs.python3}/bin/python3 ${../../../scripts/gitea_hydra_server.py} \
--baseurl ${cfg.baseurl} \
--owner ${cfg.owner} \
--repo ${cfg.repo} \
--host ${cfg.host} \
--port ${toString cfg.port}
'';
Restart = "on-failure";
RestartSec = 5;
# Hardening because why not
DynamicUser = true;
NoNewPrivileges = true;
ProtectSystem = "strict";
ProtectHome = true;
PrivateTmp = true;
PrivateDevices = true;
};
};
};
}

View File

@@ -118,6 +118,7 @@ in (utils.lib.eachSystem (builtins.filter filter_system utils.lib.defaultSystems
users.imports = [ ./machines/modules/malobeo/users.nix ];
backup.imports = [ ./machines/modules/malobeo/backup.nix ];
printing.imports = [ ./machines/modules/malobeo/printing.nix ];
gitea-translator.imports = [ ./machines/modules/malobeo/gitea_translator.nix ];
};
hydraJobs = nixpkgs.lib.mapAttrs (_: nixpkgs.lib.hydraJob) (

View File

@@ -0,0 +1,107 @@
#!/usr/bin/env python3
#imports
import os
import json
import argparse
from http.server import BaseHTTPRequestHandler, HTTPServer
import urllib.request
def _get_api_response(baseurl, owner, repo):
###https://docs.gitea.com/api/1.21/#tag/repository/operation/repoListPullRequests
###GET /api/v1/repos/{owner}/{repo}/pulls
url=(f"https://{baseurl}/api/v1/repos/{owner}/{repo}/pulls?state=open")
headers={"Accept": "application/json"}
req=urllib.request.Request(url, headers=headers)
with urllib.request.urlopen(req) as resp:
return json.loads(resp.read().decode("utf-8"))
def _parse_response(baseurl, owner, repo):
target_repo_url=f"https://{baseurl}/{owner}/{repo}.git"
pulls: dict={}
response=_get_api_response(baseurl, owner, repo)
for pr in response:
pr["target_repo_url"]=target_repo_url
pulls[str(pr["number"])]=pr
return pulls
class PullsHandler(BaseHTTPRequestHandler):
_VALID_PATHS={"/", "/gitea-pulls-sorted.json"}
# Class variables to store configuration
baseurl = None
owner = None
repo = None
def do_GET(self):
if self.path not in self._VALID_PATHS:
self.send_error(404, "Not Found")
return
answer=dict(_parse_response(self.baseurl, self.owner, self.repo))
body=json.dumps(answer, indent=2, sort_keys=True).encode("utf-8")
self.send_response(200)
self.send_header("Content-Type", "application/json; charset=utf-8")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)
def log_message(self, fmt, *args):
print(
f"[gitea-translator] {self.address_string()} - {fmt % args}",
flush=True,
)
def main():
parser = argparse.ArgumentParser(
description="Hydra Server to Gitea-pull-request translator"
)
parser.add_argument(
"--baseurl",
default="git.dynamicdiscord.de",
help="Base URL of Gitea instance (default: git.dynamicdiscord.de)"
)
parser.add_argument(
"--owner",
default="malobeo",
help="Repository owner (default: malobeo)"
)
parser.add_argument(
"--repo",
default="infrastructure",
help="Repository name (default: infrastructure)"
)
parser.add_argument(
"--host",
default="127.0.0.1",
help="Host to bind to (default: 127.0.0.1)"
)
parser.add_argument(
"--port",
type=int,
default=27364,
help="Port to bind to (default: 27364)"
)
args = parser.parse_args()
# Set class variables so they're accessible in request handlers
PullsHandler.baseurl = args.baseurl
PullsHandler.owner = args.owner
PullsHandler.repo = args.repo
print(
f"[gitea-translator] Starting, pulling from {args.baseurl}/{args.owner}/{args.repo}",
flush=True,
)
server=HTTPServer((args.host, args.port), PullsHandler)
print(
f"[gitea-translator] online @ {args.host}:{args.port}",
flush=True,
)
server.serve_forever()
if __name__ == "__main__":
main()