2022-06-06 12:37:11 +02:00
|
|
|
{ depot, pkgs, lib, config, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
virtualHost = "code.sterni.lv";
|
|
|
|
|
2022-11-27 15:00:06 +01:00
|
|
|
repoSections = [
|
|
|
|
{
|
|
|
|
section = "active";
|
|
|
|
repos = {
|
|
|
|
spacecookie = {
|
|
|
|
description = "gopher server (and library for Haskell)";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/spacecookie.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
2022-11-30 16:42:58 +01:00
|
|
|
"mirror/depot" = {
|
|
|
|
description = "monorepo for the virus lounge";
|
2022-12-02 15:27:15 +01:00
|
|
|
upstream = "https://code.tvl.fyi/depot.git";
|
2023-01-12 19:30:10 +01:00
|
|
|
cgit.defbranch = "canon";
|
2022-11-30 16:42:58 +01:00
|
|
|
};
|
|
|
|
"mirror/flipdot-gschichtler" = {
|
|
|
|
description = "message queue system for OpenLab's flipdot display";
|
|
|
|
upstream = "https://github.com/openlab-aux/flipdot-gschichtler.git";
|
|
|
|
};
|
|
|
|
"mirror/nixpkgs" = {
|
|
|
|
description = "Nix packages collection";
|
|
|
|
upstream = "https://github.com/nixos/nixpkgs.git";
|
2022-12-29 14:35:07 +01:00
|
|
|
cgit.enable-commit-graph = "0"; # too slow
|
2022-11-30 16:42:58 +01:00
|
|
|
};
|
2023-03-01 00:12:19 +01:00
|
|
|
"mirror/vuizvui" = {
|
|
|
|
description = "Nix(OS) expressions used by the OpenLab and its members";
|
|
|
|
upstream = "https://github.com/openlab-aux/vuizvui.git";
|
|
|
|
};
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
|
|
|
section = "poc";
|
|
|
|
repos = {
|
|
|
|
emoji-generic = {
|
|
|
|
description = "generic emoji library for Haskell";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/emoji-generic.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
grav2ty = {
|
|
|
|
description = "“realistic” 2d space game";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/grav2ty.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
haskell-dot-time = {
|
|
|
|
description = "UTC-centric time library for haskell with dot time support";
|
2023-01-12 19:30:10 +01:00
|
|
|
cgit.defbranch = "main";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
buchstabensuppe = {
|
|
|
|
description = "toy font rendering for low pixelcount, high contrast displays";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/buchstabensuppe.git";
|
2023-01-12 19:30:10 +01:00
|
|
|
cgit.defbranch = "main";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
2022-11-30 16:42:58 +01:00
|
|
|
"mirror/saneterm" = {
|
|
|
|
description = "modern line-oriented terminal emulator without support for TUIs";
|
2023-04-07 14:12:11 +02:00
|
|
|
upstream = "https://git.8pit.net/saneterm.git";
|
2022-11-30 16:42:58 +01:00
|
|
|
};
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
}
|
|
|
|
{
|
2022-12-29 14:35:07 +01:00
|
|
|
# TODO(sterni): resisort, klammeraffe, cl-ca, ponify, tinyrl
|
2022-11-27 15:00:06 +01:00
|
|
|
section = "archive";
|
|
|
|
repos = {
|
|
|
|
gopher-proxy = {
|
|
|
|
description = "Gopher over HTTP proxy";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/gopher-proxy.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
likely-music = {
|
|
|
|
description = "experimental application for probabilistic music composition";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/likely-music.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
logbook = {
|
|
|
|
description = "file format for keeping a personal log";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/logbook.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
sternenblog = {
|
|
|
|
description = "file based cgi blog software";
|
2022-11-30 15:52:08 +01:00
|
|
|
upstream = "https://github.com/sternenseemann/sternenblog.git";
|
2022-11-27 15:00:06 +01:00
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
];
|
2022-06-06 12:37:11 +02:00
|
|
|
|
2022-11-30 15:52:08 +01:00
|
|
|
repoPath = name: repo: repo.path or "/srv/git/${name}.git";
|
|
|
|
|
2022-06-06 12:37:11 +02:00
|
|
|
cgitRepoEntry = name: repo:
|
|
|
|
lib.concatStringsSep "\n" (
|
|
|
|
[
|
2022-11-30 15:52:08 +01:00
|
|
|
"repo.url=${name}"
|
|
|
|
"repo.path=${repoPath name repo}"
|
2022-06-06 12:37:11 +02:00
|
|
|
]
|
|
|
|
++ lib.optional (repo ? description) "repo.desc=${repo.description}"
|
2022-12-29 14:35:07 +01:00
|
|
|
++ lib.mapAttrsToList (n: v: "repo.${n}=${v}") repo.cgit or { }
|
2022-06-06 12:37:11 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
cgitHead = pkgs.writeText "cgit-head.html" ''
|
|
|
|
<style>
|
|
|
|
#summary {
|
|
|
|
max-width: 80em;
|
|
|
|
}
|
|
|
|
|
|
|
|
#summary * {
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|
|
|
|
'';
|
|
|
|
|
|
|
|
cgitConfig = pkgs.writeText "cgitrc" ''
|
|
|
|
virtual-root=/
|
|
|
|
|
|
|
|
enable-http-clone=1
|
|
|
|
clone-url=https://${virtualHost}/$CGIT_REPO_URL
|
|
|
|
|
|
|
|
enable-blame=1
|
|
|
|
enable-log-filecount=1
|
|
|
|
enable-log-linecount=1
|
|
|
|
enable-index-owner=0
|
|
|
|
enable-blame=1
|
|
|
|
enable-commit-graph=1
|
|
|
|
|
2022-11-27 15:00:06 +01:00
|
|
|
root-title=code.sterni.lv
|
2022-06-06 12:37:11 +02:00
|
|
|
css=/cgit.css
|
|
|
|
head-include=${cgitHead}
|
|
|
|
|
|
|
|
mimetype-file=${pkgs.mime-types}/etc/mime.types
|
|
|
|
|
|
|
|
about-filter=${depot.tools.cheddar.about-filter}/bin/cheddar-about
|
|
|
|
source-filter=${depot.tools.cheddar}/bin/cheddar
|
|
|
|
readme=:README.md
|
|
|
|
readme=:readme.md
|
|
|
|
|
2022-11-27 15:00:06 +01:00
|
|
|
section-sort=0
|
|
|
|
${
|
|
|
|
lib.concatMapStringsSep "\n" (section:
|
|
|
|
''
|
|
|
|
section=${section.section}
|
2023-01-12 19:30:10 +01:00
|
|
|
|
2022-11-27 15:00:06 +01:00
|
|
|
''
|
|
|
|
+ builtins.concatStringsSep "\n\n" (lib.mapAttrsToList cgitRepoEntry section.repos)
|
|
|
|
) repoSections
|
|
|
|
}
|
2022-06-06 12:37:11 +02:00
|
|
|
'';
|
2022-11-30 15:52:08 +01:00
|
|
|
|
|
|
|
/* Merge a list of attrs, but fail when the same attribute occurs twice.
|
|
|
|
|
|
|
|
Type: [ attrs ] -> attrs
|
|
|
|
*/
|
|
|
|
mergeManyDistinctAttrs = lib.foldAttrs
|
|
|
|
(
|
|
|
|
val: nul:
|
|
|
|
if nul == null then val else throw "Every attribute name may occur only once"
|
|
|
|
)
|
|
|
|
null;
|
|
|
|
|
|
|
|
flatRepos = mergeManyDistinctAttrs
|
|
|
|
(builtins.map (section: section.repos) repoSections);
|
|
|
|
|
|
|
|
reposToMirror = lib.filterAttrs (_: repo: repo ? upstream) flatRepos;
|
|
|
|
|
|
|
|
# User and group name used for running the mirror scripts
|
|
|
|
mirroredReposOwner = "git";
|
2022-11-30 16:42:58 +01:00
|
|
|
|
|
|
|
# Make repo name suitable for systemd unit/timer
|
|
|
|
unitName = name: "mirror-${lib.strings.sanitizeDerivationName name}";
|
2022-06-06 12:37:11 +02:00
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
./nginx.nix
|
|
|
|
./fcgiwrap.nix
|
|
|
|
];
|
|
|
|
|
|
|
|
config = {
|
|
|
|
services.nginx.virtualHosts."${virtualHost}" = {
|
|
|
|
enableACME = true;
|
|
|
|
forceSSL = true;
|
|
|
|
root = "${pkgs.cgit-pink}/cgit/";
|
|
|
|
extraConfig = ''
|
|
|
|
try_files $uri @cgit;
|
|
|
|
|
|
|
|
location @cgit {
|
|
|
|
include ${pkgs.nginx}/conf/fastcgi_params;
|
|
|
|
fastcgi_param SCRIPT_FILENAME ${pkgs.cgit-pink}/cgit/cgit.cgi;
|
|
|
|
fastcgi_param PATH_INFO $uri;
|
|
|
|
fastcgi_param QUERY_STRING $args;
|
|
|
|
fastcgi_param HTTP_HOST $server_name;
|
|
|
|
fastcgi_param CGIT_CONFIG ${cgitConfig};
|
|
|
|
fastcgi_pass unix:${toString config.services.fcgiwrap.socketAddress};
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
};
|
2022-11-30 15:52:08 +01:00
|
|
|
|
|
|
|
users = {
|
|
|
|
users.${mirroredReposOwner} = {
|
|
|
|
group = mirroredReposOwner;
|
|
|
|
isSystemUser = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
groups.${mirroredReposOwner} = { };
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
systemd.timers = lib.mapAttrs'
|
|
|
|
(
|
|
|
|
name: repo:
|
|
|
|
{
|
2022-11-30 16:42:58 +01:00
|
|
|
name = unitName name;
|
2022-11-30 15:52:08 +01:00
|
|
|
value = {
|
|
|
|
description = "regularly update mirror git repository ${name}";
|
|
|
|
wantedBy = [ "timers.target" ];
|
|
|
|
enable = true;
|
|
|
|
timerConfig = {
|
|
|
|
# Fire every 6h and distribute the workload over next 6h randomly
|
|
|
|
OnCalendar = "*-*-* 00/6:00:00";
|
|
|
|
RandomizedDelaySec = "6h";
|
|
|
|
Persistent = true;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
reposToMirror;
|
|
|
|
|
|
|
|
systemd.services = lib.mapAttrs'
|
|
|
|
(
|
|
|
|
name: repo:
|
|
|
|
{
|
2022-11-30 16:42:58 +01:00
|
|
|
name = unitName name;
|
2022-11-30 15:52:08 +01:00
|
|
|
value = {
|
|
|
|
description = "mirror git repository ${name}";
|
2024-02-26 12:18:55 +01:00
|
|
|
requires = [ "network-online.target" ];
|
2023-11-30 13:22:20 +01:00
|
|
|
after = [ "network-online.target" ];
|
2024-02-26 12:18:55 +01:00
|
|
|
|
2022-11-30 15:52:08 +01:00
|
|
|
script =
|
|
|
|
let
|
|
|
|
path = repoPath name repo;
|
|
|
|
in
|
|
|
|
''
|
|
|
|
set -euo pipefail
|
|
|
|
|
|
|
|
export PATH="${lib.makeBinPath [ pkgs.coreutils pkgs.git ]}"
|
|
|
|
|
|
|
|
if test ! -d "${path}"; then
|
|
|
|
mkdir -p "$(dirname "${path}")"
|
|
|
|
git clone --mirror "${repo.upstream}" "${path}"
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
|
|
|
cd "${path}"
|
|
|
|
|
|
|
|
git fetch "${repo.upstream}" '+refs/*:refs/*' --prune
|
|
|
|
'';
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
User = mirroredReposOwner;
|
|
|
|
Group = mirroredReposOwner;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
}
|
|
|
|
)
|
|
|
|
reposToMirror;
|
2022-06-06 12:37:11 +02:00
|
|
|
};
|
|
|
|
}
|