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-08-02 03:20:43 +00:00
|
|
|
update-command = [
|
|
|
|
"${pkgs.systemd}/bin/systemctl"
|
2019-08-02 14:51:37 +00:00
|
|
|
"restart"
|
2019-08-02 03:20:43 +00:00
|
|
|
"test-and-update.service"
|
|
|
|
"--no-block"
|
|
|
|
];
|
2019-07-31 09:16:47 +00:00
|
|
|
post-update = writeHaskellScript {
|
|
|
|
name = "post-update";
|
|
|
|
bins = [ pkgs.git pkgs.nix ];
|
2019-08-02 18:41:58 +00:00
|
|
|
imports = [
|
|
|
|
"System.Environment (lookupEnv)"
|
|
|
|
"Control.Monad (ap)"
|
|
|
|
"System.Directory (withCurrentDirectory)"
|
|
|
|
];
|
|
|
|
|
2019-07-31 09:16:47 +00:00
|
|
|
} ''
|
2019-08-02 18:41:58 +00:00
|
|
|
checkout :: String -> IO FilePath
|
|
|
|
checkout pwd = (mktemp "-d" |> captureTrim)
|
|
|
|
>>= ((ap (<$) $ git "clone" pwd) . LBSC.unpack)
|
|
|
|
|
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-08-13 22:24:38 +00:00
|
|
|
path <- pwd |> captureTrim
|
2019-07-31 22:54:13 +00:00
|
|
|
echo ([i|Deploying build to /var/www/#{deploy}|] :: String)
|
2019-08-02 18:41:58 +00:00
|
|
|
bracket (checkout $ LBSC.unpack path)(rm "-rf") $ \dir -> withCurrentDirectory dir $ 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-08-02 03:20:43 +00:00
|
|
|
echo "Triggering (an async) system update."
|
|
|
|
exe "sudo" ${haskellList update-command};
|
2019-07-31 09:16:47 +00:00
|
|
|
'';
|
2019-07-31 21:56:52 +00:00
|
|
|
in {
|
2019-10-25 00:10:02 +00:00
|
|
|
systemd.tmpfiles.rules = let cfg = config.services.gitolite;
|
|
|
|
in lib.mkAfter [ "Z ${cfg.dataDir}/.ssh 0600 ${cfg.user} ${cfg.group} - -" ];
|
2019-07-31 21:56:52 +00:00
|
|
|
users.users.git.linger =
|
|
|
|
true; # Frequent restarting of the systemd-user-unit leads to errors
|
|
|
|
security.sudo.extraRules = [{
|
2019-08-02 03:20:43 +00:00
|
|
|
commands = [{
|
|
|
|
command = builtins.concatStringsSep " " update-command;
|
|
|
|
options = [ "NOPASSWD" ];
|
|
|
|
}];
|
2019-07-31 21:56:52 +00:00
|
|
|
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
|
|
|
}
|