1
0
Fork 0
nixos-config/system/git.nix

63 lines
2 KiB
Nix
Raw Normal View History

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)"
"System.Directory (withCurrentDirectory)"
];
2019-07-31 09:16:47 +00:00
} ''
2019-08-02 18:41:58 +00:00
checkout :: String -> IO FilePath
2020-01-19 18:34:36 +00:00
checkout path = do
(decodeUtf8 -> dir) <- mktemp "-d" |> captureTrim
git "clone" path dir
pure dir
2019-08-02 18:41:58 +00:00
2019-07-31 09:16:47 +00:00
main = do
mirror <- lookupEnv "GL_OPTION_MIRROR"
2020-04-11 15:08:09 +00:00
whenJust mirror $ \mirror -> do
2019-07-31 22:54:13 +00:00
echo ([i|Forwarding push to #{mirror}|] :: String)
2019-11-10 09:28:02 +00:00
git "push" "--all" "-f" mirror
2019-07-31 09:16:47 +00:00
deploy <- lookupEnv "GL_OPTION_WEB_DEPLOY"
2020-04-11 15:08:09 +00:00
whenJust deploy $ \deploy -> do
2020-04-11 20:40:18 +00:00
(maybe [] (\x -> ["-f","default.nix",x]) -> target) <- lookupEnv "GL_OPTION_WEB_DEPLOY_NIX_TARGET"
2020-01-19 18:34:36 +00:00
(decodeUtf8 -> path) <- pwd |> captureTrim
2019-07-31 22:54:13 +00:00
echo ([i|Deploying build to /var/www/#{deploy}|] :: String)
2020-04-11 20:40:18 +00:00
bracket (checkout path) (rm "-rf") $ \dir -> withCurrentDirectory dir $ nix "build" "-o" ([i|/var/www/#{deploy}|] :: String) target
2019-07-31 22:54:13 +00:00
echo "Done"
2019-07-31 09:16:47 +00:00
test <- lookupEnv "GL_OPTION_TEST"
2020-04-11 15:08:09 +00:00
whenJust 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;
2019-10-25 00:15:28 +00:00
in lib.mkAfter
[ "z ${cfg.dataDir}/.ssh/id_ed25519 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
}