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";
2020-05-16 16:03:34 +00:00
bins = [ pkgs.git ];
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
2020-05-16 16:03:34 +00:00
(decodeUtf8 -> repoDir) <- mktemp "-d" |> captureTrim
git "clone" path repoDir
2020-05-16 16:06:48 +00:00
pure repoDir
2019-08-02 18:41:58 +00:00
2019-07-31 09:16:47 +00:00
main = do
2020-05-16 16:03:34 +00:00
mirrorMay <- lookupEnv "GL_OPTION_MIRROR"
whenJust mirrorMay $ \mirror -> do
2020-05-16 13:59:02 +00:00
say [i|Forwarding push to #{mirror}|]
2019-11-10 09:28:02 +00:00
git "push" "--all" "-f" mirror
2020-05-16 16:03:34 +00:00
deployMay <- lookupEnv "GL_OPTION_WEB_DEPLOY"
whenJust deployMay $ \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
2020-05-16 13:59:02 +00:00
say [i|Deploying build to /var/www/#{deploy}|]
2020-05-16 16:08:50 +00:00
bracket (checkout path) (rm "-rf") $ \repoDir -> withCurrentDirectory repoDir $ nix_build "-o" ([i|/var/www/#{deploy}|] :: String) target
2020-05-16 13:59:02 +00:00
say "Done"
2020-05-16 16:08:50 +00:00
testFlag <- lookupEnv "GL_OPTION_TEST"
whenJust testFlag $ \_ -> do
2020-05-16 13:59:02 +00:00
say "Triggering (an async) system update."
2019-08-02 03:20:43 +00:00
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
}