organize, update nixcord, add janitor
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
{ den, ... }: {
|
||||
{
|
||||
den.aspects.gitea-mirrors = {
|
||||
nixos = { pkgs, lib, config, ... }:
|
||||
let
|
||||
@@ -13,6 +13,12 @@
|
||||
giteaUrl = "http://localhost:${toString cfg.settings.server.HTTP_PORT}";
|
||||
tokenFile = "${cfg.stateDir}/mirror-setup-token";
|
||||
|
||||
repoSource = m:
|
||||
if m ? source then m.source
|
||||
else if (m.service or "git") == "github" then "https://github.com/${m.owner}/${m.repo}.git"
|
||||
else if (m.service or "git") == "gitlab" then "https://gitlab.com/${m.owner}/${m.repo}.git"
|
||||
else throw "mirrors.repos: '${m.owner}/${m.repo}' has no source and service '${m.service or "git"}' needs an explicit source";
|
||||
|
||||
setupScript = pkgs.writeShellScript "gitea-mirror-setup" ''
|
||||
set -euo pipefail
|
||||
|
||||
@@ -20,7 +26,6 @@
|
||||
TOKEN_FILE="${tokenFile}"
|
||||
GITEA_CMD="${lib.getExe cfg.package}"
|
||||
|
||||
# wait for gitea to be ready
|
||||
for i in $(seq 1 60); do
|
||||
if ${pkgs.curl}/bin/curl -sf "$GITEA_URL/api/v1/version" >/dev/null 2>&1; then
|
||||
break
|
||||
@@ -29,15 +34,15 @@
|
||||
done
|
||||
|
||||
$GITEA_CMD admin user create \
|
||||
--username "${mcfg.adminUser}" \
|
||||
--email "${mcfg.adminEmail}" \
|
||||
--username "${mcfg.admin.user}" \
|
||||
--email "${mcfg.admin.email}" \
|
||||
--random-password \
|
||||
--admin \
|
||||
--must-change-password=false 2>/dev/null || true
|
||||
|
||||
if [ ! -f "$TOKEN_FILE" ]; then
|
||||
TOKEN=$($GITEA_CMD admin user generate-access-token \
|
||||
--username "${mcfg.adminUser}" \
|
||||
--username "${mcfg.admin.user}" \
|
||||
--token-name "mirror-setup" \
|
||||
--scopes "all" \
|
||||
--raw)
|
||||
@@ -55,7 +60,7 @@
|
||||
-H "Content-Type: application/json" \
|
||||
-d "{
|
||||
\"username\": \"${owner}\",
|
||||
\"email\": \"${owner}@mirror.localhost\",
|
||||
\"email\": \"${owner}@git.bug.tools\",
|
||||
\"password\": \"$RAND_PASS\",
|
||||
\"must_change_password\": false,
|
||||
\"visibility\": \"public\"
|
||||
@@ -67,7 +72,7 @@
|
||||
-H "$AUTH" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{
|
||||
"clone_addr": "${m.source}",
|
||||
"clone_addr": "${repoSource m}",
|
||||
"repo_name": "${m.repo}",
|
||||
"repo_owner": "${m.owner}",
|
||||
"mirror": true,
|
||||
@@ -134,24 +139,27 @@
|
||||
in
|
||||
{
|
||||
options.services.gitea.mirrors = {
|
||||
adminUser = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin";
|
||||
description = "Gitea admin username for mirror management.";
|
||||
};
|
||||
admin = {
|
||||
user = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin";
|
||||
description = "Gitea admin username for mirror management.";
|
||||
};
|
||||
|
||||
adminEmail = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin@localhost";
|
||||
description = "Gitea admin email.";
|
||||
email = lib.mkOption {
|
||||
type = lib.types.str;
|
||||
default = "admin@localhost";
|
||||
description = "Gitea admin email.";
|
||||
};
|
||||
};
|
||||
|
||||
repos = lib.mkOption {
|
||||
type = lib.types.listOf (lib.types.attrsOf lib.types.str);
|
||||
default = [];
|
||||
description = "Individual repositories to mirror. Each entry: { owner, repo, source, service? }.";
|
||||
description = "Individual repositories to mirror. Each entry: { owner, repo, service?, source? }. Source is auto-derived for github/gitlab.";
|
||||
example = [
|
||||
{ owner = "nixos"; repo = "nixpkgs"; source = "https://github.com/NixOS/nixpkgs.git"; service = "github"; }
|
||||
{ owner = "nixos"; repo = "nixpkgs"; service = "github"; }
|
||||
{ owner = "someone"; repo = "thing"; source = "https://custom.instance/someone/thing.git"; }
|
||||
];
|
||||
};
|
||||
|
||||
@@ -180,11 +188,9 @@
|
||||
description = "Setup Gitea mirror repositories";
|
||||
after = [ "gitea.service" ];
|
||||
requires = [ "gitea.service" ];
|
||||
wantedBy = [ "multi-user.target" ];
|
||||
|
||||
serviceConfig = {
|
||||
Type = "oneshot";
|
||||
RemainAfterExit = true;
|
||||
User = cfg.user;
|
||||
Group = cfg.group;
|
||||
ExecStart = setupScript;
|
||||
@@ -195,6 +201,17 @@
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
systemd.timers.gitea-mirror-setup = {
|
||||
description = "Run Gitea mirror setup on boot and periodically";
|
||||
wantedBy = [ "timers.target" ];
|
||||
|
||||
timerConfig = {
|
||||
OnBootSec = "2min";
|
||||
OnUnitActiveSec = "6h";
|
||||
Unit = "gitea-mirror-setup.service";
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
@@ -15,16 +15,19 @@
|
||||
settings.server.HTTP_PORT = 3002;
|
||||
|
||||
mirrors = {
|
||||
adminUser = "admin";
|
||||
adminEmail = "admin@bug.tools";
|
||||
admin = {
|
||||
user = "admin";
|
||||
email = "admin@bug.tools";
|
||||
};
|
||||
|
||||
repos = [
|
||||
{ owner = "gmodena"; repo = "nix-flatpak"; source = "https://github.com/gmodena/nix-flatpak.git"; service = "github"; }
|
||||
{ owner = "FlameFlag"; repo = "nixcord"; source = "https://github.com/FlameFlag/nixcord.git"; service = "github"; }
|
||||
{ owner = "gmodena"; repo = "nix-flatpak"; service = "github"; }
|
||||
{ owner = "FlameFlag"; repo = "nixcord"; service = "github"; }
|
||||
{ owner = "jacob.eva"; repo = "opencom-lte"; source = "https://git.liberatedsystems.co.uk/jacob.eva/opencom-lte.git"; }
|
||||
];
|
||||
|
||||
users = [
|
||||
{ owner = "nix-community"; platform = "github"; }
|
||||
{ owner = "catppuccin"; platform = "github"; }
|
||||
{ owner = "picosh"; platform = "github"; }
|
||||
{ owner = "vic"; platform = "github"; }
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
{ den, ...}: {
|
||||
{
|
||||
den.aspects.glances = {
|
||||
nixos = { pkgs, ... }: {
|
||||
environment.systemPackages = [ pkgs.glances ];
|
||||
|
||||
Reference in New Issue
Block a user