-
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
-
100
-
101
-
102
-
103
-
104
-
105
-
106
-
107
-
108
-
109
-
110
-
111
-
112
-
113
-
114
-
115
-
116
-
117
-
118
-
119
-
120
-
121
-
122
-
123
-
124
-
125
-
126
-
127
-
128
-
129
-
130
-
131
-
132
-
133
-
134
-
135
-
136
-
137
-
138
-
139
-
140
-
141
-
142
-
143
-
144
-
145
-
146
-
147
-
148
-
149
-
150
-
151
-
152
-
153
-
154
-
155
-
156
-
157
-
158
-
159
-
160
-
161
-
162
-
163
-
164
-
165
-
166
-
167
-
168
-
169
-
170
-
171
-
172
-
173
-
174
-
175
-
176
-
177
-
178
-
179
-
180
-
181
-
182
-
183
-
184
-
185
-
186
-
187
-
188
-
189
-
190
-
191
-
192
-
193
-
194
-
195
-
196
-
197
-
198
-
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-
218
-
219
-
220
-
221
-
222
-
223
-
224
-
225
-
226
-
227
-
228
-
229
-
230
-
231
-
232
-
233
-
234
-
235
-
236
-
237
-
238
-
239
-
240
-
241
-
242
-
243
-
244
-
245
-
246
-
247
-
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
-
256
{
config,
lib,
pkgs,
...
}:
{
# Use lower IO priority for Nix so my server is still responsive while getting nix-copy-closured
nix.daemonIOSchedClass = "idle";
nixpkgs = {
hostPlatform = "x86_64-linux";
# Overlays! Fixed points!
overlays = [ (import ./overlays.nix) ];
};
# https://unnamed.website/posts/nixvm/
disko.devices.disk.main = {
imageSize = "2500M";
type = "disk";
device = "/dev/xvda";
content = {
type = "gpt";
partitions = {
boot = {
size = "1M";
type = "EF02";
};
ESP = {
size = "128M";
type = "EF00";
content = {
type = "filesystem";
format = "vfat";
mountpoint = "/boot";
mountOptions = [ "umask=0077" ];
};
};
root = {
size = "100%";
content = {
type = "btrfs";
subvolumes = {
"/".mountpoint = "/";
"/home" = { };
"/nix" = { };
};
};
};
};
};
};
# atime is an anti-feature and disabling it should boost perf on XVM
fileSystems."/".options = [ "noatime" ];
boot = {
# XVM only has BIOS not UEFI, so no systemd-boot ðŸ˜
loader.grub.enable = true;
# Spooky Xen stuff
initrd.availableKernelModules = [
"xen-blkfront"
"xen-netfront"
];
};
networking.hostName = "Unnamed-Server";
# The best time zone
time.timeZone = "UTC";
users.users = {
# For doing updates
root.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPWzNs8PdQKsgSADzbub2XfrZeIrF+jK7M4VMjuRmaIt anthonywang++"
];
# For normal logins
a.openssh.authorizedKeys.keys = [
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPDLPakDnAelqFTUudQB8X0T7yc/8ekV3jGqpeJb062l anthonywang"
];
};
programs.tmux.enable = true;
services.openssh = {
enable = true;
settings = {
# https://forgejo.org/docs/latest/admin/recommendations/#git-over-ssh
# https://docs.gitlab.com/administration/git_protocol/
# Test using GIT_TRACE_PACKET=1 git ls-remote
AcceptEnv = [ "GIT_PROTOCOL" ];
# Don't hack me
PasswordAuthentication = false;
};
};
# Keep the journal small
services.journald.extraConfig = "SystemMaxUse=1G";
# My websites
networking.firewall.allowedTCPPorts = [
80
443
];
services.caddy = {
enable = true;
package = pkgs.caddy.withPlugins {
plugins = [
"github.com/caddy-dns/porkbun@v0.3.1"
"dev.mediocregopher.com/mediocre-caddy-plugins.git@v0.0.0-20250308145011-421597d7c920"
];
hash = "sha256-ljrlhAbXSkg+yzIgpbG69AJm6BsAYvAUvedGTv+7Lu8=";
};
# Porkbun API keys
environmentFile = "/etc/caddy/env";
# By default only errors are logged
logFormat = "";
# Make Caddy log to stdout instead of to a log file
virtualHosts = builtins.mapAttrs (k: v: v // { logFormat = ""; }) {
"unnamed.website".extraConfig = ''
root * /srv/http/www
file_server
handle_errors {
rewrite * /{err.status_code}.html
file_server
}
'';
"git.unnamed.website".extraConfig = ''
handle /robots.txt {
respond "User-agent: *
Disallow: /"
}
# Block scrapers but allow Git clones
@notgit {
# Due to arcane Caddy reasons this still triggers for /robots.txt unless we explicitly ignore it here
not path /robots.txt
not header User-Agent git*
}
proof_of_work @notgit {
# 1 year
challenge_timeout 8760h
}
@assets path /cgit.css /cgit.js /cgit.png /favicon.ico
handle @assets {
root * ${pkgs.cgit}/cgit
file_server
}
reverse_proxy unix//run/fcgiwrap-caddy.sock {
transport fastcgi {
env SCRIPT_FILENAME ${pkgs.cgit}/cgit/cgit.cgi
}
}
'';
"*.unnamed.website".extraConfig = ''
tls {
dns porkbun {
api_key {env.PORKBUN_API_KEY}
api_secret_key {env.PORKBUN_API_SECRET_KEY}
}
}
root * /srv/http/{labels.2}
handle /cgi-bin/* {
reverse_proxy unix//run/fcgiwrap-caddy.sock {
transport fastcgi {
env SCRIPT_FILENAME {http.vars.root}{path}
}
}
}
file_server
'';
"{$SECRET_DOMAIN}".extraConfig = ''
root * /srv/http/{$SECRET_PATH}
file_server
'';
"a.exozy.me ta180m.exozy.me".extraConfig = ''
redir https://unnamed.website{uri} permanent
'';
};
};
# services.cgit configures cgit and fcgiwrap for nginx so it's just more straightforward to do it manually
services.fcgiwrap.instances.caddy.socket = {
user = "caddy";
group = "caddy";
};
environment.etc.cgitrc.text =
(lib.generators.toINIWithGlobalSection { } {
globalSection = {
root-title = "DO NOT L∃∀N";
root-desc = "Department of Provably Bad Code";
clone-prefix = "https://git.unnamed.website";
default-page = "about";
# The owner column is just me repeated so don't show it
enable-index-owner = 0;
# Idle column uses master branch
# https://lists.zx2c4.com/pipermail/cgit/2020-August/004514.html
# Can manually set the time using
# touch -m --date=@$(git log -1 --format=%ct) $(git show-ref | awk '{print $2}')
# https://ch1p.io/cgit-idle-time/
repository-sort = "age";
# The cache reduces load and most importantly, prevents cgit from scanning the repos on disk every time
# To clear cache, restart fcgiwrap-caddy.service
cache-size = 64;
# No spam plz
noplainemail = 1;
# The default md2html filter uses the super slow python-markdown, so instead use MD4C
about-filter = pkgs.writeShellScript "md2html" ''
${pkgs.md4c}/bin/md2html --github | sed 's/<a href="\([^/]*\)">/<a href="tree\/\1">/g'
'';
# Syntax highlighting
source-filter = "${pkgs.cgit}/lib/cgit/filters/syntax-highlighting.py";
readme = ":README.md";
# To make repo unlisted, add hide=1 to its cgitrc
section-from-path = 1;
};
})
# scan-path MUST be last!
# toINIWithGlobalSection sorts the options so we have to manually concatenate scan-path
# https://wiki.archlinux.org/title/Cgit#readme_files_are_not_found,_about_tab_not_shown
+ "scan-path=/srv/git";
systemd = {
# The cgit cache dir must be writable by dynamic user running cgit
# Easy solution is to use /var/tmp as the cache dir
# I couldn't figure out how to set cache-root for cgit, so instead symlink it
tmpfiles.rules = [ "L /var/cache/cgit - - - - /var/tmp" ];
# Update Git mirrors
services.update-mirrors = {
wantedBy = [ "multi-user.target" ];
path = with pkgs; [ git ];
serviceConfig = {
User = "a";
Group = "users";
ExecStart = pkgs.writers.writeFish "update-mirrors" ./update-mirrors.fish;
};
};
timers.update-mirrors = {
wantedBy = [ "multi-user.target" ];
timerConfig.OnCalendar = "weekly";
};
};
# Back up /srv using btrfs snapshots and btrbk
services.btrbk = {
sshAccess = [
{
key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAINoXy/V1rfnAcBJyRMAsqygOAeSNwxf8+oYtWNnUs3Rf btrbk@ThinkPad-X1-Yoga-Gen-6";
roles = [
"source"
"info"
"send"
];
}
];
instances.btrbk.settings.volume."/".subvolume = "srv";
};
}