2019-07-31 09:16:47 +00:00
|
|
|
{ config, pkgs, lib, ... }:
|
|
|
|
let
|
2019-08-02 03:17:00 +00:00
|
|
|
inherit (import ../lib) writeHaskellScript haskellList;
|
2019-07-31 09:16:47 +00:00
|
|
|
me = config.m-0.private.me;
|
2019-07-31 21:56:52 +00:00
|
|
|
test-command =
|
|
|
|
[ "${pkgs.systemd}/bin/systemctl" "start" "test-and-bump-config.service" ];
|
|
|
|
upgrade-command =
|
|
|
|
[ "${pkgs.systemd}/bin/systemctl" "start" "system-maintenance.service" ];
|
2019-07-31 09:16:47 +00:00
|
|
|
post-update = writeHaskellScript {
|
|
|
|
name = "post-update";
|
|
|
|
bins = [ pkgs.git pkgs.nix ];
|
2019-07-31 21:56:52 +00:00
|
|
|
imports = [ "System.Environment (lookupEnv)" "Data.Foldable (for_)" ];
|
2019-07-31 09:16:47 +00:00
|
|
|
} ''
|
|
|
|
main = do
|
|
|
|
mirror <- lookupEnv "GL_OPTION_MIRROR"
|
|
|
|
for_ mirror $ \mirror -> do
|
2019-07-31 22:54:13 +00:00
|
|
|
echo ([i|Forwarding push to #{mirror}|] :: String)
|
2019-07-31 09:16:47 +00:00
|
|
|
git "push" "--all" mirror
|
|
|
|
deploy <- lookupEnv "GL_OPTION_WEB_DEPLOY"
|
|
|
|
for_ deploy $ \deploy -> do
|
2019-07-31 22:54:13 +00:00
|
|
|
echo ([i|Deploying build to /var/www/#{deploy}|] :: String)
|
2019-07-31 09:16:47 +00:00
|
|
|
nix "build" "-o" ([i|/var/www/#{deploy}|] :: String)
|
2019-07-31 22:54:13 +00:00
|
|
|
echo "Done"
|
2019-07-31 09:16:47 +00:00
|
|
|
test <- lookupEnv "GL_OPTION_TEST"
|
|
|
|
for_ test $ \_ -> do
|
2019-07-31 22:54:13 +00:00
|
|
|
echo "Triggering a system update … You can wait or disconnect";
|
2019-07-31 09:16:47 +00:00
|
|
|
exe "sudo" ${haskellList test-command};
|
|
|
|
exe "sudo" ${haskellList upgrade-command};
|
2019-07-31 22:54:13 +00:00
|
|
|
echo "Done";
|
2019-07-31 09:16:47 +00:00
|
|
|
'';
|
2019-07-31 21:56:52 +00:00
|
|
|
in {
|
|
|
|
users.users.git.linger =
|
|
|
|
true; # Frequent restarting of the systemd-user-unit leads to errors
|
|
|
|
security.sudo.extraRules = [{
|
|
|
|
commands = [
|
|
|
|
{
|
|
|
|
command = builtins.concatStringsSep " " test-command;
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
}
|
|
|
|
{
|
|
|
|
command = builtins.concatStringsSep " " upgrade-command;
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
}
|
|
|
|
];
|
|
|
|
users = [ "git" ];
|
|
|
|
}];
|
|
|
|
services.gitolite = {
|
|
|
|
enable = true;
|
|
|
|
user = "git";
|
|
|
|
adminPubkey = builtins.elemAt me.keys 0;
|
|
|
|
commonHooks = [ "${post-update}/bin/post-update" ];
|
|
|
|
};
|
2019-07-31 09:16:47 +00:00
|
|
|
}
|