2020-08-12 17:14:52 +00:00
|
|
|
{ config, pkgs, ... }:
|
|
|
|
with import <stockholm/lib>;
|
2020-08-12 20:52:37 +00:00
|
|
|
let
|
2020-08-10 16:48:45 +00:00
|
|
|
|
2020-08-12 20:52:37 +00:00
|
|
|
setupGit = ''
|
|
|
|
export PATH=${makeBinPath [ pkgs.git ]}
|
2021-06-09 20:21:06 +00:00
|
|
|
export GIT_SSH_COMMAND='${pkgs.openssh}/bin/ssh -i ${config.services.gollum.stateDir}/.ssh/id_ed25519'
|
2020-08-12 20:52:37 +00:00
|
|
|
repo='git@localhost:wiki'
|
2021-06-09 20:21:06 +00:00
|
|
|
cd ${config.services.gollum.stateDir}
|
2020-08-12 20:52:37 +00:00
|
|
|
if ! url=$(git config remote.origin.url); then
|
|
|
|
git remote add origin "$repo"
|
|
|
|
elif test "$url" != "$repo"; then
|
|
|
|
git remote set-url origin "$repo"
|
|
|
|
fi
|
|
|
|
'';
|
|
|
|
|
|
|
|
pushGollum = pkgs.writeDash "push_gollum" ''
|
|
|
|
${setupGit}
|
|
|
|
git fetch origin
|
|
|
|
git merge --ff-only origin/master
|
|
|
|
'';
|
|
|
|
|
|
|
|
pushCgit = pkgs.writeDash "push_cgit" ''
|
|
|
|
${setupGit}
|
|
|
|
git push origin master
|
|
|
|
'';
|
|
|
|
|
|
|
|
in
|
2020-08-10 16:48:45 +00:00
|
|
|
{
|
2021-06-09 09:37:27 +00:00
|
|
|
services.gollum = {
|
2020-08-10 16:48:45 +00:00
|
|
|
enable = true;
|
2021-12-10 17:09:44 +00:00
|
|
|
address = "::1";
|
2020-08-12 17:14:52 +00:00
|
|
|
extraConfig = ''
|
|
|
|
Gollum::Hook.register(:post_commit, :hook_id) do |committer, sha1|
|
2020-08-12 20:52:37 +00:00
|
|
|
system('${pushCgit}')
|
2020-08-12 17:14:52 +00:00
|
|
|
end
|
|
|
|
'';
|
2020-08-10 16:48:45 +00:00
|
|
|
};
|
2020-08-12 17:14:52 +00:00
|
|
|
|
2021-06-09 09:37:56 +00:00
|
|
|
systemd.services.gollum.environment.LC_ALL = "en_US.UTF-8";
|
|
|
|
|
2021-12-09 13:30:25 +00:00
|
|
|
networking.firewall.allowedTCPPorts = [ 80 443 ];
|
|
|
|
security.acme.certs."wiki.r".server = config.krebs.ssl.acmeURL;
|
2020-08-10 16:48:45 +00:00
|
|
|
services.nginx = {
|
|
|
|
enable = true;
|
2021-12-09 13:30:25 +00:00
|
|
|
virtualHosts."wiki.r" = {
|
|
|
|
enableACME = true;
|
|
|
|
addSSL = true;
|
2021-12-10 09:13:49 +00:00
|
|
|
locations."/" = {
|
2021-12-10 17:09:44 +00:00
|
|
|
proxyPass = "http://[::1]:${toString config.services.gollum.port}";
|
2021-12-10 09:13:49 +00:00
|
|
|
proxyWebsockets = true;
|
|
|
|
extraConfig = ''
|
|
|
|
proxy_set_header Host $host;
|
|
|
|
'';
|
|
|
|
};
|
2020-08-10 16:48:45 +00:00
|
|
|
};
|
|
|
|
};
|
2020-08-12 17:14:52 +00:00
|
|
|
|
|
|
|
krebs.git = {
|
|
|
|
enable = true;
|
|
|
|
cgit.settings = {
|
|
|
|
root-title = "krebs repos";
|
|
|
|
};
|
|
|
|
rules = with git; [
|
|
|
|
{
|
|
|
|
user = [
|
|
|
|
{
|
|
|
|
name = "gollum";
|
|
|
|
pubkey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMXbjDnQWg8EECsNRZZWezocMIiuENhCSQFcFUXcsOQ6";
|
|
|
|
}
|
2020-08-12 20:52:37 +00:00
|
|
|
] ++ (attrValues config.krebs.users);
|
2020-08-12 18:49:54 +00:00
|
|
|
repo = [ config.krebs.git.repos.wiki ];
|
2020-08-12 20:52:37 +00:00
|
|
|
perm = push ''refs/heads/master'' [ create merge ];
|
2020-08-12 17:14:52 +00:00
|
|
|
}
|
|
|
|
];
|
2020-08-12 18:49:54 +00:00
|
|
|
repos.wiki = {
|
2020-08-12 17:14:52 +00:00
|
|
|
public = true;
|
2020-08-12 18:49:54 +00:00
|
|
|
name = "wiki";
|
2020-08-12 17:14:52 +00:00
|
|
|
hooks = {
|
2020-08-12 20:52:37 +00:00
|
|
|
post-receive = ''
|
|
|
|
${pkgs.git-hooks.irc-announce {
|
|
|
|
channel = "#xxx";
|
|
|
|
refs = [
|
|
|
|
"refs/heads/master"
|
|
|
|
];
|
|
|
|
nick = config.networking.hostName;
|
|
|
|
server = "irc.r";
|
|
|
|
verbose = true;
|
|
|
|
}}
|
|
|
|
/run/wrappers/bin/sudo -S -u gollum ${pushGollum}
|
|
|
|
'';
|
2020-08-12 17:14:52 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
krebs.secret.files.gollum = {
|
2021-06-09 20:21:06 +00:00
|
|
|
path = "${config.services.gollum.stateDir}/.ssh/id_ed25519";
|
2020-08-12 17:14:52 +00:00
|
|
|
owner = { name = "gollum"; };
|
|
|
|
source-path = "${<secrets/gollum.id_ed25519>}";
|
|
|
|
};
|
2020-08-12 20:52:37 +00:00
|
|
|
|
|
|
|
security.sudo.extraConfig = ''
|
|
|
|
git ALL=(gollum) NOPASSWD: ${pushGollum}
|
|
|
|
'';
|
2020-08-10 16:48:45 +00:00
|
|
|
}
|