blob: e46eb904c9e73265f32bc77c3586ec597c95c2c2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
{ pkgs, config, ... }:
let
# secrets = config.sops.secrets;
# domainInternal = "git.sorre.internal";
domainPublic = "git.sorre.xyz";
commonSettings = {
readme = "main:README.md";
};
in
{
networking.firewall.allowedTCPPorts = [ 8721 ];
services.nginx = {
enable = true;
# virtualHosts."${domainInternal}" = {
# forceSSL = true;
# # sslCertificateKey = secrets."wg-ca-key".path;
# # sslCertificate = secrets."wg-ca-crt".path;
# listen = [
# {
# addr = "100.64.0.3";
# port = 443;
# # ssl = true;
# }
# ];
# };
virtualHosts."${domainPublic}" = {
listen = [
{
addr = "100.64.0.6";
port = 8721;
}
];
};
};
# services.cgit.internal = {
# enable = true;
# user = "cgit-internal";
# group = "cgit";
# nginx.virtualHost = domainInternal;
# gitHttpBackend.checkExportOkFiles = false;
# scanPath = "/var/lib/git/repos/isabella";
# settings = commonSettings;
# };
services.cgit.public = {
enable = true;
user = "cgit-public";
group = "cgit";
nginx.virtualHost = domainPublic;
gitHttpBackend.checkExportOkFiles = false;
repos = {
futils.path = "/var/lib/git/repos/isabella/futils";
xpkgs.path = "/var/lib/git/repos/isabella/xpkgs";
sorre-website.path = "/var/lib/git/repos/isabella/sorre-website";
nixos-config.path = "/var/lib/git/repos/isabella/nixos-config";
};
settings = commonSettings;
};
systemd.services.backup-git-repos = {
serviceConfig = {
Type = "exec";
DynamicUser = true;
Group = "cgit";
StateDirectory = "backups/git";
StateDirectoryMode = "0700";
Umask = "077";
};
# TODO: figure out how to check for in-progress transfers and handle that.
description = "Back up git repositories";
path = [ pkgs.gnutar ];
enableStrictShellChecks = true;
script = ''
#!/usr/bin/env bash
set -euo pipefail
TIMESTAMP="$(date +%Y%m%d%H%M%S)"
BACKUP_PATH="$STATE_DIRECTORY/$TIMESTAMP.backup.tar"
echo "Backing up git to $BACKUP_PATH" >&2
tar cf "$BACKUP_PATH" /var/lib/git
chmod u=r,go-rwx "$BACKUP_PATH"
find "$STATE_DIRECTORY" -type f -name '*.backup.tar' -print0 |
sort --zero-terminated --reverse |
tail --zero-terminated --lines=+6 |
xargs --null --no-run-if-empty rm --
'';
};
systemd.timers.backup-git-repos = {
description = "Back up git repos every morning";
timerConfig.OnCalendar = "*-*-* 05:00:00";
wantedBy = [ "timers.target" ];
};
}
|